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

in "Products" (model product_template) I have inherited and added a custom field "brand_id" of type "Many2many"

in my custom "OrderItems" I had a field "brand_id" as "Many2one", 

here user selects a "product" and for "brand" I want to 'filter' and show only "brands" which are associated to the selected "product" in "Products

please help how to filter it.

regards


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

Hi ,

optional_product_ids is Many2many in Product Master

@api.onchange('product_id')
def onchange_product_id(self):
if self.product_id:
self.optional_id = False
optional_products = self.product_id.optional_product_ids.ids
if optional_products:
domain = [('id','in',optional_products)]
return {'domain':{'optional_id':domain}}
return {'domain':{'optional_id':[('id', 'in', [])]}}



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

thanks Kiran Mohan, will implement, check and give feedback here... :)

Tác giả

hi @Kiran Moha, sorry for late in reply, was busy in other tasks, today i tried to implement the code as your's but it is showing error. i want to copy my all 3 model's .py code and your code implemented with some changes. the error is " ValueError: Invalid domain term ('id', 'in', 'tests.brands(1, 2, 3)') " (without double quotes). don't know where i am making mistake due to lack of knowledge, please help. note: I can post the code as mentioned but this will not as readable here without formatting. regards

optional_products = self.product_id.optional_product_ids.ids

Tác giả

hi Kiran Mohan, this is same line as your first Answer here, if you want to see complete code i can post here as Answer ... because in Comment it is not possible imo.

Answer updated , it was optional_products = self.product_id.optional_product_ids earlier

Tác giả

thanks Kiran Mohan and appreciate your passions to help me :) regards

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

While defining brand_id  field in the OrderItems, you can give domain such as

In OrderItems model

brand_id = fields.Many2one(...., domain=[('id', 'in', product_id.brand_id.ids)])

where product_id is the product field.



Karan BK

Junior Odoo Developer

Tel: +353 1 886 5684 (IE) +44 121 285 5684 (UK)  +91 964 381 7554 (IN)

Target Integration | CRM ERP Cloud

Website | LinkedIn | Twitter | Facebook | YouTube | Instagram

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 23
2878
2
thg 2 25
40683
2
thg 11 22
2925
1
thg 6 22
5787
1
thg 2 22
7942