-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Create Employee on Webhook trigger
- Loading branch information
1 parent
0dc08d7
commit abeb483
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
from apps.bamboohr.models import BambooHr | ||
from apps.fyle_hrms_mappings.models import DestinationAttribute | ||
from fyle_employee_imports.bamboo_hr import BambooHrEmployeeImport | ||
from apps.users.models import User | ||
|
||
def refresh_employees(org_id, user): | ||
|
||
bambooHrImporter = BambooHrEmployeeImport(org_id=org_id, user=user) | ||
bambooHrImporter.sync_employees() | ||
|
||
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_importer = BambooHrEmployeeImport(org_id=org_id, user=user) | ||
|
||
employee_payload = {'employees': []} | ||
payload = payload['employees'][0] | ||
employee = {} | ||
for field in payload['changedFields']: | ||
employee['id'] = payload['id'] | ||
employee[field] = payload['fields'][field]['value'] | ||
|
||
employee_payload['employees'].append(employee) | ||
|
||
bamboohr_importer.upsert_employees(employees=employee_payload) | ||
|
||
hrms_employees = DestinationAttribute.objects.filter( | ||
attribute_type='EMPLOYEE', | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters