python - Odoo 11+ 如何覆盖函数参数及其所有调用而不覆盖每个调用

标签 python odoo

我想重写 odoo 中的 uom._compute_price() 和compute_quantity() 以添加产品作为参数。

问题是这些函数在许多其他模块(例如库存、帐户、销售、购买)中的许多其他函数中被调用。

所以我必须重写每个调用函数,大约出现了 140 次。

有没有更好的方法来实现这个而不修改 140 调用?

例如。在重写的函数中,我可以获得原始调用者对象及其属性吗?

最佳答案

如果有办法从 self 或任何其他对象获取产品,您可以 将 product_id 设为仅关键字参数并检查 它不是None,否则你可以从一个对象自行设置它。

      def _compute_price(self, same_arguments,*,product_id=None)
          if product_id is None:
                product_id = # get the id from something

          # your code here

如果您无法从我希望您找到的任何地方获取product_id 以及解决方案,否则您必须编辑所有调用。

关于python - Odoo 11+ 如何覆盖函数参数及其所有调用而不覆盖每个调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57541817/

相关文章:

javascript - Odoo - 自动关闭向导并刷新父级

python - 访问 Pandas 中的组

Python Pandas : creating a dataframe using a function for one of the fields

Python Subprocess call() 不执行shell命令

Python 文字 r'\' 不被接受

java - 当我从服务器获取数据时,无法从 Android 端设置登录注销 session

python - 如何使用正则表达式用空格替换字符之间的破折号

email - 是否可以使用 OpenERP 实现电子邮件已读回执?

python - odoo 10 模块名称无效

python - 奥杜。在 werkzeug 中动态注入(inject) url