Odoo Help


Passing context from TreeView to FormView

Timo Talvitie, Vizucom Oy
on 9/12/13, 7:21 AM 4,480 views

As a default, when a user creates a Quotation or a Sales Order, OpenERP opens the same form view (sale.view_order_form) for both of them.

Now, I would like to do some customization to the FormView based on which type of document the user is creating. As I understand it, I can override the Quotations and Sale Orders menu items to provide a context (e.g. {is_quotation: True}) to pass to the TreeViews that open when clicking the menu item, but when the Create button is clicked in the TreeViews the context does not get passed along to FormView where it is actually needed.

Is it possible to pass a context from a menu item --> TreeView --> FormView and eventually to python code that is triggered from the FormView?

Another alternative to achieve the customization would be to create completely separate forms for Quotation and Sales Order creation, but that would create a lot of duplicated code, so a context-based solution would be great.

Anyone has a answer or solution for this problem? I am also facing difficult doing this exactly same thing. Please help to enlighten!

Aaron Neo
on 10/19/13, 10:25 AM
Aaron Neo
On 10/19/13, 11:19 AM

Hey Timo,

I managed to solved my problem. Let me explain my case. I wanted to pass the context from act_window to new form. It was not going through properly initially but after looking carefully at some similar examples from "stock" module, I managed to find the problem.

The following code is the solution.

First I pass context <field name="context">{"ticket_type":"installation"}</field> from act_window in view XML:

Then I need to create _defaults values in my ORM model using a function:

def _get_default_holding_location_for_source(self, cr, uid, context=None):
    if context is None:
        context = {}

    if context.get("ticket_type") == "installation":
        return self._get_default_holding_location(cr, uid, context)
        return False        

_defaults = {
        'irrs_result': 'pending',
        'source_location': _get_default_holding_location_for_source

It wasn't working because of this line:

def _get_default_holding_location_for_source(self, cr, uid, ids, context=None):

Notice the extra "ids" argument. That was the problem. Because of this extra argument, the context wasn't passed in.

I hope this thread can help anyone else who are facing the same problem.

Regards, Aaron

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: 9/12/13, 7:21 AM
Seen: 4480 times
Last updated: 3/16/15, 8:10 AM