Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odgovori
7884 Prikazi

Hi all,

Here i tried the following,

1.add a dropdown field for product category in sale oder line.

2.in that sale order line list the products respective to selected product category.


This is where i go so far in "sale.order" model :

    x_product_categories = fields.Many2one('product.category' , 'Catégorie du Produit')


    @api.onchange('x_product_categories')

    def _show_list_of_products(self):

        for order in self:

            selected_category_id = order.x_product_categories

            product_id = fields.One2many('product.product' , domain=['category_id', '=','selected_category_id'])


Any suggestions please?
Thanks a lot

Avatar
Opusti

which version are you using?

Best Answer

Hi,
you can use this method. you have to do things in the sale order line then you must inherit sale.order.line instead of sale.order.

class SaleOrderLineExt(models.Model):
_inherit = 'sale.order.line'categ_id = fields.Many2one('product.category')@api.onchange('categ_id')
def _onchange_categ(self):
return {'domain': {'product_id': [('categ_id', '=', self.categ_id.id)]}}
I think this will help you, don't forget to add this category field in the UI.
Regard
Avatar
Opusti
Best Answer

Try using domain for "product_id"

domain="[('categ_id', '=', x_product_categories)]"

There will be already domain for product_id in sale.order.line , so please add this domain with the existing one.

Hope this helps

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
dec. 24
2513
2
maj 25
1159
2
jan. 24
2732
0
nov. 23
1554
0
sep. 23
1321