From 5d8f06d0a1962620607c5dcf4e0cb67fc8d86d0f Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Tue, 16 Jul 2024 18:54:13 +0530 Subject: [PATCH] Add support for deleting merchants (#87) --- .../apis/merchants.py | 26 ++++++++++--------- connector/setup.py | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/connector/fyle_integrations_platform_connector/apis/merchants.py b/connector/fyle_integrations_platform_connector/apis/merchants.py index abf8f90..5d839a5 100644 --- a/connector/fyle_integrations_platform_connector/apis/merchants.py +++ b/connector/fyle_integrations_platform_connector/apis/merchants.py @@ -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 @@ -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'], @@ -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 = [] diff --git a/connector/setup.py b/connector/setup.py index f0a5628..4bb83c6 100644 --- a/connector/setup.py +++ b/connector/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='fyle-integrations-platform-connector', - version='1.38.4', + version='1.39.0', author='Shwetabh Kumar', author_email='shwetabh.kumar@fyle.in', description='A common platform connector for all the Fyle Integrations to interact with Fyle Platform APIs',