aeat.application.ledger._actions_classification module¶
Bulk and rule-based ledger classification services.
CSV bulk classification parses
BulkClassifyRow records, converts populated
fields into ManualLedgerTransactionPatch,
and applies them through
update_manual_transaction_fields(). Rule
application evaluates LedgerClassificationRule
instances over active transactions and returns
ApplyRulesResult.
Batch persistence uses the concrete
TransactionCatalogueRepository
so the end-of-batch save can compose the catalogue write with bucket events in
one secure-object unit of work.
- bulk_classify_from_csv(*, bucket_id, csv_text, actor, source_command='aeat app ledger classify --from-csv', transaction_repository=None, bucket_event_repository=None, work_unit_repository=None, calculation_repository=None)[source]¶
Apply batch classifications from a CSV string.
The CSV must contain
transaction_idandclassificationcolumns;category_id,business_pct,usage_ratio_id,taxable_base,iva_rate,iva_amount,iva_category, andirpf_categoryare optional. Blank optional cells are treated as omitted, so a partial CSV classification row preserves existing tax facts instead of clearing them accidentally. Populated tax facts ride the sameManualLedgerTransactionPatchand theupdate_manual_transaction_fields()write path the single-classify surface uses, so a bulk row persists the same typedtaxable_base/iva_rate/iva_amount/iva_category/irpf_categoryvalues as--id-mode classify with identical validation. Unknown columns are rejected before any writes. Rows that fail validation (unknown transaction id, invalid classification value, malformed tax fact, pydantic error) are collected infailuresand the remaining valid rows are applied (partial-success semantics matching the ledger import pattern).Returns a
BulkClassifyResult.- Return type:
- Parameters:
bucket_id (str)
csv_text (str)
actor (str)
source_command (str)
transaction_repository (TransactionCatalogueRepositoryProtocol | None)
bucket_event_repository (BucketEventHistoryRepositoryProtocol | None)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
- add_classification_rule(*, bucket_id, description_pattern, classification, category_id=None, priority=100, actor, rule_repository=None)[source]¶
Persist a new ledger classification rule and return it.
rule_idis content-addressed: adding the samedescription_pattern + classification + category_idcombination twice produces the same id and the repository save overwrites the prior entry (idempotent creation).Returns a
LedgerClassificationRule.Raises
ValueErrorwhendescription_patternis not a valid regex, as validated byLedgerClassificationRule.- Return type:
- Parameters:
- apply_classification_rules(*, bucket_id, reaffirm=False, actor, source_command='aeat app ledger rule apply', transaction_repository=None, bucket_event_repository=None, rule_repository=None)[source]¶
Apply stored classification rules to unclassified ACTIVE transactions.
Scope: ACTIVE transactions in
NOT_YET_PROCESSEDstate. Whenreaffirm=True, also includes ACTIVE transactions whereclassified_by == "manual"so the operator can explicitly re-run the rule engine over manually classified rows.Rules are evaluated in priority order (lower number = higher priority); the first matching rule wins. Match is
re.search(pattern, description, re.IGNORECASE).Returns an
ApplyRulesResult.- Return type:
- Parameters:
bucket_id (str)
reaffirm (bool)
actor (str)
source_command (str)
transaction_repository (TransactionCatalogueRepositoryProtocol | None)
bucket_event_repository (BucketEventHistoryRepositoryProtocol | None)
rule_repository (object | None)