Domain on selector view of a Many2Many

Is there a way to filter the view back by a ‘many2many’ when adding a value (the view that shows the list of possible values).
The ideal would have been to put a ‘domain’ on the call of this view, but I do not know where to place it.
I already trying to put a domain on the field but is too restrictive because when registering the field it would seem that the domain of values already present is also verified.
Or perhaps there is another way ?


There is the filter attribute.

Thank you, I did not see this attribute.
Is a PYSON expression valid because I have the following error with the same syntax as a domain:

filter=[(‘company’, ‘=’, Eval(‘context’, {}).get(‘company’, -1))]

File “/trytond/model/fields/”, line 356, in convert_domain
expression = Operator(column, self._domain_value(operator, value))
File “/trytond/model/fields/”, line 333, in _domain_value
return self.sql_format(value)
File “/trytond/model/fields/”, line 113, in sql_format
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘Get’

Yes, it is just appended to the domain sent to the client.

But when i put a PYSON expression i have this error :

TypeError: int() argument must be a string, a bytes-like object or a number, not ‘Get’

if i use a ‘Get’ or if i use an ‘Eval’

TypeError: int() argument must be a string, a bytes-like object or a number, not ‘Eval’

A Bug ?

Indeed dynamic domain is not allowed for filter because it is used in the Field.get which can not be evaluated.
We should probably put a warning in the documentation about this restriction.

Ok, so no solution for my initial question, I’m looking for another way to do it.
Thank you.

I think you should explain why you need that because custom domain may not be the solution.

well, I would like to display in the selection view of the Many2Many only the records of the current company. However it is possible that in the table I have records for another company.
Thanks for any suggestion to make that.

I do not understand how it is possible to have record from another company if it is not possible to select them. So for me, it is a classic domain.

I have an object with a company field that I use in my Many2Many. I would like that when I’m on company 1 I can add to my Many2Many only the records from company 1 and that when I’m on company 2, only the records of company 2.
If I’m not mistaken, it looks like the result obtained with ‘CompanyValueMixin’ but on a Many2Many

It sounds like a simple company domain:

[('company', '=', Eval('company'))]

Not completely, because, like i writed in my first post, when you have in the many2many a record with company 1 you have a domain violation when you try to write a record for company 2.

In a Many2Many relation there are two fields to be defined:

  1. The Many2Many fields on the record model which have the company relation.
  2. The Many2One on the intermediary table that will store the data.

It seems you are defining the domain on the field 2 which will be applied on all records (and that’s why you have the domain violation for all companies) but it should be defined on the field 1.

Hope it helps!

You can probably use record rule to allow only to ‘read’ target from the current company. But this will apply everywhere.
Or you must use a function field that perform the filtering for you (a little bit like the moves on shipments).

Thank you for your answer, that’s what I did.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.