From e40098d9cfaf8b6402ca3d64e92f800d66fc43b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20M=2E=20Sehnem?= Date: Tue, 27 Sep 2022 12:02:42 -0400 Subject: [PATCH 1/2] iterate P&L report --- .../ProfitAndLossDetailReport.py | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/tap_quickbooks/quickbooks/reportstreams/ProfitAndLossDetailReport.py b/tap_quickbooks/quickbooks/reportstreams/ProfitAndLossDetailReport.py index 2d50282..ff0683d 100644 --- a/tap_quickbooks/quickbooks/reportstreams/ProfitAndLossDetailReport.py +++ b/tap_quickbooks/quickbooks/reportstreams/ProfitAndLossDetailReport.py @@ -56,52 +56,57 @@ def sync(self, catalog_entry): full_sync = not self.state_passed if full_sync: - LOGGER.info(f"Starting full sync of P&L") - end_date = datetime.date.today() - start_date = self.start_date - params = { - "start_date": start_date.strftime("%Y-%m-%d"), - "end_date": end_date.strftime("%Y-%m-%d"), - "accounting_method": "Accrual" - } - - LOGGER.info(f"Fetch Journal Report for period {params['start_date']} to {params['end_date']}") - resp = self._get(report_entity='ProfitAndLossDetail', params=params) - - # Get column metadata. - columns = self._get_column_metadata(resp) + start_date = self.start_date.date() + delta = 364 + while start_datedatetime.date.today(): + end_date = datetime.date.today() + params = { + "start_date": start_date.strftime("%Y-%m-%d"), + "end_date": end_date.strftime("%Y-%m-%d"), + "accounting_method": "Accrual" + } - # Recursively get row data. - row_group = resp.get("Rows") - row_array = row_group.get("Row") + LOGGER.info(f"Fetch Journal Report for period {params['start_date']} to {params['end_date']}") + resp = self._get(report_entity='ProfitAndLossDetail', params=params) + start_date = end_date + datetime.timedelta(1) - if row_array is None: - return + # Get column metadata. + columns = self._get_column_metadata(resp) - output = [] - categories = [] - for row in row_array: - self._recursive_row_search(row, output, categories) + # Recursively get row data. + row_group = resp.get("Rows") + row_array = row_group.get("Row") - # Zip columns and row data. - for raw_row in output: - row = dict(zip(columns, raw_row)) - if not row.get("Amount"): - # If a row is missing the amount, skip it + if row_array is None: continue - cleansed_row = {} - for k, v in row.items(): - if v == "": + output = [] + categories = [] + for row in row_array: + self._recursive_row_search(row, output, categories) + + # Zip columns and row data. + for raw_row in output: + row = dict(zip(columns, raw_row)) + if not row.get("Amount"): + # If a row is missing the amount, skip it continue - else: - cleansed_row.update({k: v}) - cleansed_row["Amount"] = float(row.get("Amount")) - cleansed_row["Balance"] = float(row.get("Balance")) - cleansed_row["SyncTimestampUtc"] = singer.utils.strftime(singer.utils.now(), "%Y-%m-%dT%H:%M:%SZ") + cleansed_row = {} + for k, v in row.items(): + if v == "": + continue + else: + cleansed_row.update({k: v}) + + cleansed_row["Amount"] = float(row.get("Amount")) + cleansed_row["Balance"] = float(row.get("Balance")) + cleansed_row["SyncTimestampUtc"] = singer.utils.strftime(singer.utils.now(), "%Y-%m-%dT%H:%M:%SZ") - yield cleansed_row + yield cleansed_row else: LOGGER.info(f"Syncing P&L of last {NUMBER_OF_PERIODS} periods") end_date = datetime.date.today() From 90c43ea3589a35ab38a705ac50506b2d7d5a10fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20M=2E=20Sehnem?= Date: Tue, 27 Sep 2022 12:06:15 -0400 Subject: [PATCH 2/2] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5874b0a..a5a0f5a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def get_version(): readme = f.read() setup(name='tap-quickbooks', - version='1.4.44', + version='1.4.45', description='Singer.io tap for extracting data from the Quickbooks API', author='hotglue', url='http://hotglue.xyz/',