Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python odoo 11@api.onchange()不处理purchase.order.line中的price\u unit字段_Python_Odoo_Onchange_Odoo 11 - Fatal编程技术网

Python odoo 11@api.onchange()不处理purchase.order.line中的price\u unit字段

Python odoo 11@api.onchange()不处理purchase.order.line中的price\u unit字段,python,odoo,onchange,odoo-11,Python,Odoo,Onchange,Odoo 11,odoo 11 onchange在purchase.order.line中不处理价格单位,而在折扣字段中处理 下面是我从中复制并修改的代码: @api.onchange('product_id') def onchange_product_id(self): res = super(PurchaseOrderLine, self).onchange_product_id() # your logic here for rec in self: rec.pr

odoo 11 onchange在purchase.order.line中不处理价格单位,而在折扣字段中处理

下面是我从中复制并修改的代码:

@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

有效的解决方案:

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

尝试扩展
\u onchange\u quantity()
,如我的回答中所述,并在那里设置
价格单位
。复制了链接上现在给出的精确代码,仍然不起作用:(好的,发现了问题,我在两个函数中都错误地缩进了return。最终的解决方案是什么?只需将其作为您的答案发布即可。刚刚发布,谢谢您指导我