"""Task to get eligible sales in snowflake.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from lib.constants import CONTRACT_TYPES from lib.utils import ows from tasks.sales_get_eligible.helpers import get_event_from_params from templates.sales_get_eligible.snowflake_get_eligible_sales\ import copy_distribution_sales_from_staging_to_temp from templates.sales_get_eligible.snowflake_get_eligible_sales\ import copy_nr_sales_from_staging_to_temp def get_eligible_sales(dag_run: dict, **kwargs) -> None: """Copy records from stmt_db_sales_*_staging to stmt_db_sales_*_temp. Args: dag_run (dict): config of the DAG this task belongs to kwargs (dict): any other optional arguments """ event = get_event_from_params(dag_run, **kwargs) sales_file_id = event.target_id sales_file = ows.get_sales_file_details(sales_file_id) accounting_period = ows.get_accounting_period_details( sales_file['accounting_period_id'] ) contract_type = accounting_period['contract_type'] hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) sales_query_templates = { CONTRACT_TYPES.DISTRIBUTION: copy_distribution_sales_from_staging_to_temp, CONTRACT_TYPES.NEIGHBOURING_RIGHTS: copy_nr_sales_from_staging_to_temp } snowflake_statement = sales_query_templates[contract_type]().render( env=config.OWS_ENV, sales_file_id=sales_file_id ) hook.run(snowflake_statement, autocommit=True)