Avoid recursive OnChange event

Bug #1098948 reported by Yann Papouin
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Wishlist
OpenERP's Framework R&D

Bug Description

In a custom module that I'm trying to develop, there are three fields with a OnChange event that affects each of the other fields.

The main issue is that the OnChange event is propagated threw all fields again and again until a balance is found (the value does not change, so the OnChange event is not triggered).

Is there a way to avoid the OnChange "butterfly effect" ?

I tried with a custom tag variable passed in the context dictionnary, but apparently this custom context is lost when exiting the OnChange event.

Changed in openobject-server:
status: New → Confirmed
importance: Undecided → Wishlist
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
Revision history for this message
Serpent Consulting Services (serpent-consulting-services) wrote :

Yann,

I am sure you can handle this within your code.

By design, if value is changed (disregard to manual way or from the onchange of another field); onchange trigger has to fire.

What you can do here is call another onchange with special context and make specific adjustments.

You can also manage this by value based call to onchanges.

If you wish, you can share your example.

Thanks.

Revision history for this message
Yann Papouin (yann-papouin) wrote :

Hi,

I'm attaching the code currently used (a mix between sale_layout and sale_margin)

Please focus on:
onchange_price_unit
onchange_margin_percent
onchange_markup_percent

The fields that interact each other are:
price_unit
price_discount
margin
margin_percent
markup_percent

As you will see, I try to use a flag inside a context, but this value is only visible in this function context (even after multiple on change)
eg:context.update({'ignore_margin_update': True});

Revision history for this message
Atul Makwana(SerpentCS) (amakwana-serpentcs) wrote :

Hello Yann,

After reviewing your onchange methods, I have done following changes to avoid the OnChange "butterfly effect".

kindly apply the attached patch and notify us regarding the results.

Hope this will solve your issue.

Let me know if you still have issues.

Thanks
Atul Makwana
Serpent Consulting Services

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.