Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
7882 Weergaven

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
Annuleer

which version are you using?

Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
dec. 24
2512
2
mei 25
1156
2
jan. 24
2722
0
nov. 23
1543
0
sep. 23
1315