diff --git a/setup.py b/setup.py index 4caa844..b2ec632 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ def get_version(): author='hotglue', url='http://hotglue.xyz/', classifiers=['Programming Language :: Python :: 3 :: Only'], - py_modules=['tap_quickbooks'], + install_requires=[ 'requests>=2.20.0', 'singer-python==5.3.1', @@ -33,7 +33,9 @@ def get_version(): ''', packages=find_packages(exclude=['tests']), package_data={ - 'tap_quickbooks.quickbooks': ['schemas/*.json', 'reportstreams/*'] + 'tap_quickbooks.quickbooks': ['schemas/*.json'], + 'tap_quickbooks.quickbooks.reportstreams': ['*.py'], + 'tap_quickbooks.quickbooks.reportstreams.english_schemas': ['*.py'] }, include_package_data=True, ) diff --git a/tap_quickbooks/quickbooks/reportstreams/BaseReport.py b/tap_quickbooks/quickbooks/reportstreams/BaseReport.py index 2f6e5d0..c96d802 100644 --- a/tap_quickbooks/quickbooks/reportstreams/BaseReport.py +++ b/tap_quickbooks/quickbooks/reportstreams/BaseReport.py @@ -30,12 +30,21 @@ def concurrent_get(self, report_entity, params): else: return response - def _get_column_metadata(self, resp): + def _get_column_metadata(self, resp, schema=None): columns = [] for column in resp.get("Columns").get("Column"): - if column.get("ColTitle") == "Memo/Description": - columns.append("Memo") + # To handle multiple languages if schema is passed, always convert Col Titles to english + if schema is not None: + col_type = column["MetaData"][0].get("Value") if column.get("MetaData") else None + if not col_type: + LOGGER.info(f"Metadata for col {column.get('ColTitle')} not found, skipping.") + continue + # append col to columns + columns.append(schema.get(col_type)) else: - columns.append(column.get("ColTitle").replace(" ", "")) + if column.get("ColTitle") == "Memo/Description": + columns.append("Memo") + else: + columns.append(column.get("ColTitle").replace(" ", "")) columns.append("Categories") return columns diff --git a/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py b/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py index 8ebf921..bc0d02f 100644 --- a/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py +++ b/tap_quickbooks/quickbooks/reportstreams/GeneralLedgerReport.py @@ -9,6 +9,7 @@ import logging import concurrent.futures from calendar import monthrange +from tap_quickbooks.quickbooks.reportstreams.english_schemas.GeneralLedgerReportFields import glr_english_schema as eng_schema LOGGER = singer.get_logger() @@ -20,7 +21,6 @@ class GeneralLedgerReport(BaseReportStream): gl_weekly = False gl_daily = False - def _recursive_row_search(self, row, output, categories): row_group = row.get("Rows") if "ColData" in list(row.keys()): @@ -220,7 +220,7 @@ def sync(self, catalog_entry): self.gl_daily = False # Get column metadata. - columns = self._get_column_metadata(r) + columns = self._get_column_metadata(r, eng_schema) # Recursively get row data. row_group = r.get("Rows") @@ -254,7 +254,7 @@ def sync(self, catalog_entry): resp = self._get(report_entity="GeneralLedger", params=params) # Get column metadata. - columns = self._get_column_metadata(resp) + columns = self._get_column_metadata(resp, eng_schema) # Recursively get row data. row_group = resp.get("Rows") diff --git a/tap_quickbooks/quickbooks/reportstreams/__init__.py b/tap_quickbooks/quickbooks/reportstreams/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tap_quickbooks/quickbooks/reportstreams/english_schemas/GeneralLedgerReportFields.py b/tap_quickbooks/quickbooks/reportstreams/english_schemas/GeneralLedgerReportFields.py new file mode 100644 index 0000000..b940cc3 --- /dev/null +++ b/tap_quickbooks/quickbooks/reportstreams/english_schemas/GeneralLedgerReportFields.py @@ -0,0 +1,41 @@ +glr_english_schema = { + "tx_date": "Date", + "txn_type": "TransactionType", + "doc_num": "Num", + "is_adj": "Adj", + "create_date": "CreateDate", + "create_by": "CreatedBy", + "last_mod_date": "LastModified", + "last_mod_by": "LastModifiedBy", + "name": "Name", + "cust_name": "Customer", + "emp_name": "Employee", + "item_name": "Product/Service", + "memo": "Memo", + "quantity": "Qty", + "rate": "Rate", + "account_name": "Account", + "split_acc": "Split", + "inv_date": "Invoice Date", + "is_ar_paid": "A/RPaid", + "is_ap_paid": "A/PPaid", + "is_cleared": "Clr", + "chk_print_state": "CheckPrinted", + "debt_home_amt": "Debit", + "credit_home_amt": "Credit", + "nat_home_open_bal": "OpenBalance", + "subt_nat_home_amount": "Amount", + "rbal_nat_home_amount": "Balance", + "exch_rate": "ExchangeRate", + "currency": "Currency", + "home_tax_amount": "TaxAmount", + "home_net_amount": "TaxableAmount", + "nat_foreign_open_bal": "ForeignOpenBalance", + "credit_amt": "ForeignCredit", + "nat_foreign_amount": "ForeignAmount", + "vend_name": "Vendor", + "dept_name": "Department", + "klass_name": "Class", + "account_num": "Account#", + "debt_amt": "ForeignDebit" +} \ No newline at end of file diff --git a/tap_quickbooks/quickbooks/reportstreams/english_schemas/__init__.py b/tap_quickbooks/quickbooks/reportstreams/english_schemas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tap_quickbooks/util.py b/tap_quickbooks/util.py index a4a54d6..79c41fd 100644 --- a/tap_quickbooks/util.py +++ b/tap_quickbooks/util.py @@ -14,6 +14,8 @@ _log_thread: Optional[threading.Thread] = None _stop_event = threading.Event() +__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) + def _log_writer(): """Background thread that writes logs to file.""" LOG_FILE_PATH.parent.mkdir(parents=True, exist_ok=True)