Hi,
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 ?
…
File “/trytond/model/fields/field.py”, line 356, in convert_domain
expression = Operator(column, self._domain_value(operator, value))
File “/trytond/model/fields/field.py”, line 333, in _domain_value
return self.sql_format(value)
File “/trytond/model/fields/many2one.py”, line 113, in sql_format
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘Get’
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.
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 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
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:
The Many2Many fields on the record model which have the company relation.
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.
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).