hi
Onchange fuction is not a good way, try this , it will help you.
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
@api.model
def create(self, vals):
if vals.get('product_qty') and vals['product_qty'] > 1:
qty = int(vals['product_qty']) - 1
print("VVVVV", vals)
if qty:
for q in range(qty):
vals['product_qty'] = 1
self.create(vals)
res = super(PurchaseOrderLine, self).create(vals)
return res
@api.multi
def write(self, vals):
if vals.get('product_qty') and vals['product_qty'] > 1:
qty = int(vals['product_qty']) - 1
if qty:
for q in range(qty):
vals = {'product_id': self.product_id.id,
'product_qty': 1,
'name': self.name,
'date_planned': self.date_planned,
'price_unit': self.price_unit,
'product_uom': self.product_uom.id,
'order_id': self.order_id.id,
}
self.create(vals)
res = super(PurchaseOrderLine, self).write(vals)
return res
If you have any further questions, please do not hesitate to comment.
Regards,
Nikhilkrishnan