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

Setup filter in Sales Order "Add An Item" search view

By
Kyle Connor
on 12/31/14, 11:41 AM 2,002 views

I am trying to setup a filter that will base itself off of the "Customer" field (partner_id) when creating or modifying a Sales Order. I am very new to OpenERP, so please pardon any obvious mistakes.

I made the following line in the search view to create the filter:

<filter string="Customers Items" domain="[('x_whereused','=',sale.view_order_form.partner_id)]" name="own_area_items"/>

x_whereused is a custom field I made in product.template which indicates which customers use what parts. I want the Add an Item - Search More view to have the above filter compare the partner_id in the newly made Sales Order with my custom field (x_whereused) and display if it matches. I get the following error currently when applying the filter.
 

"TypeError: context is undefined

http://_________/web/js.web.assets_backend/7b7a275:3778"

Thanks very much for any assistance on this!

Hi Kyle, you should change your "answer" below to a comment to my answer. Click the "Convert as comment" to do that. You may have to also copy-paste it as a comment to my answer. Also, click the grey circled checkmark on my answer to "accept" it.

john5000
on 1/2/15, 12:40 AM

And I'm checking out how to answer your further question...

john5000
on 1/2/15, 1:51 AM

Thanks! I'm definitely going to try that out. One question I have is in the case that I wanted the user to be able (if they wanted) to go through the other listings that are not matching the x_whereused field (say the item is not in the list and the sales man wants to check for something not necessarily associated with that customer), would they be able to do this with the above code in place? Please excuse me if I'm mis-understanding, but from what I can tell, the code you gave will filter the results regardless of filters being applied in the search window itself. My idea came up from observing the "My" filter in th Draft Quotations view, that shows your own drafts, and then if you remove it, it shows everyone's. Thanks and Happy New Year!

Kyle Connor
on 1/2/15, 9:26 AM

Hello. I follow what you are asking for. Unfortunately I've not found out how to do that. The domain puts a filter there, which is not shown to the user. Normally you use default_search_(field) to set a default that is shown as a search filter to the user. But that is not made for doing a lookup on a many2one within a form. So, at this point it is probably best to work out the other parts of your system and then come back to this when you have a better understanding of the various capabilities.

john5000
on 1/4/15, 12:52 AM

Well, been a long time coming but I finally ended up revisiting this and got your code implemented in a module. I decided to ditch the optional part of seeing another customers parts as that can be done in the product menu, doesn't need to done in the sales order. The final code I ended up using is: sale.view.order.form.inherit sale.order <xpath expr="//field[@name='order_line']/tree//field[@name='product_id']" position="attributes"> [('whereused','=',parent.partner_id)]

Kyle Connor
on 5/24/15, 1:39 PM
1
john5000
On 1/1/15, 9:23 PM

You can't use "sale.view_order_form.partner_id" in your filter, as the search view will not be able to understand it.

Also the filter needs to be part of the product lookup with in the sales order form.

Here is how you can add a filter to the products listing in a sales order:

And in your case the partner_id will be used as the id to filter with. 

Add the following to the product_id field view defintion:

   domain="[('x_whereused', '=', parent.partner_id)]"

You will find an example of the xpath section for doing this in the file "sale_stock_view.xml" (under the "sales" addon folder)
Look for the following section, which is the xpath section that needs to be modified:

<xpath expr="//field[@name='order_line']/tree//field[@name='product_id']" position="replace" 
    <field name="product_id
        domain="[('x_whereused', '=', parent.partner_id)]"             <-- Add this
        context=... (etc.)
        ...    />
</xpath>

You should of course put this this in your own addon that is used to override the exiting logic (hopefully you are doing that).

But if you just want to see it in action quickly, you can add that line above to the "sale_stock_view.xml" file, then under Settings->Apps find the "Sales Management" and do "Upgrade".

Now when you create an order and click on the product field it will be filtered by the partner_id.  Of course, you can change that domain= to filter by other criteria also. 

0
Kyle Connor
On 1/1/15, 11:18 PM

See comment

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

2 follower(s)

Stats

Asked: 12/31/14, 11:41 AM
Seen: 2002 times
Last updated: 5/24/15, 1:40 PM