Python 如何更改Odoo中的模块方法并避免破坏东西?
我想添加一个模块,如果选中表单视图中的特殊复选框(field.Boolean),该模块将更改税务计算(def_compute_all in class account.tax)。我使用复选框,因为我认为它可以为用户提供更清晰的信息,无论它是否处于活动状态 这样做的正确方法是什么(将来不会破坏东西的方法)以及与其他模块一起使用的方法(基本上使用与原始odoo制作的account模块相同的数据字段) 视图: 我的模块(python): 在这之后我有点迷路了。考虑过这种方法,但这很容易在将来破坏东西:Python 如何更改Odoo中的模块方法并避免破坏东西?,python,python-2.7,openerp,odoo-9,Python,Python 2.7,Openerp,Odoo 9,我想添加一个模块,如果选中表单视图中的特殊复选框(field.Boolean),该模块将更改税务计算(def_compute_all in class account.tax)。我使用复选框,因为我认为它可以为用户提供更清晰的信息,无论它是否处于活动状态 这样做的正确方法是什么(将来不会破坏东西的方法)以及与其他模块一起使用的方法(基本上使用与原始odoo制作的account模块相同的数据字段) 视图: 我的模块(python): 在这之后我有点迷路了。考虑过这种方法,但这很容易在将来破坏东西:
def newCompute (self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
# custom computation code that uses custom_tax_field 1 and 2, and all of the data fields as original
def checkCustomTaxSelection (self):
if self.custom_tax =='1':
return self.newCompute()
else:
return self._compute_amount()
看起来不好,感觉不对。有更好的方法吗
@api.v8和@api.v7是旧的Odoo版本的遗留代码吗?还是我也应该关注它们(我的模块仅限于Odoo 9)?我无法回答account.tax的所有问题,但我只能建议您,与其定义新方法,不如覆盖旧方法:
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
if self.custom_tax:
#your code here
#res = ...
else:
res = super(MyTaxCompute, self)._compute_amount(base_amount, price_unit, quantity, product, partner)
return res
我无法回答account.tax的所有问题,但我只能建议您,与其定义新方法,不如覆盖旧方法:
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
if self.custom_tax:
#your code here
#res = ...
else:
res = super(MyTaxCompute, self)._compute_amount(base_amount, price_unit, quantity, product, partner)
return res
def newCompute (self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
# custom computation code that uses custom_tax_field 1 and 2, and all of the data fields as original
def checkCustomTaxSelection (self):
if self.custom_tax =='1':
return self.newCompute()
else:
return self._compute_amount()
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
if self.custom_tax:
#your code here
#res = ...
else:
res = super(MyTaxCompute, self)._compute_amount(base_amount, price_unit, quantity, product, partner)
return res