Odoo Help


How to pass arguments to defaults function?

Anabela Damas
on 10/16/13, 4:12 PM 5,272 views

Hi, I am trying to create a field that have a default value equal to True if the partner (res_partner) is a company or a contact. I didn't figure it out how to send the argument is_company and parent_id or the id to my function.

    _inherit = 'res.partner'

       def _passiv_defaults(self, cr, uid, context):
            res = {}
          ### Here I don't know how to check if the field from partner is_company is true or false, and if the it has a parent_id
            return res

        _columns = {
                'passiv': fields.boolean('Passiv'),
         _defaults = {
            'passiv': _passiv_defaults,  

how to pass arguments to _passiv_defaults? Thanks




| 5 4 7
On 10/16/13, 5:30 PM

You can not do it this way, you can do it with on_change.

Damián Soriano
On 10/17/13, 4:37 AM

You can as well override the create() function and check in the vals dictionary if the partner is a company or a contact.

You can also do a function that receive the id of the partner to make that check the default value depending on the values in the database. You call this function from the create() and write() methods after calling the corresponding super class method.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 10/16/13, 4:12 PM
Seen: 5272 times
Last updated: 3/16/15, 8:10 AM