Skip to content

Commit

Permalink
tested and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Jan 2, 2024
1 parent 6b7e151 commit 416c596
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions apps/bamboohr/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
3 changes: 2 additions & 1 deletion apps/bamboohr/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion apps/bamboohr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 11 additions & 6 deletions fyle_employee_imports/bamboo_hr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions fyle_employee_imports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

0 comments on commit 416c596

Please sign in to comment.