Source code for cadrumo.application.modelo._calculation_aggregation_context
"""Context loading for bucket-aggregation calculation actions.Core types::class:`~cadrumo.domain.calculations.registry.schema.RegistrySnapshot`."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom...core.authority_gradeimportRegistryAuthorityGradefrom...domain.modelos.work_unit_repositoryimportWorkUnitCatalogueRepositoryProtocolfrom._calculation_helpersimportresolve_registry_snapshot_for_work_unitas_resolve_registry_snapshot_for_work_unitfrom.profile_readiness_gateimportrequire_profile_ready_for_work_unitfrom.work_lifecycleimportActiveWorkUnitUse,require_active_work_unitfrom.work_profileimportModeloWorkProfileifTYPE_CHECKING:from...domain.calculations.registry.schemaimportRegistrySnapshotfrom...domain.modelos.work_unitimportWorkUnit
[docs]defload_bucket_aggregation_context(work_unit_id:str,*,work_unit_repository:WorkUnitCatalogueRepositoryProtocol,profile:ModeloWorkProfile|None,)->tuple[WorkUnit,RegistrySnapshot,ModeloWorkProfile]:"""Return ``(work_unit, snapshot, profile)`` for aggregation calculation. ``profile`` is the record the calling command already loaded, or ``None`` for the gate to load it; either way the returned profile is the one the readiness gate checked, and it is the only profile the calculation reads. """work_units=work_unit_repository.load()work_unit=require_active_work_unit(work_units,work_unit_id=work_unit_id,repository_bucket_id=work_unit_repository.bucket_id,use=ActiveWorkUnitUse.CALCULATE,)from...domain.calculations.registry.authorityimportbundled_indexed_authoritywithbundled_indexed_authority().operation()asoperation:checked_profile=require_profile_ready_for_work_unit(work_unit,profile_decode_context=operation.profile_decode_context(),operation=operation,profile=profile,)# The calculate path needs the rung that computes amounts, not the filing# rung: a revision that honestly declares calculation must not be refused# for work this application does entirely in memory. The work unit is held# for ``ActiveWorkUnitUse.CALCULATE`` and no fichero or export layout is# rendered here, so the filing rung would be an authority this path never# exercises -- and demanding it makes a deliberate calculation-grade# revision uncalculable, not merely unfilable.snapshot=_resolve_registry_snapshot_for_work_unit(work_unit,grade=RegistryAuthorityGrade.CALCULATION,operation=operation,)returnwork_unit,snapshot,checked_profile