跳至内容
菜单
此问题已终结
3 回复
8232 查看

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

形象
丢弃

which version are you using?

最佳答案

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
形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
12月 24
2877
2
5月 25
1805
2
1月 24
3313
0
11月 23
1956
0
9月 23
1747