我正在开发sale.order.line,添加新的字段lot

lot = fields.Many2one('stock.production.lot','lot')我想把这个字段作为参数传递给一个继承的方法(onchange on quantity )
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False,
fiscal_position=False, flag=False, lot=False,context=None):
res = super(order_line, self).product_id_change(cr, uid, ids,
pricelist, product,
qty,uom, qty_uos,
uos, name, partner_id,
lang, update_tax,
date_order, packaging,
fiscal_position,
flag, context=context)
if product:
print "----------------------------------------------"
print lot
print "----------------------------------------------"
# res['value']['changement_prix'] = lot.change_prix
# res['value']['old_price'] = res['value']['price_unit']
# res['value']['price_unit'] = res['value']['old_price'] + lot.change_prix
return res 但是我在打印中得到的lot都是False的,所以我想知道如何将lot作为参数传递给这个函数thnx
发布于 2017-01-09 20:49:53
您不能以这种方式在函数中传递新参数。
它调用object的超方法,也会在超方法中产生问题。因此,您可以在XML端上下文中传递lot,
喜欢
<field name="product_id"
context="{'partner_id':parent.partner_id,
'quantity':product_uom_qty,
'pricelist':parent.pricelist_id,
'uom':product_uom, 'company_id': parent.company_id,
'lot': lot}" <======
groups="base.group_user"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, False, product_uos_qty, False, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>因此,在上下文中,你通过了大量的测试。
lot = context.get('lot')在python端,你从上下文中获取并完成代码。
否则,您必须在新模块中重写onchange的整个函数,在xml端更改onchange的论点
希望这能对你有所帮助。
发布于 2017-01-12 21:26:33
我无法通过上下文获取很多内容,所以我在product.product中创建了一个不可见的字段many2one,并将其保存在那里。而不是稍后通过浏览我的产品thnx来取回它
https://stackoverflow.com/questions/41547867
复制相似问题