Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
4850 Представления

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


Аватар
Отменить
Лучший ответ

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



Аватар
Отменить
Автор

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

Автор

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

Автор

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

Автор

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

Лучший ответ

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
апр. 23
2870
2
февр. 25
40640
2
нояб. 22
2915
1
июн. 22
5735
1
февр. 22
7934