Odoo覆盖继承的方法

时间:2017-11-24 11:10:02

标签: inheritance openerp odoo-8 product unlink

您好我要覆盖product_template中的unlink()方法,该方法已经由模块point_of_sale继承。 现在每当我继承这个方法时,我都需要调用super函数(这样就可以调用Odoo ORM中的原始unlink方法)。但是如果我这样做,则首先调用point_of_sale中的unlink(继承链)。任何想法都会中断这个继承链并放置我的自定义方法而不是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)

1 个答案:

答案 0 :(得分:2)

您可以通过更改超级

中的调用来传递链
# 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