不覆盖调用顺序函数

Odoo overriden function call order

据我了解,odoo 不会像 Python 扩展其 类 那样扩展其模型(_inherit = 'model'。这似乎很合理。但我的问题是:

如果我有 customModule1 扩展 sale.order 并覆盖 write 方法添加一些功能,然后我安装 customModule2 进而扩展 sale.order模型并重写 write 方法并添加一些功能 我知道 write 方法的所有版本都将被调用,但顺序是什么?

customModule1write是客户端在sale.order模型上写的时候先调用吗?或 customModule2write ?

是的,这是非常有趣的一点,没有人可以预测首先调用哪个模块的哪个方法,因为 odoo 管理依赖的层次结构。

Calling pattern comes into the picture only when the method will be called from object (manually from code) and if write method call from UI (means Sales Order edit from UI) then it will call each write method written for that model no matter in which module it is and it's sequence is LAST WRITTEN CALL FIRST (but it's only when the method is called from UI).

所以在你的情况下,自定义模块 1自定义模块 2 将处于同一级别并且都具有相同的父级 销售订单.

销售订单 => 自定义模块 1(写入方法覆盖)

销售订单 => 自定义模块 2(写入方法覆盖)

So while the write method will be called manually from code then it will gives priority to local module first and then it will call super method.

在那种情况下,假设从 模块 1 调用 write 方法,那么它可能会忽略 Module 2 的 write 方法,因为模块 1 和模块 2 都在同一级别(super 将调用 parent class 的 write 方法)。因为我们在开发中多次遇到这个问题,即在多个模块上重写的方法并且这些方法处于同一级别,所以它不会调用下一个模块的方法。

所以当你需要调用每个模块的每个方法时,它们必须在层次结构中,但不能在同一级别。

因为并行模块有时不会调用该方法是有主要原因的。

因为这里有两件事,

1). depends : 父模块(决定模块层级)

2). _inherit : 这里定义对象的方法和行为。

Module 1 and Module 2 are not there in depends of each other so by hierarchy it's not necessary to call the method from these both module no matter whether they are overriding the same method of same model.