Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
4789 Vizualizări

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


Imagine profil
Abandonează
Cel mai bun răspuns

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



Imagine profil
Abandonează
Autor

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

Autor

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

Autor

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

Autor

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

Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
apr. 23
2846
2
feb. 25
40565
2
nov. 22
2890
1
iun. 22
5704
1
feb. 22
7926