Odoo 覆盖继承的方法
Odoo overwrite inherited method
您好,我想覆盖 product_template 中的 unlink() 方法,该方法已被模块 point_of_sale 继承。
现在,每当我继承此方法时,我都需要调用超级函数(以便调用 Odoo ORM 中的原始取消链接方法)。但是如果我这样做,首先调用 point_of_sale 中的取消链接(继承链)。任何想法也中断这个继承链并放置我的自定义方法而不是 point_of_sale > unlink 方法?
我需要这个来忽略这段代码中的警告,然后继续。如果其他解决方案也可以工作。
Point_of_sale > unlink() 方法:
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)
可以通过改变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)
NOTE that you have to add point_of_sale in the depends of the module
您好,我想覆盖 product_template 中的 unlink() 方法,该方法已被模块 point_of_sale 继承。 现在,每当我继承此方法时,我都需要调用超级函数(以便调用 Odoo ORM 中的原始取消链接方法)。但是如果我这样做,首先调用 point_of_sale 中的取消链接(继承链)。任何想法也中断这个继承链并放置我的自定义方法而不是 point_of_sale > unlink 方法?
我需要这个来忽略这段代码中的警告,然后继续。如果其他解决方案也可以工作。
Point_of_sale > unlink() 方法:
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)
可以通过改变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)
NOTE that you have to add point_of_sale in the depends of the module