Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5669 Vistas

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
Descartar
Mejor respuesta

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
Descartar

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.

Publicaciones relacionadas Respuestas Vistas Actividad
15
mar 21
12058
1
nov 22
2169
0
mar 16
3721
3
dic 19
4103
4
oct 15
3836