Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Should constraint methods be redefinable?

By
Pablo
on 4/3/13, 6:49 AM 1,665 views

In order to add an option to allow the importation of VAT numbers without validating them I'm trying to redefine the method check_vat. It is added to res_partner in the module base_vat (base_vat.py:114). This method is used to implement the constraint logic defined for the constraint on base_vat.py:150

_constraints = [(check_vat, _construct_constraint_msg, ["vat"])]

To redefine this method I inherit res_partner as shown below:

class ags_res_partner(osv.osv):
    _inherit = 'res.partner'

def check_vat(self, cr, uid, ids, context=None):
    res = super(ags_res_partner, self).check_vat(cr, uid, ids, context=context)
    #if parametro_comprobar_CIFS return res
    print "redefined check_vat"
    return True        

def simple_vat_check(self, cr, uid, country_code, vat_number, context=None):
    print "redefined simple_vat_check"
    return True

ags_res_partner()

The result is that the redefined version of simple_vat_check (a method called from inside check_vat) gets invoked but not check_vat. Debugging this code I find that the inheritance is working. In fact, I can see my class in self.__class__.__mro__ when inside the check_vat implementation of base_vat. The problem comes from the way that the constraint methods get called (orm.py:1527), skipping the OpenERP managed inheritance system. Once inside check_vat, simple_vat_check gets invoked properly taking into account that inheritance system.

Since check_vat is defined as a public method, I understand it should be redefinable. Am I wrong? Did I commit any mistake or the fact that the inheritance gets skipped is just a bug?

Thanks in advance

1

Jeudy Nicolas

--Jeudy Nicolas--
1181
| 6 7 8
PELOUSEY, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 9/10/13, 9:43 AM

hello,

Unfortunatly I think you have to redefine all _constraints. Your code should look like this:

class ags_res_partner(osv.osv):
    _inherit = 'res.partner'

    def check_vat(self, cr, uid, ids, context=None):
        res = super(ags_res_partner, self).check_vat(cr, uid, ids, context=context)
        #if parametro_comprobar_CIFS return res
        print "redefined check_vat"
    return True

    def simple_vat_check(self, cr, uid, country_code, vat_number, context=None):
        print "redefined simple_vat_check"
        return True

    _constraints = [(check_vat, _construct_constraint_msg, ["vat"])]

Your module should depend on base module in you case and load after base (you can add an higher sequence number in __openerp__.py , but not in your case,base module is loaded before all other mods.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/3/13, 6:49 AM
Seen: 1665 times
Last updated: 3/16/15, 8:10 AM