odoo10 如何在 1 个字段中构建 2 个 onchange 函数

odoo10 how to build 2 onchange function in 1 field

我对 Odoo 10 中的 onchange 函数有疑问。

这是一些示例代码:

class test_1(models.Model)
    Input = fields.Integer()

来自另一个 class,我有一个 onchange 函数。此 class 是默认系统,无法更改或添加此代码中的任何内容。

class test_onchange(models.Model)
    @api.onchange('Input')
    def _onchange_test_1(self):
        ## some process ##

这是我正在编写的函数。它也是 onchangeInput

class test_onchanger(models.Model)
    @api.onchange('Input')
    def _onchange_test_addon(self):
        ## some process. and different  _onchange_test_1

所以问题是:

如果 Input 字段已经有一个 [=13],我如何从另一个 class/module 在 Input 字段上构建一个 onchange 函数=] 函数来自默认 system/code.

有人有想法吗?我可以继承 _onchange_test_1 或其他什么吗?

您可以继承现有的 onchange 方法或为同一字段编写另一个 onchange 方法,两者都可以。

确认一下,您想要扩展(将自定义添加到)现有的onchange方法?

正如另一个答案中提到的,最简单的方法是继承现有的 onchange 方法。


假设这是您无法修改的核心代码:

class CoreClass(models.Model):
    _name = 'core.class'

    Input = fields.Integer()

    @api.onchange('Input')
    def _onchange_input(self):
        ## some process ##

在您的模块中,您可以扩展 class 并进行其他更改。

注意:核心 class 方法在您使用 super 调用时仍然运行。

class CoreClassCustom(models.Model):
    _inherit = 'core.class'

    @api.onchange('Input')
    def _onchange_input(self):
        res = super(CoreClassCustom, self)._onchange_input()
        ## your custom process ##
        return res

这里是 the Odoo 10 ORM Documentation,它简要介绍了 onchange 个方法。