Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New employee exported at field added to Bamboohr table #117

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 12 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,8 +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()
self.bamboohr.save()

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's save only once after both of them are completed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incase the 2nd call fails, we end up storing wrong timestamps


self.platform_connection.sync_employees(org_id=self.org_id)

Expand All @@ -129,7 +139,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
Loading