odoo。 api.onchange do die dip dip dip

发布于 2025-01-18 00:01:17 字数 905 浏览 4 评论 0原文

我正在尝试覆盖onChange account.move.line模型的函数,以更新我已添加到account的自定义字段的值。移动模型:

class SoftOneInvoiceLine(models.Model):

    _inherit= "account.move.line"

    change_from_user=fields.Boolean('Change by user',default=True)

    @api.onchange('quantity', 'discount', 'price_unit', 'tax_ids')

    def _onchange_price_subtotal(self):
        super(SoftOneInvoiceLine,self)._onchange_price_subtotal()
        for rec in self:
            if (rec.change_from_user):
                rec.move_id.global_discount=0
                rec.move_id.write({'global_discount':0})
                print (rec.move_id," ",rec.move_id.global_discount)
            rec.change_from_user=True

上面的代码,当您更改account.move.line的4个字段之一时,不会以形式更改global_discount字段的值。

_onchange_price_subtotal函数被执行,因为打印命令显示在日志中,

为什么global_discount不反映UI?

I'm trying to override an onchange function of account.move.line model in order to update the value of a custom field I've added to the account. move model:

class SoftOneInvoiceLine(models.Model):

    _inherit= "account.move.line"

    change_from_user=fields.Boolean('Change by user',default=True)

    @api.onchange('quantity', 'discount', 'price_unit', 'tax_ids')

    def _onchange_price_subtotal(self):
        super(SoftOneInvoiceLine,self)._onchange_price_subtotal()
        for rec in self:
            if (rec.change_from_user):
                rec.move_id.global_discount=0
                rec.move_id.write({'global_discount':0})
                print (rec.move_id," ",rec.move_id.global_discount)
            rec.change_from_user=True

The code above, doesn't change the value of the global_discount field in the form when you change one of the 4 fields of account.move.line.

The _onchange_price_subtotal functions gets executed, because the print command is displayed in the logs

Why doesn't global_discount new value doesn't reflect on UI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2025-01-25 00:01:17

您没有

rec.move_id.write({'global_discount':0})

尝试过更新?

rec.move_id.update({'global_discount':0})

另外,您不反思UI的意思是什么?它在DB表中更新吗?

Instead of

rec.move_id.write({'global_discount':0})

have you tried update ?

rec.move_id.update({'global_discount':0})

Also, what you meant by not reflecting in UI ? Is it updated in db table ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文