Skip to content

Commit

Permalink
New employee exported at field added to Bamboohr table (#117)
Browse files Browse the repository at this point in the history
* New employee exported at field added to Bamboohr table

* employees exported update at exporting employees

* comment resolved
  • Loading branch information
Ashutosh619-sudo authored Dec 27, 2023
1 parent 263c4e0 commit 14e9bee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
20 changes: 20 additions & 0 deletions apps/bamboohr/migrations/0005_bamboohr_employee_exported_at.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
1 change: 1 addition & 0 deletions apps/bamboohr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 11 additions & 1 deletion fyle_employee_imports/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 14e9bee

Please sign in to comment.