diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 58d9ff7..733fe95 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -15,9 +15,9 @@ jobs: - uses: actions/checkout@v2 - name: Bring up Services and Run Tests run: | - docker-compose -f docker-compose-pipeline.yml build - docker-compose -f docker-compose-pipeline.yml up -d - docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=70 + docker compose -f docker-compose-pipeline.yml build + docker compose -f docker-compose-pipeline.yml up -d + docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=70 echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV - name: Upload coverage reports to Codecov with GitHub Action diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e7d2c1b..f6a7e9e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,9 +12,9 @@ jobs: - uses: actions/checkout@v2 - name: Bring up Services and Run Tests run: | - docker-compose -f docker-compose-pipeline.yml build - docker-compose -f docker-compose-pipeline.yml up -d - docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=70 + docker compose -f docker-compose-pipeline.yml build + docker compose -f docker-compose-pipeline.yml up -d + docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=70 echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV - name: Upload coverage reports to Codecov with GitHub Action diff --git a/apps/sage300/dependent_fields.py b/apps/sage300/dependent_fields.py index 649a678..d0d18f6 100644 --- a/apps/sage300/dependent_fields.py +++ b/apps/sage300/dependent_fields.py @@ -158,7 +158,7 @@ def post_dependent_cost_code(import_log: ImportLog, dependent_field_setting: Dep @handle_import_exceptions -def post_dependent_cost_type(import_log: ImportLog, dependent_field_setting: DependentFieldSetting, platform: PlatformConnector, filters: Dict, posted_cost_codes: List = []): +def post_dependent_cost_type(import_log: ImportLog, dependent_field_setting: DependentFieldSetting, platform: PlatformConnector, filters: Dict): import_settings = ImportSetting.objects.filter(workspace_id=import_log.workspace.id).first() use_cost_code_in_naming = False use_category_code_in_naming = False @@ -192,29 +192,28 @@ def post_dependent_cost_type(import_log: ImportLog, dependent_field_setting: Dep import_log.save() for category in cost_categories: - if category['cost_code_name'] in posted_cost_codes: - cost_code_name = prepend_code_to_name(prepend_code_in_name=use_cost_code_in_naming, value=category['cost_code_name'], code=category['cost_code_code']) - payload = [] + cost_code_name = prepend_code_to_name(prepend_code_in_name=use_cost_code_in_naming, value=category['cost_code_name'], code=category['cost_code_code']) + payload = [] - for cost_type in category['cost_categories']: - cost_type_name = prepend_code_to_name(prepend_code_in_name=use_category_code_in_naming, value=cost_type['cost_category_name'], code=cost_type['cost_category_code']) - payload.append({ - 'parent_expense_field_id': dependent_field_setting.cost_code_field_id, - 'parent_expense_field_value': cost_code_name, - 'expense_field_id': dependent_field_setting.cost_category_field_id, - 'expense_field_value': cost_type_name, - 'is_enabled': True - }) + for cost_type in category['cost_categories']: + cost_type_name = prepend_code_to_name(prepend_code_in_name=use_category_code_in_naming, value=cost_type['cost_category_name'], code=cost_type['cost_category_code']) + payload.append({ + 'parent_expense_field_id': dependent_field_setting.cost_code_field_id, + 'parent_expense_field_value': cost_code_name, + 'expense_field_id': dependent_field_setting.cost_category_field_id, + 'expense_field_value': cost_type_name, + 'is_enabled': True + }) - if payload: - sleep(0.2) - try: - platform.dependent_fields.bulk_post_dependent_expense_field_values(payload) - CostCategory.objects.filter(cost_code_name=category['cost_code_name']).update(is_imported=True) - processed_batches += 1 - except Exception as exception: - is_errored = True - logger.error(f'Exception while posting dependent cost type | Error: {exception} | Payload: {payload}') + if payload: + sleep(0.2) + try: + platform.dependent_fields.bulk_post_dependent_expense_field_values(payload) + CostCategory.objects.filter(cost_code_name=category['cost_code_name']).update(is_imported=True) + processed_batches += 1 + except Exception as exception: + is_errored = True + logger.error(f'Exception while posting dependent cost type | Error: {exception} | Payload: {payload}') import_log.status = 'PARTIALLY_FAILED' if is_errored else 'COMPLETE' import_log.error_log = [] @@ -250,7 +249,7 @@ def post_dependent_expense_field_values(workspace_id: int, dependent_field_setti cost_category_import_log.save() return else: - is_cost_type_errored = post_dependent_cost_type(cost_category_import_log, dependent_field_setting, platform, filters, posted_cost_codes) + is_cost_type_errored = post_dependent_cost_type(cost_category_import_log, dependent_field_setting, platform, filters) if not is_cost_type_errored and not is_cost_code_errored and cost_category_import_log.processed_batches_count > 0: DependentFieldSetting.objects.filter(workspace_id=workspace_id).update(last_successful_import_at=datetime.now()) diff --git a/tests/test_sage300/test_dependent_fields.py b/tests/test_sage300/test_dependent_fields.py index cca80b7..6bf2a63 100644 --- a/tests/test_sage300/test_dependent_fields.py +++ b/tests/test_sage300/test_dependent_fields.py @@ -120,7 +120,8 @@ def test_post_dependent_cost_type( ) filters = { - "workspace_id": workspace_id + "workspace_id": workspace_id, + "cost_code_name__in": ['Direct Mail Campaign', 'Platform APIs'] } dependent_field_settings = DependentFieldSetting.objects.get(workspace_id=workspace_id) @@ -132,8 +133,7 @@ def test_post_dependent_cost_type( cost_category_import_log, dependent_field_setting=dependent_field_settings, platform=platform.return_value, - filters=filters, - posted_cost_codes=['Direct Mail Campaign', 'Platform APIs'] + filters=filters ) assert platform.return_value.dependent_fields.bulk_post_dependent_expense_field_values.call_count == 2 @@ -150,12 +150,16 @@ def test_post_dependent_cost_type( ImportSetting.objects.filter(workspace_id=workspace_id).update(import_code_fields=['JOB', 'COST_CODE', 'COST_CATEGORY']) CostCategory.objects.filter(workspace_id=workspace_id).update(job_code='123', cost_code_code='456', cost_category_code='789') + filters = { + "workspace_id": workspace_id, + "cost_code_name__in": ['CRE Platform', 'Integrations CRE'] + } + post_dependent_cost_type( cost_category_import_log, dependent_field_setting=dependent_field_settings, platform=platform.return_value, - filters=filters, - posted_cost_codes=['CRE Platform', 'Integrations CRE'] + filters=filters ) assert platform.return_value.dependent_fields.bulk_post_dependent_expense_field_values.call_count == 4