"""Logic for updating statement_period_payment_entity actions state.""" from typing import Type from owsresponse import response from abacus_state.constants.constants import ( ABACUS_OUTBOX_EVENT_TYPES, ABACUS_OUTBOX_STATUSES, ACTION_STATUSES, ) from abacus_state.models.abacus_outbox import AbacusOutbox from abacus_state.models.abacus_state import AbacusState from abacus_state.schemas.abacus_state import AbacusStateDetailSchema def update_statement_period_payment_entity_state( abacus_state: Type[AbacusState], **params ): """Update statement_period_payment_entity state by abacus_state_id. Args: abacus_state (AbacusState): AbacusState instance to be updated params (dict): dict of fields to be updated (i.e. action_status, message) Returns: an owsresponse Response object """ abacus_state.update_attributes(**params) if abacus_state.action_status == ACTION_STATUSES.COMPLETE: AbacusOutbox.build( target_type=abacus_state.parent_table_name, target_id=abacus_state.parent_table_id, event_type=ABACUS_OUTBOX_EVENT_TYPES.CLOSE_BALANCE_COMPLETED, status=ABACUS_OUTBOX_STATUSES.PENDING, ) AbacusState.commit_changes() return response.Response( message=AbacusStateDetailSchema().dump(abacus_state), status=200 )