This question has been flagged
1 Reply
11767 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.

Avatar
Discard

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

Best Answer

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

Avatar
Discard