程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 Onchange 更新 one2many 字段。奥多14大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 Onchange 更新 one2many 字段。奥多14?

开发过程中遇到使用 Onchange 更新 one2many 字段。奥多14的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 Onchange 更新 one2many 字段。奥多14的解决方法建议,希望对你解决使用 Onchange 更新 one2many 字段。奥多14有所启发或帮助;

由于未保存字段“tax_IDs_after_fiscal_position”的问题,我尝试使用在 pos.order.line 模型中调用的以下函数更新 One2many 字段 这是我的代码:

class PosOrderline(models.Model):
    _inherit = "pos.order.line" 

    @API.onchange('product_ID')
    def _onchange_product_ID(self):
        self.tax_IDs_after_fiscal_position = self.product_ID.taxes_ID
        self.write({'tax_IDs_after_fiscal_position': [(4,self.product_ID.taxes_ID)]})

我收到以下错误:

The above exception was the direct cause of the following exception:

TraceBACk (most recent call last):
  file "/usr/lib/python3/dist-packages/odoo/http.py",line 639,in _handle_exception
    return super(Jsonrequest,self)._handle_exception(exception)
  file "/usr/lib/python3/dist-packages/odoo/http.py",line 315,in _handle_exception
    raise exception.with_traceBACk(NonE) from new_cause
AttributeError: 'account.tax' object has no attribute 'ref'

请问怎么了? 有什么帮助吗? 谢谢。

解决方法

请不要在 onchange 内使用 write。

@api.onchange('product_id')
def _onchange_product_id(self):
    self.tax_ids_after_fiscal_position =  [(6,self.product_id.taxes_id.ids)]

大佬总结

以上是大佬教程为你收集整理的使用 Onchange 更新 one2many 字段。奥多14全部内容,希望文章能够帮你解决使用 Onchange 更新 one2many 字段。奥多14所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。