Odoo Help


Can I pass a variable through an act_window in XML?

Juan Formoso
on 11/17/14, 6:32 AM 6,733 views

I have seen variables called from context this way:

context="{'template': template_value,}"

They're coming from some value of the current form, aren't they? And, why can't I pass it through an act_window to the destination model. For example, in the context of an act_window, if I write this:

context="{'default_template_id': 2,}"

It works, but not if I try to get the context of the source model:

context="{'default_template_id': context.get('template_id', False),}"

Another option would be to call a function from there, but I think that's not possible:

context="{'default_template_id': my_function,}"

Can anyone help me? Thank you in advance.


The only way I know to add an option to the menu More in tree views is through XML (how can I add an option to More in Python?), so my act_window is defined in XML:

<act_window name="Invite partners to an event"
    context="{'default_template_id': context.get('template_id', False),}"


René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 11/18/14, 6:53 AM

(After rewriting my answer several times)

If you are assuming that the context contains all field values of your current view, you are wrong.

But you can easily add values from the fields of your model to the context .

context = "{'default_template_id': template_id}"



John Does solution is a quick work arround.

Another suggestion is to add your values with the right key in the previous view (unless there is no name collision). This way you don't have to change the context. It should be passed unchanged.

And finally, after some research, what seems ugly but is powerful:

  1. Create a server action (ir.act.server) that executes python code
  2. Bind this server action to your object as multi_action via an action_binding (ir.values)
  3. Let your server action return a window action (ir.act.act_window)
    1. either as python dictionary directly in the server action
      action = { ..... }
    2. or as python code in a method of the related object
      action = obj.my_client_action_multi_function(context=context)
    3. (or maybe even as window action created in xml?)

Compare the answer of Daniel Reis in this SO topic:

If you choose 3.2 your function could look like this:

def my_client_action_multi_function(cr, uid, ids, context=None):
if context is None:
    context = {};
context['default_template_id'] = context.get('template_id',False);
return {
            'name': ...,
            'res_model': ...,
            'type': 'ir.actions.act_window',
            'view_mode': ...,
            'view_type': ...,
            'domain': [],
            'context': context,

In all cases, you can directly manipulate your context in the server action before returning the window action.



Thank you René! Yes, I thought that, so I was wrong. I passed some variables to a view through context, and in this view I declared an act_window (to see a new option in "More...") which redirects me to other model view. In that act_window, I try to get the context I was using, but it's not recognized.

Juan Formoso
on 11/18/14, 7:18 AM

Updated my answer, but can you please post your code?

René Schuster
on 11/18/14, 7:48 AM

Thank you René, I edited my post with the code.

Juan Formoso
on 11/18/14, 7:58 AM



| 5 3 6
Jakarta, Indonesia
On 11/18/14, 7:09 AM

One workaround that came into my mind is to create a "dummy" field to store the content of the context.get('template_id', False) (invisible, if you want to), and then use that "dummy" field to feed the other context.

On 11/18/14, 6:15 AM


Template is nothing predefined views with values. This templates are created and stored in database. When you create new record templates are sent to new form via context. You could use onchange function http://stackoverflow.com/questions/22218067/openerp-onchange-method-for-fields-in-different-page-of-view

Thank you George for your attention. But I have re-read my own question and it's very confusing, I haven't explained it very well and that's not what I was refering to. I'm going to edit to enlight it better.

Juan Formoso
on 11/18/14, 6:23 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/17/14, 6:32 AM
Seen: 6733 times
Last updated: 3/16/15, 8:10 AM