on_change behaves odd when fields conflict with context_*

Bug #611934 reported by digitalsatori(Shine IT)
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo GTK Client (MOVED TO GITHUB)
Fix Released
Medium
Naresh(OpenERP)

Bug Description

I'm testing on trunk version, the problem doesn't affect openobject-web client.

I created a model with a many2one field 'project_id' pointed to the model 'project.project', and I set an 'on_change_project_id(self, cr, uid, ids, project_id, context)' method on this field.

The problem is when the on_change method triggered, the current 'project_id' didn't actually passed as an argument into on_change method, instead, the 'context_project_id' on model 'res.users' get passed.

I've noticed that the 'context_project_id''s value will automatically insert into 'session.context' with key 'project_id', and I guess that the 'project_id' in the context actually interferes with the passing argument on on_change method. This sounds like a bug, any idea?

Currently I can workaround the problem by setting the field name other than 'project_id' ,e.g. 'myproject_id', however, this really looks awkward.

Related branches

Changed in openobject-client:
status: New → Confirmed
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello,

              I created a new model and added a many2one field of project.project named as project_id and added an on_change method on it with context. And it is working as it should. Can you give me an example where you have used it and it mixes with context_project_id?

Thanks.

Revision history for this message
digitalsatori(Shine IT) (digitalsatori) wrote :

The attachment is a very small testing module, you may install it and see what the problem is.
Please test it on trunk version of openerp.

To reproduce the problem:

1. install the testing module
2. set 'start date' and 'end date' on one or more projects (demo data)
3. check in the 'user preference' menu, ensure the project field is BLANK
4. Now launch the 'Test Project On Change' form, make sure the 'start date' and 'end date' is BLANK
5. select the project that we modified at STEP 2.
Problem: the 'start date' and 'end date' remain BLANK at this stage, it suppose to change according to the project's date setting

6. open user preference menu and select the project that we modified at STEP 2
7. now select any project on 'Test Project On Change' form,
Problem: the date will remain as the same as the "modified project's date setting" no matter what the project you selected (please clear the 'start date' and 'end date' field on the form before changing to other project to see the problem)

NO above mentioned problem on openerp web client.

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello,

   I agree with your point. context_project_id gets replaced by project_id as in context we remove the _context part of a context field so context_project_id becomes project_id and it alters the value of project_id at client side. For this I have found a solution. would you please check the attached patch and notify us?

Thanks.

affects: openobject-client → openobject-server
Changed in openobject-server:
assignee: nobody → Anup (Open ERP) (ach-openerp)
status: Confirmed → In Progress
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :
Changed in openobject-server:
milestone: none → 6.0
summary: - on_change event pass the value in context instead of the value on field
+ on_change behaves odd when fields conflict with context_*
Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

It is happening in all models, try account_invoice, res_partner, is a consistent error.

regards

affects: openobject-server → openobject-client
Changed in openobject-client:
milestone: 6.0 → none
Revision history for this message
digitalsatori(Shine IT) (digitalsatori) wrote :

@Anup, the way you patch the code is only hiding the problem. As I said the WEB CLIENT is working correctly, this implied that the problem is at the client side, patching the server code does not sound right to me.

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello,

   I agree with you that this thing must be fixed at the client side. I have a found solution for this. Would you please check the attached patch and give your views?

Thanks.

Revision history for this message
digitalsatori(Shine IT) (digitalsatori) wrote :

Thank you for providing the patch code. The code can be written concisely as following:

for key in rpc.session.context:
  if key not in context:
    contex[key] = rpc.session.context[key]

However, I doubt that 'context.update(rpc.session.context)' in the original code base or the above patching code is really needed.
I found that at revision 1417, you yourself introduce the line "context.update(rpc.session.context)", but I don't get what the purpose of it.

Changed in openobject-client:
importance: Undecided → Medium
milestone: none → 6.0
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello digitalsatori,
As this line was need before when the rpc.session.context was not considered in the eval i.e the field with context_* values that are changed from user_preferences get stored in the rpc.session.context and the context on the normal field are stored in the context at the record/model level. Now we send the updated context for the eval so there is no need of this line.

Can you please have a test by commenting this line in the trunk client without the above patch.
# context.update(rpc.session.context)

Thanks

Revision history for this message
digitalsatori(Shine IT) (digitalsatori) wrote :

yes, commeting out 'context.update(rpc.session.context)' solved the problem

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello,

Thanks for the notification.
It has been commited to trunk with 1464 <email address hidden>

Thanks

Changed in openobject-client:
assignee: Anup (Open ERP) (ach-openerp) → nch(OpenERP) (nch-openerp)
status: In Progress → Fix Released
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.