object _defaults: how to remove fields before it applies

Asked by Eduardo Ruiz

I have problems with onchange envents produced by object defaults dictionary. Is there a way to clear it before the events are triggered?

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Eduardo Ruiz
Solved:
Last query:
Last reply:
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#1

Hello Eduardo,

You may go to the field when there is a blank value on it.

Right click on the same and click on 'set as default' value.This will set NOTHING/False/0.0 to the field.

Thank you.

Revision history for this message
Eduardo Ruiz (readylan) said :
#2

Hello Jay,

the problem persists because the onchange_<field> is still triggering, though it defaults to NOTHING/False/0.0.
The only way for now to avoid this behavior is commenting the default value in the original declaration of the class.

Thank you.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#3

Hello,

Tell me what is the flow you get to the error?

Onchange () generally takes the values from current form view.

Thank you.

Revision history for this message
Eduardo Ruiz (readylan) said :
#4

Hello Jay,

my real case is in sale orders. I have extended the model with a new many2one field (cashbox). In the onchange event of this field i want to set some values by default in the actual sale order, like the customer. Mostly, this fires the onchange_partner_id, changing the price list ...
If i put default value in view for cashbox field, the result is not what i want since some fields are not filled up. It works fine when changing the value manually in the view. It works fine too modifying the code in sale.py just deleting some fields of the sale.order _defaults dictionary.
That's the reason of my question: is it possible to delete from base class _defaults dictionary to prevent the onchange event to happen for this fields?

Thanks

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#5

Hello Eduardo,

Normally, onchange works when the value on the field is changed.
In the case of _defaults, if you have set some default value on the field cashbox,onchange will definately be fired.

However, you may delete _defaults if this satisfies your need.

Thank you.

Revision history for this message
Eduardo Ruiz (readylan) said :
#6

Hello Jay,

thank you for your help. This is finally what i did:

class sale_order(osv.osv):
    _inherit = 'sale.order'

    def __init__(self, pool, cr):
        super(sale_order, self).__init__(pool,cr)

        list=['partner_shipping_id', 'partner_order_id', 'partner_invoice_id', 'pricelist_id']
        for f in list:
            del self._defaults[f]
sale_order()

Now, i can manage correctly the on_change events produced in this model.