From 72e6d1b190998c88978349d7ab70ef5e099b76b3 Mon Sep 17 00:00:00 2001 From: Keyna Rafael <95432445+keyn4@users.noreply.github.com> Date: Tue, 26 Sep 2023 09:37:18 -0500 Subject: [PATCH] fix logic for err msg - fetch based on config firs (#69) --- .../reportstreams/GeneralLedgerReport.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py b/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py index 78dae28..9cd4b3d 100644 --- a/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py +++ b/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py @@ -13,6 +13,8 @@ class GeneralLedgerReport(QuickbooksStream): key_properties: ClassVar[List[str]] = [] replication_method: ClassVar[str] = 'FULL_TABLE' + gl_weekly = False + gl_daily = False def __init__(self, qb, start_date, state_passed): self.qb = qb @@ -142,7 +144,7 @@ def sync(self, catalog_entry): while start_date < today: - if self.qb.gl_daily: + if self.qb.gl_daily or self.gl_daily: if (today - start_date).days <= 1: end_date = today params["end_date"] = today.strftime("%Y-%m-%d") @@ -150,7 +152,7 @@ def sync(self, catalog_entry): end_date = start_date + relativedelta(days=+1) params["end_date"] = (end_date - datetime.timedelta(days=1)).strftime("%Y-%m-%d") - elif self.qb.gl_weekly: + elif self.qb.gl_weekly or self.gl_weekly: if (today - start_date).days <= 7: end_date = today params["end_date"] = today.strftime("%Y-%m-%d") @@ -171,20 +173,19 @@ def sync(self, catalog_entry): LOGGER.info(f"Fetch GeneralLedgerReport for period {params['start_date']} to {params['end_date']}") resp = self._get(report_entity='GeneralLedger', params=params) - rows = resp.get("Rows", {}).get("Row") - rows = rows[-1].get("Rows", {}).get("Row")[-1].get("ColData", []) if rows else None - if rows: - resp_msg = rows[0].get("value") - if resp_msg == "Unable to display more data. Please reduce the date range.": - if not self.qb.gl_weekly and not self.qb.gl_daily: - self.qb.gl_weekly = True + if not self.qb.gl_weekly and not self.qb.gl_daily: + str_resp = str(resp) + if "Unable to display more data. Please reduce the date range." in str_resp: + if not self.gl_weekly and not self.gl_daily: + self.gl_weekly = True continue - elif self.qb.gl_weekly and not self.qb.gl_daily: - self.qb.gl_weekly = False - self.qb.gl_daily = True + elif self.gl_weekly and not self.gl_daily: + self.gl_weekly = False + self.gl_daily = True continue - self.qb.gl_weekly = False - self.qb.gl_daily = False + del str_resp + self.gl_weekly = False + self.gl_daily = False # Get column metadata. columns = self._get_column_metadata(resp)