Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4609 Tampilan

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


Avatar
Buang
Jawaban Terbai

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', [])]}}



Avatar
Buang
Penulis

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

Penulis

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

Penulis

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

Penulis

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

Jawaban Terbai

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

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Apr 23
2600
2
Feb 25
39922
2
Nov 22
2669
1
Jun 22
5430
1
Feb 22
7676