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

feat: Add support for optional dependent fields sync #94

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,56 +48,62 @@ def bulk_post_dependent_expense_field_values(self, data):
return self.connection.bulk_post_dependent_expense_field_values(payload)


def sync(self):
def sync(self, skip_dependent_field_ids: list):
"""
Syncs the latest API data to DB.
:param skip_dependent_field_ids: List of dependent field IDs to skip
"""
params = {
'order': 'updated_at.desc',
'is_enabled': 'eq.true',
'is_custom': 'eq.true',
'type': 'eq.DEPENDENT_SELECT'
}

if skip_dependent_field_ids:
params['id'] = f'not_in.({",".join(map(str, skip_dependent_field_ids))})'

generator = self.expense_fields_connection.list_all(
query_params={
'order': 'updated_at.desc',
'is_enabled': 'eq.true',
'is_custom': 'eq.true',
'type': 'eq.DEPENDENT_SELECT'
}
query_params=params
)

for items in generator:
for row in items['data']:
parent_field_id = row['parent_field_id']
id = row['id']

options_generator = self.connection.list_all(
{
'expense_field_id': f'eq.{id}',
'parent_expense_field_id': f'eq.{parent_field_id}',
'order': 'id.desc'
}
)

attributes = []
count = 1
attribute_type = row['field_name'].upper().replace(' ', '_')

options_list = []
for options in options_generator:
for option in options['data']:
if option['expense_field_value'] not in options_list:
options_list.append(option['expense_field_value'])

attributes.append({
'attribute_type': attribute_type,
'display_name': row['field_name'],
'value': option['expense_field_value'],
'active': True,
'source_id': 'expense_custom_field.{}.{}'.format(row['field_name'].lower(), count),
'detail': {
'custom_field_id': row['id'],
'placeholder': row['placeholder'],
'is_mandatory': row['is_mandatory'],
'is_dependent': True
}
})
count = count + 1

self.attribute_type = attribute_type
self.bulk_create_or_update_expense_attributes(attributes, True)
if parent_field_id:
options_generator = self.connection.list_all(
{
'expense_field_id': f'eq.{id}',
'parent_expense_field_id': f'eq.{parent_field_id}',
'order': 'id.desc'
}
)

attributes = []
count = 1
attribute_type = row['field_name'].upper().replace(' ', '_')

options_list = []
for options in options_generator:
for option in options['data']:
if option['expense_field_value'] not in options_list:
options_list.append(option['expense_field_value'])

attributes.append({
'attribute_type': attribute_type,
'display_name': row['field_name'],
'value': option['expense_field_value'],
'active': True,
'source_id': 'expense_custom_field.{}.{}'.format(row['field_name'].lower(), count),
'detail': {
'custom_field_id': row['id'],
'placeholder': row['placeholder'],
'is_mandatory': row['is_mandatory'],
'is_dependent': True
}
})
count = count + 1

self.attribute_type = attribute_type
self.bulk_create_or_update_expense_attributes(attributes, True)
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def set_workspace_id(self):
self.dependent_fields.set_workspace_id(self.workspace_id)
self.reports.set_workspace_id(self.workspace_id)

def import_fyle_dimensions(self, import_taxes: bool = False, import_dependent_fields: bool = False, is_export: bool = False):
def import_fyle_dimensions(self, import_taxes: bool = False, import_dependent_fields: bool = False, is_export: bool = False, skip_dependent_field_ids: list = []):
"""Import Fyle Platform dimension."""
apis = ['employees', 'categories', 'projects', 'cost_centers', 'expense_custom_fields', 'corporate_cards']

Expand All @@ -109,6 +109,9 @@ def import_fyle_dimensions(self, import_taxes: bool = False, import_dependent_fi
for api in apis:
dimension = getattr(self, api)
try:
dimension.sync()
if api == 'dependent_fields':
dimension.sync(skip_dependent_field_ids)
else:
dimension.sync()
except Exception as e:
logger.exception(e)
2 changes: 1 addition & 1 deletion connector/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='fyle-integrations-platform-connector',
version='1.39.3',
version='1.40.0',
author='Shwetabh Kumar',
author_email='[email protected]',
description='A common platform connector for all the Fyle Integrations to interact with Fyle Platform APIs',
Expand Down