تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
11792 أدوات العرض

Hi,

How to restrict drop down values of many2one field accounding to perticular condition?

ie) I need to show only cretain values, according to a perticular condition in many to one field


Example:

'section_id': fields.many2one('crm.case.section', 'Sales Team'),

I need to show only perticular 'section_id' values as If 'section_id' = 2.


الصورة الرمزية
إهمال
أفضل إجابة

Dear aneesh,

You sholud use the domain for condition. we can set domain in two ways

1. python file.

2. xml file.

we can choose any one way to set the domain.

So you should use domain like this

in python file

'section_id': fields.many2one('crm.case.section', 'Sales Team', domain="[('section_id', '=', 2)]")

or

in xml file

<field name="section_id" domain="[('section_id', '=', 2)]"/>

Thanks & Regards

Ankit H Gandhi.

الصورة الرمزية
إهمال

could the domain be dynamic, i.e, the 2 added in the domain could be any number based on a value entered in another field?

Yes, you can set it dynamic.but your new field is related to each other.

أفضل إجابة

Hi friend:

You have to add the domain which defines your condition.So, you can do it by two ways:

Either in your python file.

Or in your  xml file.

Here is an example: where field_a is the field that you want on it the many_2_one depends.(any number based on a value entered in another field?)

 Python:

'section_id': fields.many2one('crm.case.section', 'Sales Team', domain="[('section_id', '=', field_a)]")

or

XML:

<field name="section_id" domain="[('section_id', '=', field_a)]"/>

Regards.

الصورة الرمزية
إهمال

Friend, if its what you are looking for vote ;)

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
فبراير 25
5773
1
ديسمبر 24
1360
1
نوفمبر 22
15913
3
أغسطس 22
12873
2
أغسطس 22
4391