Aggregator rules for Odoo
The BOM creation is achieved via Aggregators that use output keys with special syntax that make use of Odoo features.
There are currently two field names that are reserved and handled specially to facilitate Odoo functionality:
- model - specifies which Odoo model to instantiate with this rule
- template - specifies which Odoo model instance to copy as a basis when instatiating an object from this rule
Note that the
template
key is usually paired with a lookup syntax (see examples below). While this is not mandatory it is generally the practical way of using this feature.
There are currently three types of Odoo-specific keys that can be used in aggregator rules:
- Assignment with a lookup:
some_record_id := my.model.reference_code: some lookup value
- Assignment from a locally created model:
some_field := a_field_on_the_rules_model: rule_name
- Note that you can only reference models created by rules that operate in the same
domain
and are created for the same instance of that particular domain.
- Assignment of a value computed in the aggregator
some_field: 1234
Configuration
Konfoo always allows you to create instances of the following models:
mrp.bom.line
mrp.routing.workcenter
product.product
You can allow additional models in the Konfoo module under Technical → Allowed models.
Examples
Basic BOM line
Consider an aggregator like this:
rules:
- trafos:
domain: Light
require:
- self.product
- self.quantity
- util::lights_unit_is_continuous(self.product)
model: mrp.bom.line
product_id := product.product.default_code: TRAFO-0100
product_uom_id := uom.uom.name: pcs
product_qty: (expr) round(to_float(self.quantity) / 6.0 + 0.5)
From the output of this aggregator the Odoo module will:
- Know based on
model
value that this rule must create a newmrp.bom.line
instance - Knows to look up the value for
product_id
fromproduct.product
using Odoo DOM[('default_code', '=', 'TRAFO-0100')]
- Knows to look up the value for
product_uom_id
fromuom.uom
by[('name', '=', 'pcs')]
- Knows to set
product_qty
value to the value computed by the aggregator
Creating a new product
This example creates a new product.product
instance based on a template product, sets some custom attributes and then uses it on a BOM line.
rules:
- window_glass_product:
domain: Window
require:
- self.material
- self.width
- self.height
model: product.product
template := product.product.default_code: GLASS-TEMPLATE
default_code: (expr) `GLASS-W${self.width}-H${self.height}`
product_width: (expr) self.width
product_height: (expr) self.height
- window:
domain: Window
require:
- self.material
- self.unit
- self.width
- self.height
model: mrp.bom.line
product_id := id: window_glass_product
product_uom_id := uom.uom.name: (expr) self.unit
product_qty: (expr) self.width * self.height
The first rule (window_glass_product
) will:
- Create an instance of
product.product
, but it will copy it from a product that hasdefault_code
set to'GLASS-TEMPLATE'
- Override
default_code
with a computed value - Set the custom fields
product_width
andproduct_height
to the computed values
The second rule (window
) will:
- Set
product_id
value to the product generated in the previous rule for this instance ofWindow
- Set
product_uom_id
andproduct_qty
values just as in the previous example