Expressions

Currently expressions are only usable in Aggregators - primarily to avoid needless boilerplate for defining a function for every calculation and variable access.

In version <= 0.4.0 compute fields do not support expressions.

Expressions are prefixed with the string (expr) and have access to everything compute fields have access to. For more please see API Reference.

An example of an aggregator rule:

- window_hinges:
    domain: Window
    require:
        - self.hinges_product_code
        - self.hinges_qty
    model: mrp.bom.line
    product.product.default_code: (expr) self.hinges_product_code
    uom.uom.name: pcs
    product_qty: (expr) self.hinges_qty

Any aggregator rule's output field that has the expression prefix is treated as code and the result of the evaluation is assigned as value to the output field. Anything else (such as uom.uom.name: pcs) is treated as-is (in this case the string "pcs").

Normally expressions are expected to return a value that will be assigned to the field the expression is evaluated for. That does not mean you cannot do more complex operations inside the expression:

    product_qty: |
        (expr)
        let magic_quantity = some_module::calculate_magic_stuff();
        self.hinges_qty + magic_quantity