Skip to content

Commit

Permalink
Duplicate vendor name exist DB sanity test (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh authored Jun 14, 2023
1 parent 9b84249 commit ad7f6c3
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions apps/quickbooks_online/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,29 @@ def create_or_update_employee_mapping(expense_group: ExpenseGroup, qbo_connectio
create=True
)

existing_employee_mapping = EmployeeMapping.objects.filter(
source_employee=source_employee
).first()

destination = {}
if existing_employee_mapping:
destination['destination_employee_id'] = existing_employee_mapping.destination_employee_id
destination['destination_card_account_id'] = existing_employee_mapping.destination_card_account_id

mapping = EmployeeMapping.create_or_update_employee_mapping(
source_employee_id=source_employee.id,
destination_vendor_id=entity.id,
workspace=expense_group.workspace,
**destination
)
if entity:
existing_employee_mapping = EmployeeMapping.objects.filter(
source_employee=source_employee
).first()

destination = {}
if existing_employee_mapping:
destination['destination_employee_id'] = existing_employee_mapping.destination_employee_id
destination['destination_card_account_id'] = existing_employee_mapping.destination_card_account_id

mapping = EmployeeMapping.create_or_update_employee_mapping(
source_employee_id=source_employee.id,
destination_vendor_id=entity.id,
workspace=expense_group.workspace,
**destination
)

mapping.source_employee.auto_mapped = True
mapping.source_employee.save()
mapping.source_employee.auto_mapped = True
mapping.source_employee.save()

mapping.destination_vendor.auto_created = True
mapping.destination_vendor.save()
mapping.destination_vendor.auto_created = True
mapping.destination_vendor.save()
return
except WrongParamsError as bad_request:
logger.error(bad_request.response)

Expand All @@ -220,13 +222,13 @@ def create_or_update_employee_mapping(expense_group: ExpenseGroup, qbo_connectio
}
)

raise BulkError('Mappings are missing', [{
'row': None,
'expense_group_id': expense_group.id,
'value': expense_group.description.get('employee_email'),
'type': 'Employee Mapping',
'message': 'Employee mapping not found'
}])
raise BulkError('Mappings are missing', [{
'row': None,
'expense_group_id': expense_group.id,
'value': expense_group.description.get('employee_email'),
'type': 'Employee Mapping',
'message': 'Employee mapping not found'
}])


def handle_quickbooks_error(exception, expense_group: ExpenseGroup, task_log: TaskLog, export_type: str):
Expand Down

0 comments on commit ad7f6c3

Please sign in to comment.