Skip to Content
Menu
This question has been flagged
2 Replies
3371 Views

Hi there, I have a question.

I've have 2 views (Quotation and Sales Order). when I create a new sale order, I want to filter the value visible in a many2one depending on the calling view.

I have absolutely no idea how to achieve this.

Can someone pls help?


Thanks a lot

Avatar
Discard
Best Answer

Christian,

you can do it in 2 ways:

1)  As u have 2 seperate views, u can pass some unique context from fields in both views, and in search method use these context values to filter your data..
<field name="<m20_field>" context = "{'view': 'quotation'}"/> in view of Quotation &,

<field name="<m20_field>" context = "{'view': 'sale_order'}"/> in view of Sale Order

then in search method of that m2o_field refresncing object:

def search(self, args, ......):
     if self.env.context is None:

         self.env.context = {}

     if self.env.context.get('view', False) == "quotation":

         #Perform you operation for quotation view

     elif self.env.context.get('view', False) == "sale_order":

         #Perform you operation for sale order view


2) pass domain in the field to filter the values:

<field name="m20_field" domain ="[(<YOUR DOMAIN>)]" />


Hope it helps!

Avatar
Discard
Author Best Answer

Thanks Pawan. Your answer is useful but not exactly what I need as I just realized my question wasn't complete.

I have 2 menus: Quotation and Sale Order. they call 2 separate tree views.

When I click on create in both forms, always the same form view is called.

In the form view I want to have a field (order type which I created as many2one) to different filters based on which tree forms calls it.

Avatar
Discard

Christian,

as quotation and sale order are pointing to same object (sale.order) and there is no different form views created for them, what u can do is:

-> in xml file at action of quotation menu (action_quotations) pass some unique context {'view':'quotation'}, same u can do at Sale order menu action also

-> then this context will be passed to every method of sale.order opening through quotation menu(or sale order, if passed)

-> u can check value of context in search() i kept in my answer above and use above method for further process