Formula
TL;DR - Derive attribute using other attributes of current/parent class
Formula rules are lambda expressions or functions that can reference other attributes of current/parent class. They are declared in the declare_logic()
function in logic/declare_logic.py
.
Execution order is system-determined based on dependencies.
Changes to referenced parent attributes are propagated to all child rows. Contrast this to the Copy
rule, for parent references where you do not want propagation.
Formulas may be pruned if there are no changes to the referenced attributes.
Provide expression as lamda
Simple formulas are most easily expressed as lambda functions:
Rule.formula(derive=models.OrderDetail.Amount, # compute price * qty
as_expression=lambda row: row.UnitPrice * row.Quantity)