odoo 11 @ api.onchange()在purchase.order.line中的price_unit字段上不起作用

时间:2019-03-03 14:23:55

标签: python odoo onchange odoo-11

odoo 11 onchange不适用于purchase.order.line中的price_unit,而适用于折扣字段。

下面是我从Odoo onchange not working correctly复制并修改的代码:

@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 个答案:

答案 0 :(得分:0)

有效的解决方案:

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