"""Task to copy approved sales from _temp to the 'final' snowflake table.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from lib.constants import CONTRACT_TYPES from tasks.sales_approve import helpers from templates.sales_approve.snowflake_copy_approved_sales\ import copy_approved_distribution_sales from templates.sales_approve.snowflake_copy_approved_sales\ import copy_approved_nr_sales def copy_approved_sales(dag_run: dict, **kwargs) -> None: """Copy records from stmt_db_sales_*_temp to stmt_db_sales_*. Args: dag_run (dict): config of the DAG this task belongs to kwargs (dict): any other optional arguments """ event = helpers.get_event_from_params(dag_run, **kwargs) sales_file_id = event.target_id sales_file, accounting_period = helpers.get_event_records(event) contract_type = accounting_period['contract_type'] hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) approved_sales_templates = { CONTRACT_TYPES.DISTRIBUTION: copy_approved_distribution_sales, CONTRACT_TYPES.NEIGHBOURING_RIGHTS: copy_approved_nr_sales } copy_statement = approved_sales_templates[contract_type]().render( env=config.OWS_ENV, sales_file_id=sales_file_id ) hook.run(copy_statement, autocommit=True)