Skip to content

Commit

Permalink
remove unnecessary check
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrishabh17 committed Aug 7, 2024
1 parent fc13efb commit 34c6751
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 22 additions & 23 deletions apps/sage300/dependent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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())

Expand Down
14 changes: 9 additions & 5 deletions tests/test_sage300/test_dependent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 34c6751

Please sign in to comment.