"""Task to calculate mech deductions and insert them into snowflake staging table.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from tasks.accounting_run_calculate import helpers from templates.accounting_run_calculate.\ snowflake_calculate_mechanical_deduction_results \ import calculate_mech_deductions_template def calculate_mech_deductions_task(dag_run: dict, **kwargs) -> None: """Calculate and stage distro mechanical deductions. Use ACCOUNTING_RUN_RESULTS_DISTRO_STAGING, CONTRACT_TRANSACTION_STAGING, SNAPSHOT_MECHANICAL_TRANSACTION, contract_mechanical_deduction, and exchange_rate to calculate mech deductions by transaction and insert into ACCOUNTING_RUN_RESULTS_DISTRO_MECH_STAGING. NOTE: At this time the calculation is for US SALES ONLY. 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) accounting_run_id = event.target_id hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) insert_statement = calculate_mech_deductions_template().render( accounting_run_id=accounting_run_id, schema=config.OWS_ENV ) hook.run(insert_statement, autocommit=True)