xopgi.ql.translate.basic – Basic translation tools

Basic translator for predicates to Odoo domains.

xopgi.ql.translate.basic.filtered(predicate)[source]

Translate a predicate over a single record into an Odoo domain.

The predicate must be a lambda function that accepts a positional argument. The name of the positional argument is used to know if we must translate an attribute or not:

>>> filtered(lambda this: this.age < 10)
[('age', '<', 10)]

The name ‘this’ is not included in the domain.

The allowed semantics of predicate match the allowed semantics of the Odoo domains. However, this function allows for certain mismatches in semantics:

>>> filtered(lambda this: this.debit < this.credit)
[('debit', '<', 'credit')]

Odoo sees 'credit' as the literal string instead of the name of an attribute. Attributes are only allowed on the left operand of a comparison:

>>> filtered(lambda this: 1 < this.age < 10 == 10)
['&', '&', (1, '<', 'age'), ('age', '<', 10), (10, '=', 10)]

In this case, the (1, '<', 'age') is incorrect in a Odoo domain.

Arbitrary expressions can be either fail or be incorrectly translated:

>>> filtered(lambda this: this.sum/this.count == average)  # doctest: +ELLIPSIS
Traceback (...)
...
AssertionError: Not just one item the in stack...