# ============================================================================= # Projet : AIR — Accounting Intermediate Representation # Auteur : Simon-Pierre Boucher # Contact : contact@spboucher.ai # Fichier : evaluator.py # Description : ALSL v0.1 evaluator — matches policy `when` clauses against economic events. # ============================================================================= """Deterministic evaluation of ALSL `when` clauses against AIR events.""" from __future__ import annotations from alsl.model import ClassificationPolicy, PolicySet, TaxPolicy, WhenClause from core.events import EconomicEvent from core.money import Money def matches(when: WhenClause, event: EconomicEvent, subtotal: Money | None) -> bool: if when.event_type is not None and event.type.value != when.event_type: return False jurisdiction = event.tax.jurisdiction if event.tax else None if when.jurisdiction is not None and jurisdiction != when.jurisdiction: return False if when.jurisdiction_in is not None and jurisdiction not in when.jurisdiction_in: return False if when.min_amount is not None: if subtotal is None: return False if when.currency is not None and subtotal.currency != when.currency: return False if subtotal.amount < when.min_amount: return False return True def applicable_tax_policies( policies: PolicySet, event: EconomicEvent, subtotal: Money | None ) -> list[TaxPolicy]: return [p for p in policies.tax_policies if matches(p.when, event, subtotal)] def applicable_classifications( policies: PolicySet, event: EconomicEvent, subtotal: Money | None ) -> list[ClassificationPolicy]: return [ p for p in policies.classification_policies if matches(p.when, event, subtotal) ]