Skip to content

Commit

Permalink
Add support for deleting merchants (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrishabh17 authored Jul 16, 2024
1 parent df79cbc commit 5d8f06d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions connector/fyle_integrations_platform_connector/apis/merchants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from apps.workspaces.models import Workspace
from .base import Base
from typing import List
from fyle_accounting_mappings.models import ExpenseAttribute


class Merchants(Base):
"""
Class for Merchants API
Expand All @@ -14,21 +14,24 @@ def get(self):
generator = self.get_all_generator()
for items in generator:
merchants = items['data'][0]

return merchants

def post(self, payload: List[str], skip_existing_merchants: bool = False):
def post(self, payload: List[str], skip_existing_merchants: bool = False, delete_merchants: bool = False):
"""
Post data to Fyle
Post data to Fyle
"""
generator = self.get_all_generator()
for items in generator:
merchants = items['data'][0]
if skip_existing_merchants:
merchants['options'] = payload
if delete_merchants:
merchants['options'] = list(set(merchants['options']) - set(payload))
else:
merchants['options'].extend(payload)
merchants['options'] = list(set(merchants['options']))
if skip_existing_merchants:
merchants['options'] = payload
else:
merchants['options'].extend(payload)
merchants['options'] = list(set(merchants['options']))
merchant_payload = {
'id': merchants['id'],
'field_name': merchants['field_name'],
Expand All @@ -45,23 +48,22 @@ def post(self, payload: List[str], skip_existing_merchants: bool = False):

return self.connection.post({'data': merchant_payload})


def sync(self):
"""
Syncs the latest API data to DB.
"""
generator = self.get_all_generator()
for items in generator:
merchants=items['data'][0]
merchants = items['data'][0]
existing_merchants = ExpenseAttribute.objects.filter(
attribute_type='MERCHANT', workspace_id=self.workspace_id)
delete_merchant_ids = []

if(existing_merchants):
if (existing_merchants):
for existing_merchant in existing_merchants:
if existing_merchant.value not in merchants['options']:
delete_merchant_ids.append(existing_merchant.id)

ExpenseAttribute.objects.filter(id__in=delete_merchant_ids).delete()

merchant_attributes = []
Expand Down
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.38.4',
version='1.39.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

0 comments on commit 5d8f06d

Please sign in to comment.