spb/air Public MIT
AIR — The Language of Accounting.
Python 100%
1# =============================================================================2# Projet : AIR — Accounting Intermediate Representation3# Auteur : Simon-Pierre Boucher4# Contact : contact@spboucher.ai5# Fichier : evaluator.py6# Description : ALSL v0.1 evaluator — matches policy `when` clauses against economic events.7# =============================================================================8"""Deterministic evaluation of ALSL `when` clauses against AIR events."""9from __future__ import annotations1011from alsl.model import ClassificationPolicy, PolicySet, TaxPolicy, WhenClause12from core.events import EconomicEvent13from core.money import Money141516def matches(when: WhenClause, event: EconomicEvent, subtotal: Money | None) -> bool:17 if when.event_type is not None and event.type.value != when.event_type:18 return False19 jurisdiction = event.tax.jurisdiction if event.tax else None20 if when.jurisdiction is not None and jurisdiction != when.jurisdiction:21 return False22 if when.jurisdiction_in is not None and jurisdiction not in when.jurisdiction_in:23 return False24 if when.min_amount is not None:25 if subtotal is None:26 return False27 if when.currency is not None and subtotal.currency != when.currency:28 return False29 if subtotal.amount < when.min_amount:30 return False31 return True323334def applicable_tax_policies(35 policies: PolicySet, event: EconomicEvent, subtotal: Money | None36) -> list[TaxPolicy]:37 return [p for p in policies.tax_policies if matches(p.when, event, subtotal)]383940def applicable_classifications(41 policies: PolicySet, event: EconomicEvent, subtotal: Money | None42) -> list[ClassificationPolicy]:43 return [44 p for p in policies.classification_policies45 if matches(p.when, event, subtotal)46 ]47