【问题标题】:odoo 11 @api.onchange() not working on price_unit field in purchase.order.lineodoo 11 @api.onchange() 不适用于 purchase.order.line 中的 price_unit 字段
【发布时间】:2019-03-03 14:23:55
【问题描述】:

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

【问题讨论】:

  • 尝试扩展_onchange_quantity(),就像你提到的我的回答一样,并在那里设置price_unit
  • 复制的确切代码现在在链接上给出,仍然无法正常工作:(
  • 好的,找到问题了,我在两个函数中都错误地缩进了return
  • 最终解决方案是什么?只需将其发布为您的答案。
  • 刚刚发布,感谢您指导我完成

标签: python odoo onchange odoo-11


【解决方案1】:

有效的解决方案:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-13
    相关资源
    最近更新 更多