context not passed in one2many fields or many2many fields

Bug #1217374 reported by Alexandre Fayolle - camptocamp
34
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Odoo Web (MOVED TO GITHUB)
Fix Released
Undecided
OpenERP Publisher's Warranty Team

Bug Description

Steps to reproduce:

1. install the attached opw_addon module
2. connect to the web interface of your instance, go to Settings and click on Modules -> Test
3. click on the line "Model1"

Expected result:

A form view of Test Model with a single line, the line having Name = Line1 and Reproduce Bug = "1: new key value"

Actual result:

An error message with a stack trace saying that "new_key" is not in context.

Analysis:

The 'new_key' context value is passed in the view, but it is not visible to the web client.

This branch: https://code.launchpad.net/~openerp-dev/openerp-web/7.0-opw-584668-cpa fixes the issue (but the MP was rejected by Olivier Dony). It needs some work, because with that branch I get another bug.

Steps to reproduce bug #2:

1. install the patch on the branch mentioned above, and restart the instance
2. in the web interface, go to Settings and click on Modules -> Partners
3. Click on the line "Agrolait"

Expected result:

the Agrolait partner is displayed

Actual result:

A message saying "Uncaught Error: NameError: name 'supplier' is not defined" is displayed.
Clicking on OK will display the Agrolait partner, but the contacts kanban view is empty.

If I unapply the webclient patch, the res.partner view works fine.

If I edit the view "view_partner_form" and apply the following patch, the view (with the webclient patch) works again, but this probably breaks other things:

=== modified file 'openerp/addons/base/res/res_partner_view.xml'
--- openerp/addons/base/res/res_partner_view.xml 2013-04-25 16:39:16 +0000
+++ openerp/addons/base/res/res_partner_view.xml 2013-08-27 12:30:09 +0000
@@ -186,7 +186,7 @@

                     <notebook colspan="4">
                         <page string="Contacts" attrs="{'invisible': [('is_company','=',False), ('child_ids', '=', [])]}" autofocus="autofocus">
- <field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier}">
+ <field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id}">
                                 <kanban>
                                     <field name="color"/>
                                     <field name="name"/>

(This patch removes the 'default_supplier' entry from the context dictionary)

If I unapply the webclient patch, the res.partner view works fine (which is to be expected, as the context is not passed to the field without the webclient patch).

Tags: maintenance

Related branches

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

the code of the addon mentionned in the bug report.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

PLEASE do *not* flag this as a duplicate of https://bugs.launchpad.net/openerp-web/+bug/1091204 : it is not (the other one is fixed and I can reproduce this one on the latest 7.0 branches).

description: updated
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

a consequence of the last sentence in the bug report is that all views with a one2many field for which a custom context is passed must be checked and fixed if necessary.

Revision history for this message
Stefan Reisich (nafex) wrote :

thank you very much. finally someone took care of this annoying bug.

Changed in openerp-web:
assignee: nobody → OpenERP Publisher's Warranty Team (openerp-opw)
tags: added: maintenance
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :
Download full text (7.8 KiB)

A few suspicious lines in the view definitions of the standard addons, found by a quick grep:

$ rgrep --include "*xml" "field.*ids.*context" .
./hr_expense/hr_expense_view.xml: <field name="line_ids" context="{'currency_id': currency_id, 'default_analytic_account': context.get('analytic_account', '')}">
./account_payment/account_payment_view.xml: <field name="line_ids" context="{'order_id': active_id or False}" >
./survey/survey_view.xml: <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
./survey/survey_view.xml: <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
./survey/survey_view.xml: <field name="answer_choice_ids" nolabel="1" context="{'in_visible_answer_type': in_visible_answer_type}"/>
./survey/survey_view.xml: <field name="column_heading_ids" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
./survey/survey_view.xml: <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
./survey/survey_view.xml: <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
./survey/survey_view.xml: <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
./survey/survey_view.xml: <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
./purchase/purchase_view.xml: <field name="seller_ids" context="{'uom_id': uom_id}"/>
./marketing_campaign/marketing_campaign_view.xml: <field name="activity_ids" context="{'default_object_id': object_id, 'default_campaign_id': active_id}"/>
./marketing_campaign/marketing_campaign_view.xml: <field name="from_ids" mode="tree" context="{'default_activity_to_id': active_id}">
./marketing_campaign/marketing_campaign_view.xml: <field name="to_ids" mode="tree" context="{'default_activity_from_id': active_id}">
./stock/wizard/stock_partial_picking_view.xml: <field name="move_ids" context="{'hide_tracking': hide_tracking}">
./stock/stock_view.xml: <field name="move_ids" context="{'inventory_id':active_id}" options='{"reload_on_button": true}' >
./mrp/mrp_view.xml: <field name="product_id" on_change="product_id_change(product_id)" domain="[('bom_ids','!=',False),('bom_ids.bom_id','=',False)]" ...

Read more...

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

comment #7 does not imply that these views are buggy, just that without the patch applied, there is a good chance that the provided context is ignored (as is the case in the base res.parner form view which crashes with the patch applied). Therefore the should be at least tested to check that they don't crash with the patch applied.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Another issue in this part of the code (with patch applied): when using a many2one field when building the context. The attached addon (updated version of the one in a previous comment) shows this : you get False as the value associated to 'related_key' in the context instead of the id of the related record.

This can be a problem e.g. when trying to pass the id of a stock.warehouse to a product.product in order to display the available stock levels in that warehouse.

Changed in openerp-web:
status: New → Fix Committed
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

I confirm the acl's branch fixes the issue in a much cleaner way tha then 7.0-opw-584668-cpa branch (it does not cause bug #2 in my original bug report).

Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

Hello,

I have merged acl's branch in web 7.0
revno: 4027 [merge]
revision-id: <email address hidden>

Thanks for the report

Regards

Changed in openerp-web:
status: Fix Committed → 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.