default value passed through context (in m2o field) can't override default value defined in its class

Bug #925622 reported by Cuong
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Web (MOVED TO GITHUB)
Invalid
Undecided
Unassigned

Bug Description

Hi,

I face an issue like this. For example,
in product class, it has a field "type". I set its default value is 'consu' type. Now in another class, I define a m2o field to product class, named 'product_id'.
===
'product_id': fields.many2one(...., context={'default_type': 'product'})
===

Then, when I create a product directly within form view of my class, it will pop up product dialog, 'type' field with default value of 'consu', not 'product'.

Thanks,

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hi,

You're not giving any versioning information, so I take it you are reporting this for trunk.

Default values passed through the context *do* override the defaults defined in the model, but that works only when the context really contains those values! To double-check this and convince yourself, try adding the default_type value to the context of the menu action from which you reach the form view, and see how it works.

Now what you see could be a bug or simply an unsupported feature... I don't see any example of a m2o fields having a literal context passed in its declaration in the 6.1 standard addons (but there are a few one2many cases)

You may want to try the following:
- set the context in the view of the model containing the product_id m2o (at XML-level) instead of doing it in Python
- use a string literal for the context instead of a python dict, e.g:
     'product_id': fields.many2one(...., context="{'default_type': 'product'}")

BTW, was this working in 6.0 on both Web and GTK clients?

Thanks,

Revision history for this message
Cuong (bhcuong2008) wrote :

Hi Olivier,

Sorry for lacking of version info. This is the trunk with latest revision. I has learned this from 6.0 (using context in many2one field's declaration). I will test your suggestion with literal string instead of python dict.

Thanks,

Revision history for this message
Cuong (bhcuong2008) wrote :

Hi Olivier,

I've tested many cases, and I can't repeat this issue that I faced last night. Now all work well with both python dict and literal string.

If any, I will report later. Now you can ignore this issue.

Thanks,

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

On 02/03/2012 11:58 AM, Cuong wrote:
> I've tested many cases, and I can't repeat this issue that I faced last
> night. Now all work well with both python dict and literal string.
>
> If any, I will report later. Now you can ignore this issue.

Thanks for the update, feel free to reopen this bug report later as needed.

Changed in openerp-web:
status: New → Invalid
Revision history for this message
Cuong (bhcuong2008) wrote :

Hi Olivier,

I've tried a lot of test cases, and found an issue. It is related to 'form_view_ref' in context. In view definition as below,
===
<field name="product_id" context={'form_view_ref': '.....'}/>
===
Then all contents of context defined in python class will have no effects, the context is overridden by the above definition. So, this issue affects my default value passed in field definition of its class. I think it is one of reasons that cause my issue.

I've tested on my own project. I just take product class as an example.

Thanks,

Revision history for this message
Cuong (bhcuong2008) wrote :

Currently my solution is setting context all in one place, in the field definition in its class or in view definition.

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.