"""A Task to populate accounting_period_report table with s3 vat links.""" from lib.config import VAT_APPLIED_COUNTRY_CODES from lib.utils import aws from lib.utils import ows from tasks.accounting_period_calculate_vat import helpers def create_accounting_period_report_task(dag_run, **kwargs): """Check if vat s3 links exist on s3 and send them to ows-royalties.""" event = helpers.get_event_from_params(dag_run, **kwargs) accounting_period = ows.get_accounting_period_details(event.target_id) accounting_period_id = accounting_period.get('accounting_period_id') for country_code in VAT_APPLIED_COUNTRY_CODES.split(','): report_type = f'vat_applied_{country_code.lower()}' vat_applied_s3_path = helpers.build_vat_report_path( accounting_period_id, accounting_period.get('accounting_period_name'), report_type=report_type ) if aws.file_exists(vat_applied_s3_path): ows.create_accounting_period_report( accounting_period_id, report_type=report_type, report_url=vat_applied_s3_path ) vat_exempt_s3_path = helpers.build_vat_report_path( accounting_period_id, accounting_period.get('accounting_period_name'), report_type='vat_exempt' ) if aws.file_exists(vat_exempt_s3_path): ows.create_accounting_period_report( accounting_period_id, report_type='vat_exempt', report_url=vat_exempt_s3_path )