将onchange方法代码从V7迁移到V8

时间:2015-06-17 05:46:05

标签: openerp odoo openerp-8 odoo-8

我想将带有新api的版本7中的销售订单行的product_id_change方法迁移到版本8。

一般情况下,我看到我们无法转换那些基本方法是用旧api编写的新api中的onchange方法,在用super调用基本方法时会产生问题。

执行此操作时出现错误,错误表示您已将15个参数传递给方法,而需要19个。

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, context = None ):

这是旧api的方法声明。我想用超级方法调用将这段代码完全保存在新的api中。

有没有希望实现这个目标?

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以通过这种方式迁移到版本8

@api.multi
@api.onchange('product_id')
def product_id_change(self):
    if not self.product_id:
        return {'domain': {'product_uom': []}}

    vals = {}
    domain = {'product_uom': [('category_id', '=', self.product_id.uom_id.category_id.id)]}
    if not (self.product_uom and (self.product_id.uom_id.category_id.id == self.product_uom.category_id.id)):
        vals['product_uom'] = self.product_id.uom_id

    product = self.product_id.with_context(
        lang=self.order_id.partner_id.lang,
        partner=self.order_id.partner_id.id,
        quantity=self.product_uom_qty,
        date=self.order_id.date_order,
        pricelist=self.order_id.pricelist_id.id,
        uom=self.product_uom.id
    )

    name = product.name_get()[0][1]
    if product.description_sale:
        name += '\n' + product.description_sale
    vals['name'] = name

    if self.order_id.pricelist_id and self.order_id.partner_id:
        vals['price_unit'] = product.price
    self.update(vals)
    return {'domain': domain}
相关问题