Odoo Help


filter Many2one based on a specific view

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




| 4 4 6
Hyderabad, India

On 9/6/16, 1:17 AM


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!

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.


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

on 9/6/16, 4:26 AM

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