This question has been flagged

I want to ask users to select a Product Category on every Sales Quotation and have Odoo restrict the products that can be added to only those in the selected category.

How can I do this?

Avatar
Discard
Best Answer

For version 13, this approach might work:

1. Create a new field to link the sale.order model to the product.category model, allowing users a place to store the selected Category for each order:



2. Add this field to the User Interface, together with a domain on the order_line field to restrict products to those in the currently selected category:


<field name="partner_shipping_id" position="after">
<field name="x_product_category"/>
</field>

<xpath expr="//page/field[@name='order_line']/tree/field[@name='product_id']" position="attributes">
<attribute name="domain">[('categ_id','=',parent.x_product_category)]</attribute>
</xpath>


This restricts Users to only the products from the category they select:


Avatar
Discard

Hi Ray - this is useful (as ever), but is it possible to handle a user not selecting a product category?

Also, is it possible to pass the product category when creating a new product? (I tried to add context, but couldn't get it work)

(1) not with this approach (2) you would need to pass context from the sale order line to the product, rather than the order to the product. So this means context would need access to a custom field on the sale order line that stores the current category on that line. "parent." from the perspective of the product is the line, not the order.