Rational
We have a Dict but it is not really possible to use them in a domain because it does string comparison.
It will be a good improvement to be able to make domain on the key value.
Both back-ends have function to manipulate JSON data: PostgreSQL JSON function and SQLite JSON1 extension.
For now, there is only Oracle which supports the SQL/JSON standard. So an had-hoc solution for the Tryton limited usage is preferable.
Proposal
I propose to extend the domain syntax to allow the ‘.’ notation (like for relation field) to access the value of a specific key. For example ('dict.key', '=', value)
will search for record with the JSON object having key value equals to value.
This can be implemented in PostgreSQL with the operator dict->>key = value
and in SQLite with json_extract(dict, '$.key') = value
.
On the client side, the domain evaluation can be adapted to test the value of the key. The domain inversion can just ignore such case. And finally the domain parser could have a syntax for this but it is not mandatory (as it can be too expensive to retrieve all the key strings).