From 14e9beea0cf91f163021da940f52bda1f2547cc1 Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:40:46 +0530 Subject: [PATCH] New employee exported at field added to Bamboohr table (#117) * New employee exported at field added to Bamboohr table * employees exported update at exporting employees * comment resolved --- .../0005_bamboohr_employee_exported_at.py | 20 +++++++++++++++++++ apps/bamboohr/models.py | 1 + fyle_employee_imports/base.py | 12 ++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 apps/bamboohr/migrations/0005_bamboohr_employee_exported_at.py diff --git a/apps/bamboohr/migrations/0005_bamboohr_employee_exported_at.py b/apps/bamboohr/migrations/0005_bamboohr_employee_exported_at.py new file mode 100644 index 00000000..38fe89b1 --- /dev/null +++ b/apps/bamboohr/migrations/0005_bamboohr_employee_exported_at.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.14 on 2023-12-26 16:05 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('bamboohr', '0004_auto_20221220_0935'), + ] + + operations = [ + migrations.AddField( + model_name='bamboohr', + name='employee_exported_at', + field=models.DateTimeField(auto_now_add=True, help_text='Employee exported to Fyle at datetime'), + preserve_default=False, + ), + ] diff --git a/apps/bamboohr/models.py b/apps/bamboohr/models.py index b050ab7e..a0b57ca5 100644 --- a/apps/bamboohr/models.py +++ b/apps/bamboohr/models.py @@ -17,6 +17,7 @@ class BambooHr(models.Model): sub_domain = models.CharField(max_length=255, null=True, help_text='Bamboo HR Sub Domain') created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime') updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime') + employee_exported_at = models.DateTimeField(auto_now_add=True, help_text='Employee exported to Fyle at datetime') class Meta: db_table = 'bamboohr' diff --git a/fyle_employee_imports/base.py b/fyle_employee_imports/base.py index e170b341..20afb557 100644 --- a/fyle_employee_imports/base.py +++ b/fyle_employee_imports/base.py @@ -1,4 +1,7 @@ from typing import Dict, List +from datetime import datetime + +from apps.bamboohr.models import BambooHr from apps.fyle_hrms_mappings.models import DestinationAttribute, ExpenseAttribute from apps.orgs.models import Org from apps.users.helpers import PlatformConnector @@ -9,6 +12,7 @@ class FyleEmployeeImport(): def __init__(self, org_id: int, user): self.org_id = org_id self.user = user + self.bamboohr = BambooHr.objects.get(org_id__in=self.org_id) refresh_token = AuthToken.objects.get(user__user_id=self.user).refresh_token cluster_domain = Org.objects.get(user__user_id=self.user).cluster_domain self.platform_connection = PlatformConnector(refresh_token, cluster_domain) @@ -115,9 +119,14 @@ def fyle_employee_import(self, hrms_employees): if fyle_employee_payload: self.platform_connection.bulk_post_employees(employees_payload=fyle_employee_payload) + self.bamboohr.employee_exported_at = datetime.now() + if employee_approver_payload: self.platform_connection.bulk_post_employees(employees_payload=employee_approver_payload) + + self.bamboohr.employee_exported_at = datetime.now() + self.bamboohr.save() self.platform_connection.sync_employees(org_id=self.org_id) def sync_hrms_employees(self): @@ -129,7 +138,8 @@ def sync_employees(self): hrms_employees = DestinationAttribute.objects.filter( attribute_type='EMPLOYEE', - org_id=self.org_id + org_id=self.org_id, + updated_at__gte=self.bamboohr.employee_exported_at, ).order_by('value', 'id') self.import_departments(hrms_employees)