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

Hi, I am trying to add dynamic domain in Odoo 10 Many2one field. Here is the code:


    @api.multi

    def _get_education_domain(self):

        res = {}

        education_list = []

        if self.emeu_sector_id.id:

            education_ids = self.emeu_sector_id.emeu_education_ids

            education_list = [x.id for x in education_ids]

        return [('id', 'in', education_list)]


emeu_education_id = fields.Many2one(

        'emeu.education', string=_('Education'), ondelete='restrict', domain=_get_education_domain)


This throws JSON serialiser error. Can anyone please help me to fix the issue.

 

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

Hey,

try to keep a value of domain in a separate field. E.g.:

@api.multi
@api.depends("emeu_sector_id.emeu_education_ids")
def _get_education_domain(self):
        for object in self:
              education_list = []
              if object.emeu_sector_id.id:
                   education_ids = object.emeu_sector_id.emeu_education_ids
                   education_list = [x.id for x in education_ids]               object.education_list = [(6,0, education_list)]
education_list = fields.Many2many('emeu.education',store=True,compute=_get_education_domain) emeu_education_id = fields.Many2one('emeu.education', string=_('Education'), ondelete='restrict'])

And on the xml form:

<field name="education_list" invisible="1"/> 
<field name="emeu_education_id" domain="[('id','in',education_list[0][2])]" />
الصورة الرمزية
إهمال
الكاتب

Hey, thanks for your answer but now it's throwing an error:

TypeError: 'Many2many' object does not support indexing

Does the domain field is filled properly?

If yes, try one of the followings: to remove [0][2] OR instead put ids

الكاتب

Domain field is populated properly. I already tried both of them and throwing following error:

RuntimeError: maximum recursion depth exceeded while calling a Python object

الكاتب

Hey, I got it fixed. Remove domain attribute from class field emeu_education_id and added in view:

<field name="emeu_education_id" domain="[('id','in',education_list[0][2])]" />

الكاتب

Please update your answer with above comment so that I can accept your answer. Much thanks for your help!! :)

glad to hear! the answer was updated

الكاتب

Thanks man!! :)

أفضل إجابة

You can follow this: https://youtu.be/XGqXEL2qQmE 

Hope it helps, Thanks

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

Vualá, amazing¡¡¡

I have remove [0][2] for domain xml view, I don't know exactly what this is for.

Thanks man¡¡¡¡

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
Domain filter تم الحل
1
ديسمبر 23
18914
0
فبراير 25
18
1
يوليو 19
4985
2
مارس 15
6773
0
مارس 15
3743