"""Task to take reserves for the given accounting run.""" from lib.constants import CONTRACT_TYPES from lib.utils import ows from tasks.accounting_run_commit import helpers def debit_reserves_for_accounting_run_task(dag_run: dict, *args, **kwargs): """POST to ows-ledger to take reserves for the given accounting run. Only if the accounting_run is in a distribution accounting_period. Args: dag_run (dict): a dag's config """ abacus_event = helpers.get_event_from_params(dag_run, **kwargs) accounting_run_id = abacus_event.target_id task_instance = kwargs.get('task_instance') contract_type = task_instance.xcom_pull( task_ids='contract_type_branch', key='contract_type' ) if not contract_type: accounting_period, _ = helpers.get_event_records(accounting_run_id) contract_type = accounting_period.get('contract_type') if contract_type != CONTRACT_TYPES.DISTRIBUTION: print(f'DO NOT DEBIT RESERVES IN {contract_type} ACCOUNTING PERIOD') return ows.debit_reserves_from_ledger_account_by_run(accounting_run_id)