Anatomy of a scenario
A scenario has two parts:- Filters decide whether the scenario applies to a given document.
- Outputs describe what to attach to the document when the filters match.
bill/invoice), so a regime can hold one set of scenarios for invoices and a different set for orders or payments.
Filters
A scenario matches when every filter it defines is satisfied by the document. An empty filter is treated as “any value is fine”, so a scenario with no filters matches every document of the configured schema.
The Categories filter is what allows a country with multiple tax categories — like Spain (mainland VAT and Canary IGIC) — to express “this note applies to reverse-charge invoices, but only when the lines are using VAT”. The same scenario can then be paired with another that scopes the note to IGIC.
Note that category matching looks at the document’s lines, charges, and discounts: even though scenario outputs always land at the document level, the applicability is determined by what’s used inside the document.
Outputs
When a scenario matches, GOBL applies its outputs to the document:
Outputs always land on the document, never on individual lines. That keeps the document model simple: a scenario filter may inspect line-level details to decide whether to fire, but the resulting note or extension belongs to the invoice as a whole.
How matching works
When you build a document:- GOBL collects every scenario defined by the document’s regime and any enabled addons for the document’s schema.
- Each scenario is evaluated against the document. All filters must match for the scenario to apply.
- For every matching scenario, the outputs are merged into the document. Notes are deduplicated by
cat+key; extensions overwrite any earlier value for the same key.