Skip to content

Commit

Permalink
Added sync for cost_code, cost_category in dep field import (#169)
Browse files Browse the repository at this point in the history
* Added sync for cost_code, cost_category in dep field import

* lint fix

* Added path instead of func in chain

* lint fix
  • Loading branch information
Hrishabh17 authored May 21, 2024
1 parent 79c2f5e commit 72fe27d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,6 @@ docker-compose.yml
# Cache db
cache.db
fyle_integrations_platform_connector/
fyle_accounting_mappings/
fyle_accounting_mappings/

customer_dry_run.py
4 changes: 3 additions & 1 deletion apps/mappings/imports/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from apps.mappings.imports.modules.expense_custom_fields import ExpenseCustomField
from apps.fyle.models import DependentFieldSetting


SOURCE_FIELD_CLASS_MAP = {
'CATEGORY': Category,
'PROJECT': Project,
Expand Down Expand Up @@ -52,6 +51,9 @@ def auto_import_and_map_fyle_fields(workspace_id):
chain = Chain()

if project_mapping and dependent_fields:
chain.append('apps.mappings.tasks.sync_sage300_attributes', 'JOB', workspace_id)
chain.append('apps.mappings.tasks.sync_sage300_attributes', 'COST_CODE', workspace_id)
chain.append('apps.mappings.tasks.sync_sage300_attributes', 'COST_CATEGORY', workspace_id)
chain.append('apps.sage300.dependent_fields.import_dependent_fields_to_fyle', workspace_id)

if chain.length() > 0:
Expand Down
4 changes: 0 additions & 4 deletions apps/sage300/dependent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from apps.fyle.models import DependentFieldSetting
from apps.sage300.models import CostCategory
from apps.fyle.helpers import connect_to_platform
from apps.mappings.tasks import sync_sage300_attributes


logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down Expand Up @@ -145,10 +143,8 @@ def post_dependent_expense_field_values(workspace_id: int, dependent_field_setti

def import_dependent_fields_to_fyle(workspace_id: str):
dependent_field = DependentFieldSetting.objects.get(workspace_id=workspace_id)

try:
platform = connect_to_platform(workspace_id)
sync_sage300_attributes('JOB', workspace_id)
post_dependent_expense_field_values(workspace_id, dependent_field, platform)
except FyleInvalidTokenError:
logger.info('Invalid Token or Fyle credentials does not exist - %s', workspace_id)
Expand Down
23 changes: 0 additions & 23 deletions tests/test_sage300/test_dependent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import_dependent_fields_to_fyle
)
from apps.fyle.models import DependentFieldSetting
from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError


def test_construct_custom_field_placeholder():
Expand Down Expand Up @@ -151,29 +150,7 @@ def test_import_dependent_fields_to_fyle(
'dependent_fields.bulk_post_dependent_expense_field_values'
)

sync_sage300_attributes = mocker.patch('apps.sage300.dependent_fields.sync_sage300_attributes')
import_dependent_fields_to_fyle(workspace_id)

assert platform.return_value.dependent_fields.bulk_post_dependent_expense_field_values.call_count == 4
assert DependentFieldSetting.objects.get(workspace_id=workspace_id).last_successful_import_at is not None
assert sync_sage300_attributes.call_count == 1

sync_sage300_attributes.side_effect = Exception('Error')
try:
import_dependent_fields_to_fyle(workspace_id)

assert platform.return_value.dependent_fields.bulk_post_dependent_expense_field_values.call_count == 4
assert DependentFieldSetting.objects.get(workspace_id=workspace_id).last_successful_import_at is not None
assert sync_sage300_attributes.call_count == 2
except Exception as e:
assert str(e) == 'Error'

sync_sage300_attributes.side_effect = FyleInvalidTokenError('Token Not Found')
try:
import_dependent_fields_to_fyle(workspace_id)

assert platform.return_value.dependent_fields.bulk_post_dependent_expense_field_values.call_count == 4
assert DependentFieldSetting.objects.get(workspace_id=workspace_id).last_successful_import_at is not None
assert sync_sage300_attributes.call_count == 3
except Exception as e:
assert str(e) == 'Token Error'

0 comments on commit 72fe27d

Please sign in to comment.