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

I have a model named "student" that had a many2many relation with a model named "authorized" and another model named "authorized" with a many2many relation with the model "student". In the other hand, I have a third model named "exit_control" that contains a many2one relation with the model "student".

I wanna a second field many2one in the model "exit_control" that shows only the authorizeds related with the student selected.

In other words: if student1 is related with authorized6 and authorized8, and the complete table of authorized had 20 authorizeds, and I select the student1 in the field student_id of the model exit_control, I wanna show a field many2one with the authorized6 and authorized8.

Student model had:

authorized_ids = fields.Many2many('aula10.authorized', string='Authorizeds')

Authorized model had:

authorized_for_ids = fields.Many2many('aula10.student', string='Can get this student:')

Exit_control model had:

student_id = fields.Many2one('aula10.student',string='Student')
Given_to_id = fields.Many2one('aula10.authorized', string='Given to:')

Given_to_id is the field that I wanna use for show the filtered authorizeds.

I tried to use the attribute domain in view and in model, but was impossible for me.

Can you help me, please?

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

Hi Daniel,

to use domain, you need a searchable field to filter. I guess, you should add a related field to the model Exit_control:

authorized_ids = fields.Many2many(
    related="student_id.authorized_ids",
    store=True,
)


Than, use the domain in the xml:

<field name="authorized_ids" invisible="1">
<field name="Given_to_id"
       domain="[('id', 'in', authorized_ids and authorized_ids[0] and authorized_ids[0][2] or False)]"
/>

Take into account that depending on Odoo version, there are sometimes troubles in using domain by m2m fields. Thus, I used so complex one. However, ('id', 'in', authorized_ids) might work in certain cases as well.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 22
3197
1
يونيو 21
4169
2
مارس 24
2251
1
فبراير 24
2728
1
يوليو 22
5464