Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
16998 Ansichten

I have two models that have a many-to-one relationship:

class model_a(models.Model):
...
model_b_id = fields.Many2one('Some name', comodel_name='model_b')
...
class model_b(models.Model):
...
model_a_ids = fields.One2many('Some name', comodel_name='model_a', inverse_name='model_b_id', readonly=True)
...

Now my goal is to have two filters, one showing only those entities of model B that have at least one entity of model A assigned (model_a_ids is not empty), and one showing only those entities of model B that have no entity of model A assigned (model_a_ids is empty).

I managed to acheive the first goal with the following filter:

<filter string="Assigned" domain="[('model_a_ids', '!=', [])]"/> 

But my attempts to create the opposite filter failed. I tried the following:

<filter string="Unassigned 1" domain="[('model_a_ids', '=', [])]"/>
<filter string="Unassigned 2" domain="['!', ('model_a_ids', '!=', [])]"/>

Both filters do not work, with both filters the result is empty (although there are entities fulfilling this criterion). And there is no error message in the log either.

How can I achieve my goal?



Avatar
Verwerfen
Beste Antwort

Hi,

Try

<filter string="Unassigned 1" domain="[('model_a_ids', '=', False)]"/>

It will work

Regards....

Avatar
Verwerfen
Autor

Wow, great, that works like a charm! Many thanks!

For Odoo 12 it does not work. Any ideas why?

For what it's worth, on Odoo 13 it worked with None instead of False

This worked on another field

attrs="{'readonly': [('fieldname', '!=', ())]}

Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Juli 15
33145
1
Juni 22
13397
1
Juni 22
7386
1
Apr. 22
2605
1
Juli 19
9475