Reputation: 14746
I want to migrate product_id_change method of sale order line which is in version 7 to version 8 with new api.
Generally I seen we can't convert those onchange method in new api whose base method are written in old api, it will create issue while we calling base method with super.
I am getting error while doing this, error says you have passed 15 parameters to the method while 19 required.
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 ):
This is the declaration of method with old api. I want to keep this code completely in new api with super method calling.
Is there any hope to achieve this ?
Any help will be appreciated.
Upvotes: 1
Views: 262
Reputation: 2324
You can Migrate to version 8 this way
@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}
Upvotes: 1