From 416c5969ee238d9889d457eb0b78cff1933cf1ce Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 2 Jan 2024 21:00:14 +0530 Subject: [PATCH] tested and bug fix --- apps/bamboohr/tasks.py | 7 ++++--- apps/bamboohr/urls.py | 3 ++- apps/bamboohr/views.py | 2 +- fyle_employee_imports/bamboo_hr.py | 17 +++++++++++------ fyle_employee_imports/base.py | 3 +-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/apps/bamboohr/tasks.py b/apps/bamboohr/tasks.py index 3ea39c9d..77a760a1 100644 --- a/apps/bamboohr/tasks.py +++ b/apps/bamboohr/tasks.py @@ -15,14 +15,16 @@ def update_employee(org_id: int, user: User, payload: dict): """ Update employee in fyle when employee in Bamboohr is added or updated """ - bamboohr = BambooHr.objects.get(org_id__in=org_id, is_credentials_expired=False) + bamboohr = BambooHr.objects.get(org_id__in=[org_id], is_credentials_expired=False) bamboohr_importer = BambooHrEmployeeImport(org_id=org_id, user=user) employee_payload = {'employees': []} payload = payload['employees'][0] employee = {} + employee['id'] = payload['id'] + employee['firstName'] = payload['fields']['firstName']['value'] + employee['lastName'] = payload['fields']['lastName']['value'] for field in payload['changedFields']: - employee['id'] = payload['id'] employee[field] = payload['fields'][field]['value'] employee_payload['employees'].append(employee) @@ -34,6 +36,5 @@ def update_employee(org_id: int, user: User, payload: dict): org_id=org_id, updated_at__gte=bamboohr.employee_exported_at, ).order_by('value', 'id') - bamboohr_importer.import_departments(hrms_employees=hrms_employees) bamboohr_importer.fyle_employee_import(hrms_employees=hrms_employees) diff --git a/apps/bamboohr/urls.py b/apps/bamboohr/urls.py index 5de8f5b4..d165370e 100644 --- a/apps/bamboohr/urls.py +++ b/apps/bamboohr/urls.py @@ -1,11 +1,12 @@ from django.urls import path from .views import PostFolder, PostPackage, BambooHrConnection, BambooHrView, BambooHrConfigurationView, \ - DisconnectView, SyncEmployeesView, HealthCheck + DisconnectView, SyncEmployeesView, HealthCheck, WebhookAPIView app_name = 'bamboohr' urlpatterns = [ + path('webhook_callback/', WebhookAPIView.as_view(), name='webhook-callback'), path('health_check/', HealthCheck.as_view(), name='health-check'), path('', BambooHrView.as_view(), name='bamboohr'), path('packages/', PostPackage.as_view(), name='package'), diff --git a/apps/bamboohr/views.py b/apps/bamboohr/views.py index 60ecc35d..4da0420e 100644 --- a/apps/bamboohr/views.py +++ b/apps/bamboohr/views.py @@ -63,7 +63,7 @@ def post(self, request, *args, **kwargs): { 'status': 'success' }, - status=status.HTTP_201_OK + status=status.HTTP_201_CREATED ) class BambooHrView(generics.ListAPIView): diff --git a/fyle_employee_imports/bamboo_hr.py b/fyle_employee_imports/bamboo_hr.py index 91ffddd2..fbfd8b76 100644 --- a/fyle_employee_imports/bamboo_hr.py +++ b/fyle_employee_imports/bamboo_hr.py @@ -19,18 +19,23 @@ def sync_hrms_employees(self): def upsert_employees(self, employees: Dict): attributes = [] for employee in employees['employees']: - supervisor = [employee['supervisorEmail']] if employee['supervisorEmail'] else None - active_status = True if employee['status'] == 'Active' else False + supervisor = [employee.get('supervisorEmail', None)] + active_status = True if employee.get('status', None) == 'Active' else False + + display_name = employee.get('displayName', None) + if not display_name: + display_name = employee['firstName'] + ' ' + employee['lastName'] + detail = { - 'email': employee['workEmail'] if employee['workEmail'] else None, - 'department_name': employee['department'] if employee['department'] else None, - 'full_name': employee['displayName'] if employee['displayName'] else None, + 'email': employee.get('workEmail', None), + 'department_name': employee.get('department', None), + 'full_name': display_name, 'approver_emails': supervisor, } attributes.append({ 'attribute_type': 'EMPLOYEE', - 'value': employee['displayName'], + 'value': display_name, 'destination_id': employee['id'], 'detail': detail, 'active': active_status diff --git a/fyle_employee_imports/base.py b/fyle_employee_imports/base.py index d83710d0..5211fda0 100644 --- a/fyle_employee_imports/base.py +++ b/fyle_employee_imports/base.py @@ -115,7 +115,6 @@ def get_employee_and_approver_payload(self, hrms_employees): def fyle_employee_import(self, hrms_employees): fyle_employee_payload, employee_approver_payload = self.get_employee_and_approver_payload(hrms_employees) - if fyle_employee_payload: self.platform_connection.bulk_post_employees(employees_payload=fyle_employee_payload) @@ -141,6 +140,6 @@ def sync_employees(self): org_id=self.org_id, updated_at__gte=self.bamboohr.employee_exported_at, ).order_by('value', 'id') - + self.import_departments(hrms_employees) self.fyle_employee_import(hrms_employees)