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

filter Many2one based on a specific view

By
Christian
on 9/5/16, 10:21 AM 177 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

1

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 9/6/16, 1:17 AM

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!

0
Christian
On 9/6/16, 3:56 AM

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.

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

Pawan
on 9/6/16, 4:26 AM

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/5/16, 10:21 AM
Seen: 177 times
Last updated: 9/6/16, 3:56 AM