Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
7880 Vizualizări

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

Imagine profil
Abandonează

which version are you using?

Cel mai bun răspuns

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
Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
dec. 24
2511
2
mai 25
1151
2
ian. 24
2720
0
nov. 23
1541
0
sept. 23
1312