Skip to Content
Menu
This question has been flagged
3 Replies
6497 Views

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
Discard

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
Discard
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
Discard
Related Posts Replies Views Activity
2
Dec 24
1334
2
Jan 24
817
0
Nov 23
450
0
Sep 23
327
2
Aug 23
1794