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.

0

How to pass arguments to defaults function?

By
Anabela Damas
on 10/16/13, 4:12 PM 3,792 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

0
nazarii
On 10/16/13, 5:30 PM

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

0
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.

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: 10/16/13, 4:12 PM
Seen: 3792 times
Last updated: 3/16/15, 8:10 AM