Windows client : context passed on a button in a view does not get passed to the resulting action/view called

Bug #487649 reported by Niels Huylebroeck
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo GTK Client (MOVED TO GITHUB)
Fix Released
Undecided
Unassigned
Nominated for 5.0 by Niels Huylebroeck

Bug Description

I have a button like this :

<button name="%(action_crm_project_task_work)d" type="action" icon="gtk-go-forward" string="Create Task Work" colspan="2" context="{'project_id': project_id}"/>

The action it is calling :

<record id="action_crm_project_task_work" model="ir.actions.act_window">
    <field name="name">Enter work for project</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">project.task.work</field>
    <field name="view_id" ref="project_work_entry.project_work_entry_project_task_work_view"/>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
</record>

On the model project.task.work I have written a custom function which reads in context, and if 'project_id' is in the context it alters the view slightly (applying a domain on a field)

The problem is in linux and the webclient this action works as the context is indeed correctly passed, in the windows client it throws this error when calling the action :

Traceback (most recent call last):
  File "widget\view\form_gtk\parser.pyo", line 132, in button_clicked
  File "modules\action\main.pyo", line 79, in execute
  File "modules\action\main.pyo", line 108, in _exec_action
  File "tools\__init__.pyo", line 36, in expr_eval
  File "<string>", line 1, in <module>
NameError: name 'project_id' is not defined

description: updated
Revision history for this message
Niels Huylebroeck (red15) wrote :

I pushed the module where I have this problem to lp:~openerp-community/openobject-addons/trunk-addons-community/

rev 130 ( <email address hidden> )
subdir project_work_entry

There might still be small issues with this module as it was developed to co-exist with other modules.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Niels,

Context from button is passed to the action quite normally.

Make sure you have project_id field is in the same view or object for which the button is displayed.(i.e. the project_id field is in the same xml record or belongs to the same model).

Update your code too.

Changed in openobject-client:
status: New → Invalid
Revision history for this message
Niels Huylebroeck (red15) wrote :

Jay,

I assume you looked at the source code, where you found a reference to a project_id in the crm.case model which is not there by default. Like I said, this module is part of a chain of modules, one of the other modules actually provides a project_id in the crm.case.

But the point is calling the action from any model (even where you would just pass project_id: 1 in the context) still results that in windows you get the error I pasted and in linux it executes perfectly.

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

Hello Niels,

We have checked in windows with latest version.

We are able to get the context from the button.

What we did is: Called an action from button.

It would be best if you give the module,so we can trace whether its the programming issue or really a bug.

As said by Jay(OpenERP), the field project_id should belong to the form view of the current object.

<field name="period_id" select="2"/>
<button name="%(action_open_accounts)d" string="Import Invoice" type="action" context="{'name_ach':period_id}"/>

This action belongs to account.account. Now, If I go to the search method of account.account, I clearly meet to the context.

Thank you.

Changed in openobject-client:
status: New → Invalid
Revision history for this message
Niels Huylebroeck (red15) wrote :

Ok I updated the project_work_entry module in community addon.

You should just be able to get module and look how the wizard field stays empty on windows machines and is filled with the current project if you click the button on the project form view.

Changed in openobject-client:
status: Invalid → New
Revision history for this message
Niels Huylebroeck (red15) wrote :

Turns out I had changed something in my local client that made it work with the way it currently is defined in the uploaded module.
I've now fixed this problem and am now able to reproduce this problem consistently regardless of windows/linux.

I'll invalidate this bug for now until I find out why the module still is not behaving like I expect it to.

Changed in openobject-client:
status: New → Invalid
Revision history for this message
Niels Huylebroeck (red15) wrote :

Did some debugging on the client, I found out that when an action is called the attribute context is not passed along when calling this action. Instead the screen context is passed through.

See line 132 in widget/view/form_gtk/parser.py

                elif button_type == 'action':
                    obj = service.LocalService('action.main')
                    action_id = int(self.attrs['name'])
                    obj.execute(action_id, {'model':self.form.screen.name, 'id': id or False,
                        'ids': id and [id] or [], 'report_type': 'pdf'}, context=self.form.screen.context)

The context as you see is self.form.screen.context, why not pass the self.attrs['context'] ? or a combination of both ?

Revision history for this message
Niels Huylebroeck (red15) wrote :

Ok just noticed, the fix is already in 5.0 stable : revision <email address hidden> (rev 1006 on 5.0)

So basically I was right reporting this bug for 5.0.6 as the 5.0.6 release tag is dated 22 Sept 2009 and the fix was only committed on 16 Oct 2009.

Next time I think it would be safer to assume people are reporting bugs for 5.0.6 and not the 5.0 branch in general. (As 5.0.6 is finally what the customers will use and not the branch version)

Regards,
Niels

Changed in openobject-client:
status: Invalid → Fix Committed
Revision history for this message
Niels Huylebroeck (red15) wrote :

Can someone target this bug on the 5.0.7 client release ? It's already fixed so it'll just make the change log easier to write.

Changed in openobject-client:
milestone: none → 5.0.7
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.