Odoo覆盖继承的方法 [英] Odoo overwrite inherited method
问题描述
我想覆盖product_template的unlink()方法,该方法已经由point_of_sale模块继承. 现在,无论何时继承此方法,我都需要调用超级函数(以便调用Odoo ORM中的原始unlink方法).但是,如果执行此操作,则首先调用point_of_sale中的取消链接(继承链).有什么想法会干扰这个继承链并放置我的自定义方法,而不是point_of_sale> unlink方法吗?
Hi I'd like to overwrite the unlink() method from product_template which already has been inherited by the module point_of_sale. Now whenever I inherit this method I need to call the super function (so that the original unlink method within the Odoo ORM is called). But if I do this the unlink within point_of_sale is called first (inheritance chain). Any idea too interupt this inheritance chain and place my custom method instead of the point_of_sale > unlink method?
我需要它来忽略此代码中的警告,然后继续前进.如果有其他解决方案,也可以使用.
I need this to ignore the warning in this code, and just move on. If other solution this can work as well.
销售点> unlink()方法:
Point_of_sale > unlink() method:
def unlink(self, cr, uid, ids, context=None):
product_ctx = dict(context or {}, active_test=False)
if self.search_count(cr, uid, [('id', 'in', ids), ('available_in_pos', '=', True)], context=product_ctx):
if self.pool['pos.session'].search_count(cr, uid, [('state', '!=', 'closed')], context=context):
raise osv.except_osv(_('Error!'),
_('You cannot delete a product saleable in point of sale while a session is still opened.'))
return super(product_template, self).unlink(cr, uid, ids, context=context)
推荐答案
您可以通过更改超级调用来传递链条
You can pass the chain by changing the call in super
# i think this will import the class
# if not then try to find to correct import statement because this
# the only way to do it and this technique worked for someone else
from openerp.addons.point_of_sale.poin_of_sale import product_template as product_template_pos
# in your method pass that class to super not your class
return super(product_template_pos, self).unlink(cr, uid, ids, context=context)
请注意,您必须根据模块的不同添加point_of_sale
NOTE that you have to add point_of_sale in the depends of the module
这篇关于Odoo覆盖继承的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!