Skip to content

Commit

Permalink
Fix: attribute error (#628)
Browse files Browse the repository at this point in the history
* Fix: attribute error

* Add workspace id filter

---------

Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
ruuushhh and GitHub Actions committed Jul 16, 2024
1 parent eb68a46 commit 80841ac
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions apps/netsuite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_department_id_or_none(expense_group: ExpenseGroup, lineitem: Expense):

department_id = None
source_id = None
source_value = None

if department_setting:
if lineitem:
Expand All @@ -53,8 +54,9 @@ def get_department_id_or_none(expense_group: ExpenseGroup, lineitem: Expense):
elif department_setting.source_field == 'COST_CENTER':
source_value = lineitem.cost_center
else:
attribute = ExpenseAttribute.objects.filter(attribute_type=department_setting.source_field).first()
source_value = lineitem.custom_properties.get(attribute.display_name, None)
attribute = ExpenseAttribute.objects.filter(attribute_type=department_setting.source_field, workspace_id=expense_group.workspace_id).first()
if attribute:
source_value = lineitem.custom_properties.get(attribute.display_name, None)
else:
source_value = expense_group.description[department_setting.source_field.lower()]

Expand All @@ -75,6 +77,7 @@ def get_class_id_or_none(expense_group: ExpenseGroup, lineitem: Expense):

class_id = None
source_id = None
source_value = None

if class_setting:
if lineitem:
Expand All @@ -84,8 +87,9 @@ def get_class_id_or_none(expense_group: ExpenseGroup, lineitem: Expense):
elif class_setting.source_field == 'COST_CENTER':
source_value = lineitem.cost_center
else:
attribute = ExpenseAttribute.objects.filter(attribute_type=class_setting.source_field).first()
source_value = lineitem.custom_properties.get(attribute.display_name, None)
attribute = ExpenseAttribute.objects.filter(attribute_type=class_setting.source_field, workspace_id=expense_group.workspace_id).first()
if attribute:
source_value = lineitem.custom_properties.get(attribute.display_name, None)
else:
source_value = expense_group.description[class_setting.source_field.lower()]

Expand Down Expand Up @@ -165,6 +169,7 @@ def get_location_id_or_none(expense_group: ExpenseGroup, lineitem: Expense):

location_id = None
source_id = None
source_value = None

if location_setting:
if lineitem:
Expand All @@ -174,8 +179,9 @@ def get_location_id_or_none(expense_group: ExpenseGroup, lineitem: Expense):
elif location_setting.source_field == 'COST_CENTER':
source_value = lineitem.cost_center
else:
attribute = ExpenseAttribute.objects.filter(attribute_type=location_setting.source_field).first()
source_value = lineitem.custom_properties.get(attribute.display_name, None)
attribute = ExpenseAttribute.objects.filter(attribute_type=location_setting.source_field, workspace_id=expense_group.workspace_id).first()
if attribute:
source_value = lineitem.custom_properties.get(attribute.display_name, None)
else:
source_value = expense_group.description[location_setting.source_field.lower()]

Expand All @@ -194,6 +200,7 @@ def get_custom_segments(expense_group: ExpenseGroup, lineitem: Expense):

custom_segments = []
source_id = None
source_value = None
default_expense_attributes = ['CATEGORY', 'EMPLOYEE', 'TAX_GROUP', 'CORPORATE_CARD']
default_destination_attributes = ['DEPARTMENT', 'CLASS', 'PROJECT', 'LOCATION']

Expand All @@ -210,7 +217,8 @@ def get_custom_segments(expense_group: ExpenseGroup, lineitem: Expense):
attribute_type=setting.source_field,
workspace_id=expense_group.workspace_id
).first()
source_value = lineitem.custom_properties.get(attribute.display_name, None)
if attribute:
source_value = lineitem.custom_properties.get(attribute.display_name, None)

mapping: Mapping = get_filtered_mapping(
setting.source_field, setting.destination_field, expense_group.workspace_id, source_value, source_id
Expand Down

0 comments on commit 80841ac

Please sign in to comment.