all onchange methods activated after any error message or after page reload

Bug #607499 reported by jerzyo
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Web Client
Fix Released
Undecided
Unassigned

Bug Description

This a bug that requires complicated settings.

I am using openerp-web version 5.0.11. firefox 3.5.9

I have a following form:
field A which is a many2one filed
field B which is a string
field C which is a string
button X that checks the correctness of field C and displays an error or changes the state if an object

On field A I have an onchange() function that automatically fills field B.
User can change field B afterwards.

Suppose the user fills field A, then changes field B and chooses a wrong option in field C.
When he clicks the button, An error page appears (I use standard raise osv.except_osv())

When he/she clicks "OK" he comes back to the form using history.back(javascript call)
What happens there is strange. Coming back using history (at least in firefox 3.5) reruns the onchange function of field A. This changes the value of field B. without any user action, which is wrong because user didn't want that and have already set up the value of the field. In other systems such behaviour migh have big bad implications.

The solutions that will satisfy me would be (maybe anyone knows how to do it)
1. changing the forms so that they execute onchange only when user chnges manually the value of the filed, not on reload or back/forward button. I think that this is the way in should be.
2. enable button functions to return {'warning':{}} like the onchange fuctions, which will make a popup window or giving any other way of making popups.
3. Make osv.except_osv() make a popup window (or enable this in the configuration)
4. Or at least make the form completely blank once you reload the page

The only solution (nasty workaround) I can think myself is to make a hidden variable that will be set to "error" if the button click results in an error (by setting it to "error" at the beginning of a function and setting to "no_error" at the end). If value is "error" than all onchange methods will not do anything. It is a really nasty hack and I would like to avoid it as long as I can.

jerzyo (jerzyo)
tags: added: 5.0.11
Revision history for this message
Jiten (OpenERP) (jiten-openerp) wrote :

Hello jerzyo,

Can you please provide more information regarding module and the flow where you are getting this error ?
 How can I reproduce this bug ?

Thanks.

Revision history for this message
jerzyo (jerzyo) wrote :

I do not see any clear example in the standard modules.

For example, in account module one wants to add an extra verification step on the invoices. This verification step checks something (for example if the number of product on product lines is not negative or if payment term in not before current day). This verification should run when the "Confim" button is clicked. The common way to report such error is to raise osv.except_osv().

This works well unless you change the partner address to a non-default on. If you chose a partner, the address is filled by its default address, but you can change it. If you changed it and them make an error, and click on confirm button, and the error is raised, the info is displayed and afterwards you can go back to the form, but when you go back to the form in web_client, the onchange function of the partner field is called which settles the value of partner address to default.

Revision history for this message
jerzyo (jerzyo) wrote :

OK, I found how to reproduce it:

In web client
In Financial management->Invoices->supplier invoices
- Create new invoice.
- Choose partner that has 2 addresses, the first address is filled by default
- Change the partner address to the second address
- Write 1234 in "Total" field
- Click validate
- an error is raised, becouse the total does not match the sum of the invoice lines
- click ok to go back to the form
- Voila! the partner addres is automatically set to the default one. This involves also the financial account and you won't even notice it when changing the total field and validate once more. You end up with a wrong validated invoice. This might create a REALLY BIG MESS in the company.

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote : Re: [Bug 607499] Re: all onchange methods activated after any error message or after page reload

I think the error is in the on_change method on invoice... Im agree.....

The onchange method must be validated with the state of documents too IMHO

2010/7/28 jerzyo <email address hidden>

>
>

Navrang Oza (noz-tiny)
Changed in openobject-client-web:
assignee: nobody → Jra (Open ERP) (jra-openerp)
Changed in openobject-client-web:
status: New → In Progress
Revision history for this message
jerzyo (jerzyo) wrote :

Hi

The problem gets much worse in IE8. In IE8, when the error appears and one goes back, then some data gets lost. In IE8 in described above situation, some fields get lost (they were filled with values and now they are not).

I disagree with Nhomar. When an error is raised, you cannot gurantee that the state of the field is properly set. Moreover, when an error is raised, you should go back to state as if button was never pressed. In invoice, when you want to confirm an incorrect invoice, after an error is raised, you should go back to the draft state. Errors are for making it impossible to change the state of the object if values are incorrect.

In my opinion this is connected with the history.back() button of the error page, which works in an incorrect manner (and different in different browser). In my opinion this should be a form button that will post all the values of the form and fill the form with proper values. Another solution is to make error page a popup window - there would be no switching from one form to another, so the values in the form will be changed.

I need to get this fixed really badly. Please let me know, what do you think about my suggestions. If no one fixes the bug in 2 weeks, I will have to do it myself. However, if I do it myself, I will make a kind of nasty hack which would be useless for others. I need help with it

Changed in openobject-client-web:
assignee: Jra (Open ERP) (jra-openerp) → Xavier (Open ERP) (xmo)
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

can you check if it's fixed or not in trunk ?

Changed in openobject-client-web:
status: In Progress → Incomplete
Revision history for this message
Jiten (OpenERP) (jiten-openerp) wrote :

Hello jerzyo,

It is working fine in stable and trunk both with latest code.
Please update your web branch.

Current revision of stable web : 2950
Current revision of trunk web : 4231

Thanks.

Changed in openobject-client-web:
status: Incomplete → Fix Released
milestone: none → 6.0-rc2
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.