aeat.application.ledger._actions_split_merge module¶
Split and merge services for manual ledger transaction lineage.
Split operations load a TransactionCatalogue through a
TransactionCatalogueRepository, mark parent and child rows with
SplitLineage, append audit events through a
BucketEventHistoryRepository, and return
SplitTransactionResult. Merge operations
verify the complete child cohort and return
MergeTransactionsResult.
- split_transaction(*, bucket_id, transaction_id, children, actor, source_command='aeat app ledger split', reason='', transaction_repository=None, bucket_event_repository=None, work_unit_repository=None, calculation_repository=None, occurred_at=None)[source]¶
Redistribute one parent transaction into N child transactions.
Pre-conditions:
Parent must be in ACTIVE lifecycle state.
Parent must not be referenced by a finalized modelo calculation.
At least two children must be supplied.
Sum of child amounts equals the parent amount exactly (no rounding).
Child amounts are non-negative magnitudes; direction is inherited from the parent (the builder copies
parent.direction).
Effect:
Parent transitions ACTIVE -> SPLIT and gains
split_lineagewith role=PARENT and the child ids as siblings.Each child is persisted as ACTIVE with
split_lineagerole=CHILD and (parent + other-child) ids as siblings.Children inherit currency, direction, and (by default) counterparty / booked_date / value_date from the parent.
Children default to
BusinessClassification.NOT_YET_PROCESSEDto force conscious tax treatment per row; classification, evidence, and attachment links are NOT auto-cloned.A single
LEDGER_TRANSACTION_SPLITevent is emitted, anchored on the parent transaction id sofor_object(parent_id)returns the whole lineage chain in chronological order.Catalogue + event are persisted atomically.
Returns a
SplitTransactionResult.- Return type:
- Parameters:
bucket_id (str)
transaction_id (str)
children (tuple[SplitChildCommand, ...])
actor (str)
source_command (str)
reason (str)
transaction_repository (TransactionCatalogueRepositoryProtocol | None)
bucket_event_repository (BucketEventHistoryRepositoryProtocol | None)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
occurred_at (datetime | None)
- merge_transactions(*, bucket_id, child_transaction_ids, actor, source_command='aeat app ledger merge', reason='', transaction_repository=None, bucket_event_repository=None, work_unit_repository=None, calculation_repository=None, occurred_at=None)[source]¶
Re-merge a complete cohort of split children into a fresh transaction.
Returns a
MergeTransactionsResult.Pre-conditions:
At least two child ids supplied.
All children exist in the catalogue.
All children share the same
split_group_id.All children are currently ACTIVE.
The parent recorded in each child’s lineage is in SPLIT state.
The cohort is complete - the children supplied must equal the parent’s recorded sibling set (no partial re-merge).
Neither the parent nor any child is referenced by a finalized modelo calculation.
Effect:
Children transition ACTIVE -> ARCHIVED with a lifecycle lineage entry recording the merge.
Parent transitions SPLIT -> ARCHIVED with its lifecycle lineage extended; the parent’s split_lineage role=PARENT is preserved for audit so the chain is reconstructable.
A fresh transaction is persisted with a content-addressed id derived from a synthesized
merged:{split_group_id}provider key plus the parent’s amount / narrative / value_date, andsplit_lineagerole=MERGED carrying the merged child ids.One
LEDGER_TRANSACTION_MERGEDevent is emitted, anchored on the parent transaction id sofor_object(parent_id)returns the entire split + merge chain in chronological order.Catalogue + event are persisted atomically.
- Return type:
- Parameters:
bucket_id (str)
actor (str)
source_command (str)
reason (str)
transaction_repository (TransactionCatalogueRepositoryProtocol | None)
bucket_event_repository (BucketEventHistoryRepositoryProtocol | None)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
occurred_at (datetime | None)