Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4536 Lượt xem

i created many2many field in (mrp.bom model) that select multiply product from product.template based on boolean filed must be True,

i need to created many2one field in (mrp.production model) that select one record form selected product in many2many field in mrp.bom model

any idea how to do that ?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi  loay elhaj,


You can use domain to filter the Many2one field,

product_ids = fields.Many2many('product.template')


product_id = fields.Many2one('product.template' , domain=[('id', 'in', product_ids.ids)])

where product_ids is the many2many field and product_id is the Many2one field. 


Hope it Helps,

Kiran K


Ảnh đại diện
Huỷ bỏ
Tác giả

but the product_ids and product_id in different models

Tác giả

in mrp.bom is many2many and my other field that should be many2one in mrp.production

Then Try,

product_id = fields.Many2one('product.template' , domain=[('id', 'in', bom_id.product_ids.ids)])

Tác giả

i've update the question see it again plz

Add Many2one field in mrp.production with domain

product_id = fields.Many2one('product.template' , domain=[('id', 'in', bom_id.product_ids.ids)])

Tác giả

error raised
packing = fields.Many2one('product.template', domain=[('id', 'in', bom_id.product_ids.id)])
AttributeError: 'Many2one' object has no attribute 'product_ids' - - -

Câu trả lời hay nhất

I solved this issue by returning many2one field domain depending on many2many field results on changing the desired field. Like following:

@api.onchange('product_id')
def _onchange_product_alternative_domain(self):
for line in self:
if line.product_id:
return {'domain': {'alternative_product_id': [('id', 'in', line.product_id.alternative_product_ids.ids)]}}

Here alternative_product_ids is many2many field.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Error raised
ValueError: Invalid domain term ('id', 'in', 'bom_id.product_ids.ids')

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 6 24
14843
2
thg 2 25
5812
1
thg 12 24
1380
1
thg 11 22
15920
3
thg 8 22
12896