Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job, Dep Field code-prepending support #206

Merged
merged 13 commits into from
Jul 23, 2024
4 changes: 2 additions & 2 deletions apps/mappings/helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

def format_attribute_name(use_code_in_naming: bool, attribute_name: str, attribute_code: str = None) -> str:
Hrishabh17 marked this conversation as resolved.
Show resolved Hide resolved
"""
Format the attribute name based on the use_code_in_naming
Format the attribute name based on the use_code_in_naming flag
"""
if use_code_in_naming:
if use_code_in_naming and attribute_code:
return "{} {}".format(attribute_code, attribute_name)
return attribute_name
2 changes: 2 additions & 0 deletions apps/sage300/dependent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def post_dependent_cost_code(import_log: ImportLog, dependent_field_setting: Dep
for project in projects:
project_name = format_attribute_name(use_code_in_naming=use_job_code_in_naming, attribute_name=project['job_name'], attribute_code=project['job_code'])
projects_from_categories.append(project_name)
print(projects_from_categories)
Hrishabh17 marked this conversation as resolved.
Show resolved Hide resolved

existing_projects_in_fyle = ExpenseAttribute.objects.filter(
workspace_id=dependent_field_setting.workspace_id,
Expand All @@ -117,6 +118,7 @@ def post_dependent_cost_code(import_log: ImportLog, dependent_field_setting: Dep
active=True
).values_list('value', flat=True)

print(existing_projects_in_fyle)
Hrishabh17 marked this conversation as resolved.
Show resolved Hide resolved
import_log.total_batches_count = len(existing_projects_in_fyle)
import_log.save()

Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ def add_import_settings():
ImportSetting.objects.create(
workspace_id=workspace_id,
import_categories=False,
import_vendors_as_merchants=False
import_vendors_as_merchants=False,
import_code_fields = []
)


Expand Down
19 changes: 19 additions & 0 deletions tests/test_mappings/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from apps.mappings.helpers import format_attribute_name


def test_format_attribute_name():
# Test case 1: use_code_in_naming is True and attribute_code is not None
result = format_attribute_name(True, "attribute_name", "attribute_code")
assert result == "attribute_code attribute_name"

# Test case 2: use_code_in_naming is True but attribute_code is None
result = format_attribute_name(True, "attribute_name", None)
assert result == "attribute_name"

# Test case 3: use_code_in_naming is False and attribute_code is not None
result = format_attribute_name(False, "attribute_name", "attribute_code")
assert result == "attribute_name"

# Test case 4: use_code_in_naming is False and attribute_code is None
result = format_attribute_name(False, "attribute_name", None)
assert result == "attribute_name"
12 changes: 8 additions & 4 deletions tests/test_sage300/test_dependent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def test_post_dependent_cost_code(
create_temp_workspace,
add_cost_category,
add_dependent_field_setting,
add_project_mappings
add_project_mappings,
add_import_settings
):
workspace_id = 1

Expand Down Expand Up @@ -92,7 +93,8 @@ def test_post_dependent_cost_type(
create_temp_workspace,
add_cost_category,
add_dependent_field_setting,
add_project_mappings
add_project_mappings,
add_import_settings
):
workspace_id = 1

Expand Down Expand Up @@ -136,7 +138,8 @@ def test_post_dependent_expense_field_values(
create_temp_workspace,
add_cost_category,
add_dependent_field_setting,
add_project_mappings
add_project_mappings,
add_import_settings
):
workspace_id = 1

Expand Down Expand Up @@ -167,7 +170,8 @@ def test_import_dependent_fields_to_fyle(
create_temp_workspace,
add_cost_category,
add_dependent_field_setting,
add_project_mappings
add_project_mappings,
add_import_settings
):
workspace_id = 1

Expand Down
26 changes: 19 additions & 7 deletions tests/test_sage300/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
disable_projects,
update_and_disable_cost_code
)
from apps.workspaces.models import Workspace, Sage300Credential
from apps.workspaces.models import Workspace, Sage300Credential, ImportSetting
from fyle_accounting_mappings.models import ExpenseAttribute
from apps.fyle.models import DependentFieldSetting
from apps.sage300.models import CostCategory
Expand Down Expand Up @@ -101,7 +101,9 @@ def test_disable_projects(
projects_to_disable = {
'destination_id': {
'value': 'old_project',
'updated_value': 'new_project'
'updated_value': 'new_project',
'code': 'old_project_code',
'updated_code': 'old_project_code'
}
}

Expand Down Expand Up @@ -129,7 +131,9 @@ def test_disable_projects(
projects_to_disable = {
'destination_id': {
'value': 'old_project_2',
'updated_value': 'new_project'
'updated_value': 'new_project',
'code': 'old_project_code',
'updated_code': 'new_project_code'
}
}

Expand All @@ -145,17 +149,25 @@ def test_update_and_disable_cost_code(
create_temp_workspace,
add_fyle_credentials,
add_dependent_field_setting,
add_cost_category
add_cost_category,
add_import_settings
):
workspace_id = 1

projects_to_disable = {
'destination_id': {
'value': 'old_project',
'updated_value': 'new_project'
'updated_value': 'new_project',
'code': 'old_project_code',
'updated_code': 'old_project_code'
}
}

import_settings = ImportSetting.objects.get(workspace_id=workspace_id)
use_code_in_naming = False
if 'JOB' in import_settings.import_code_fields:
use_code_in_naming = True

cost_category = CostCategory.objects.filter(workspace_id=workspace_id).first()
cost_category.job_name = 'old_project'
cost_category.job_id = 'destination_id'
Expand All @@ -175,7 +187,7 @@ def test_update_and_disable_cost_code(
mocker.patch.object(mock_platform.return_value.cost_centers, 'sync')
mocker.patch.object(mock_platform.return_value.dependent_fields, 'bulk_post_dependent_expense_field_values')

update_and_disable_cost_code(workspace_id, projects_to_disable, mock_platform)
update_and_disable_cost_code(workspace_id, projects_to_disable, mock_platform, use_code_in_naming)

updated_cost_category = CostCategory.objects.filter(workspace_id=workspace_id, job_id='destination_id').first()
assert updated_cost_category.job_name == 'new_project'
Expand All @@ -185,7 +197,7 @@ def test_update_and_disable_cost_code(

DependentFieldSetting.objects.get(workspace_id=workspace_id).delete()

update_and_disable_cost_code(workspace_id, projects_to_disable, mock_platform)
update_and_disable_cost_code(workspace_id, projects_to_disable, mock_platform, use_code_in_naming)

updated_cost_category = CostCategory.objects.filter(workspace_id=workspace_id, job_id='destination_id').first()
assert updated_cost_category.job_name == 'old_project'
7 changes: 5 additions & 2 deletions tests/test_sage300/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ def test__create_destination_attribute(
destination_id = 1
active = True
detail = 'test'
code = '123'

expected_result = {
'attribute_type': attribute_type,
'display_name': display_name,
'value': value,
'destination_id': destination_id,
'active': active,
'detail': detail
'detail': detail,
'code': code
}

assert sage_connector._create_destination_attribute(
Expand All @@ -62,7 +64,8 @@ def test__create_destination_attribute(
value=value,
destination_id=destination_id,
active=active,
detail=detail
detail=detail,
code=code
) == expected_result


Expand Down
Loading