"""Task to copy approved contract txns from _staging to the 'final' snowflake table.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from lib.constants import CONTRACT_TYPES from lib.utils import ows from tasks.accounting_run_commit.helpers import get_event_from_params from templates.accounting_run_commit.snowflake_copy_contract_transactions\ import copy_contract_transaction_distro_template from templates.accounting_run_commit.snowflake_copy_contract_transactions\ import copy_contract_transaction_nr_template def copy_contract_transactions(dag_run: dict, **kwargs) -> None: """Copy over contract txns from staging to final table.""" event = get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id accounting_run = ows.get_accounting_run_details(accounting_run_id) accounting_period = ows.get_accounting_period_details( accounting_run['accounting_period_id'] ) contract_type = accounting_period['contract_type'] CONTRACT_TRANSACTION_TABLES = { CONTRACT_TYPES.DISTRIBUTION: copy_contract_transaction_distro_template, CONTRACT_TYPES.NEIGHBOURING_RIGHTS: copy_contract_transaction_nr_template } hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) copy_statement = CONTRACT_TRANSACTION_TABLES[contract_type]().render( accounting_run_id=accounting_run_id, environment=config.OWS_ENV, ) hook.run(copy_statement, autocommit=True)