From 602f644f2a350b924fcb79f73fe0324c0fa289bd Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:57:29 +0530 Subject: [PATCH] Added method for fetching inactive records (#24) * Added generator for the get calls * fixed the loop terminate * Added method for fetching inactive records * Modified the last_updated_at arg to optional --- qbosdk/apis/accounts.py | 15 +++++++++++++++ qbosdk/apis/customers.py | 15 +++++++++++++++ qbosdk/apis/items.py | 15 +++++++++++++++ qbosdk/apis/vendors.py | 15 +++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/qbosdk/apis/accounts.py b/qbosdk/apis/accounts.py index 578a74f..5c80814 100644 --- a/qbosdk/apis/accounts.py +++ b/qbosdk/apis/accounts.py @@ -24,3 +24,18 @@ def get_all_generator(self): Generator with dicts in Accounts schema. """ return self._query_get_all_generator('Account', Accounts.GET_ACCOUNTS) + + def get_inactive(self, last_updated_time: None): + """ + Retrieves a list of inactive accounts from the QuickBooks Online API. + + :param last_updated_time: The last updated time to filter the accounts. + :return: A list of inactive accounts. + """ + + QUERY = "/query?query=select * from Account where Active=false" + if last_updated_time: + QUERY += f" and Metadata.LastUpdatedTime >= '{last_updated_time}'" + QUERY += " STARTPOSITION {0} MAXRESULTS 1000" + + return self._query_get_all_generator('Account', QUERY) diff --git a/qbosdk/apis/customers.py b/qbosdk/apis/customers.py index 5ffc0b2..5e6d69c 100644 --- a/qbosdk/apis/customers.py +++ b/qbosdk/apis/customers.py @@ -33,3 +33,18 @@ def count(self): Count in Int. """ return self._query(Customers.COUNT_CUSTOMERS)['totalCount'] + + def get_inactive(self, last_updated_time: None): + """ + Retrieves a list of inactive customers from the QuickBooks Online API. + + :param last_updated_time: The last updated time to filter the customers. + :return: A list of inactive customers. + """ + + QUERY = "/query?query=select * from Customer where Active=false" + if last_updated_time: + QUERY += f" and Metadata.LastUpdatedTime >= '{last_updated_time}'" + QUERY += " STARTPOSITION {0} MAXRESULTS 1000" + + return self._query_get_all_generator('Customer', QUERY) diff --git a/qbosdk/apis/items.py b/qbosdk/apis/items.py index 8499c9c..01adc6b 100644 --- a/qbosdk/apis/items.py +++ b/qbosdk/apis/items.py @@ -25,3 +25,18 @@ def get_all_generator(self): Generator with dicts in Items schema. """ return self._query_get_all_generator('Item', Items.GET_ITEMS) + + def get_inactive(self, last_updated_time: None): + """ + Retrieves a list of inactive items from the QuickBooks Online API. + + :param last_updated_time: The last updated time to filter the items. + :return: A list of inactive items. + """ + + QUERY = "/query?query=select * from Item where Active=false" + if last_updated_time: + QUERY += f" and Metadata.LastUpdatedTime >= '{last_updated_time}'" + QUERY += " STARTPOSITION {0} MAXRESULTS 1000" + + return self._query_get_all_generator('Item', QUERY) diff --git a/qbosdk/apis/vendors.py b/qbosdk/apis/vendors.py index cc064fd..04ced97 100644 --- a/qbosdk/apis/vendors.py +++ b/qbosdk/apis/vendors.py @@ -46,3 +46,18 @@ def search_vendor_by_display_name(self, display_name=None): response = self._get_request('QueryResponse', Vendors.SEARCH_VENDOR.format(display_name)) return response['Vendor'][0] if 'Vendor' in response else None + + def get_inactive(self, last_updated_time: None): + """ + Retrieves a list of inactive vendors from the QuickBooks Online API. + + :param last_updated_time: The last updated time to filter the vendors. + :return: A list of inactive vendors. + """ + + QUERY = "/query?query=select * from Vendor where Active=false" + if last_updated_time: + QUERY += f" and Metadata.LastUpdatedTime >= '{last_updated_time}'" + QUERY += " STARTPOSITION {0} MAXRESULTS 1000" + + return self._query_get_all_generator('Vendor', QUERY)