2

odoo 11 onchange not working on price_unit in purchase.order.line, while it is working on the discount field.

Below is my code which I copied from Odoo onchange not working correctly and then modified:

@api.onchange('product_id')
def onchange_product_id(self):
    res = super(PurchaseOrderLine, self).onchange_product_id()
    # your logic here
    for rec in self:
        rec.price_unit = rec.product_id.list_price  

        return res

@api.onchange('price_unit')
def _onchange_price_unit(self):
    res = super(PurchaseOrderLine, self)._onchange_price_unit()
    # your logic here
    for rec in self:
        rec.discount = rec.product_id.puchase_price_discount
        return res

1 Answers1

0

Solution that worked:

class PurchaseOrderLine(models.Model):
    _inherit = 'purchase.order.line'
    _description = "Purchase Order Line"


    @api.onchange('product_id')
    def onchange_product_id(self):

        res = super(PurchaseOrderLine,self).onchange_product_id()

        for rec in self:
            self.price_unit = 10

        return res