Odoo Help

Welcome!

This community 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.

0

Passing context from TreeView to FormView

By
Timo Talvitie
on 9/12/13, 7:21 AM 3,207 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
1
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)
    else:
        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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/12/13, 7:21 AM
Seen: 3207 times
Last updated: 3/16/15, 8:10 AM