Skip to content

Commit

Permalink
skip employee mapping validation when merchant name is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 committed Sep 27, 2023
1 parent b4c464c commit 9effee3
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions apps/quickbooks_online/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,25 @@ def __validate_expense_group(expense_group: ExpenseGroup, general_settings: Work
expense_group.fund_source == 'CCC'
and ((general_settings.corporate_credit_card_expenses_object in ('CREDIT CARD PURCHASE', 'DEBIT CARD EXPENSE') and general_settings.map_merchant_to_vendor) or general_settings.corporate_credit_card_expenses_object == 'BILL')
):

employee_attribute = ExpenseAttribute.objects.filter(value=expense_group.description.get('employee_email'), workspace_id=expense_group.workspace_id, attribute_type='EMPLOYEE').first()

try:
entity = EmployeeMapping.objects.get(source_employee=employee_attribute, workspace_id=expense_group.workspace_id)

if general_settings.employee_field_mapping == 'EMPLOYEE':
entity = entity.destination_employee
else:
entity = entity.destination_vendor if entity.destination_vendor and entity.destination_vendor.active else None

if not entity:
raise EmployeeMapping.DoesNotExist
except EmployeeMapping.DoesNotExist:
bulk_errors.append({'row': None, 'expense_group_id': expense_group.id, 'value': expense_group.description.get('employee_email'), 'type': 'Employee Mapping', 'message': 'Employee mapping not found'})
if employee_attribute:
Error.objects.update_or_create(
workspace_id=expense_group.workspace_id, expense_attribute=employee_attribute, defaults={'type': 'EMPLOYEE_MAPPING', 'error_title': employee_attribute.value, 'error_detail': 'Employee mapping is missing', 'is_resolved': False}
)
if not (general_settings.corporate_credit_card_expenses_object == 'JOURNAL ENTRY' and general_settings.name_in_journal_entry == 'EMPLOYEE'):
employee_attribute = ExpenseAttribute.objects.filter(value=expense_group.description.get('employee_email'), workspace_id=expense_group.workspace_id, attribute_type='EMPLOYEE').first()

try:
entity = EmployeeMapping.objects.get(source_employee=employee_attribute, workspace_id=expense_group.workspace_id)

if general_settings.employee_field_mapping == 'EMPLOYEE':
entity = entity.destination_employee
else:
entity = entity.destination_vendor if entity.destination_vendor and entity.destination_vendor.active else None

if not entity:
raise EmployeeMapping.DoesNotExist
except EmployeeMapping.DoesNotExist:
bulk_errors.append({'row': None, 'expense_group_id': expense_group.id, 'value': expense_group.description.get('employee_email'), 'type': 'Employee Mapping', 'message': 'Employee mapping not found'})
if employee_attribute:
Error.objects.update_or_create(
workspace_id=expense_group.workspace_id, expense_attribute=employee_attribute, defaults={'type': 'EMPLOYEE_MAPPING', 'error_title': employee_attribute.value, 'error_detail': 'Employee mapping is missing', 'is_resolved': False}
)

expenses = expense_group.expenses.all()

Expand Down

0 comments on commit 9effee3

Please sign in to comment.