Odoo overwrite inherited method

半城伤御伤魂 提交于 2019-12-24 00:54:55

问题


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.

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)

回答1:


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)

NOTE that you have to add point_of_sale in the depends of the module



来源:https://stackoverflow.com/questions/47472027/odoo-overwrite-inherited-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!