TDL-13967: Add ProfitAndLoss report stream#37
Conversation
8f786ff to
b7b19cd
Compare
| params["end_date"] = end_tm_str | ||
|
|
||
| resp = self.client.get(self.endpoint, params=params) | ||
| self.parse_report_metadata(resp) |
There was a problem hiding this comment.
I think having parse_report_metadata() be recursive is excessive. The response object here is just three keys, Header (which we ignore), Rows, and Columns.
Parsing resp['Columns'] seems like a loop over resp['Columns']['Column'] and filtering the 'Metadata'.
Parsing resp['Rows'] is the only recursive part, so we can repurpose most of the logic in parse_report_metadata() into parse_rows() or something
There was a problem hiding this comment.
Split down parse_report_metadata() into two functions parse_report_columns() and parse_report_rows().
parse_report_columns() will parse resp['Columns'] with a loop over resp['Columns']['Column'] and filters Metadata.
parse_report_rows() is the recursive one which will parse resp['Rows'].
| 'data': [] | ||
| } | ||
|
|
||
| start_tm_str = strftime(start_dttm)[0:10] |
There was a problem hiding this comment.
Use str(start_dttm.date()) to get date
There was a problem hiding this comment.
Updated date retrieval as per suggestion.
| columns = pileOfColumns.get('Column', []) | ||
| for column in columns: | ||
| metadatas = column.get('MetaData', []) | ||
| for md in metadatas: |
There was a problem hiding this comment.
I prefer instead of using md have more descriptive variable name like metadata
There was a problem hiding this comment.
Updated md with proper variable name metadata
| ''' | ||
|
|
||
| if isinstance(pileOfRows, list): | ||
| for x in pileOfRows: |
There was a problem hiding this comment.
Stop using variable names like x. Please provide more descriptive
There was a problem hiding this comment.
Updated x with descriptive name row
| self.parse_report_rows(pileOfRows['Summary']) | ||
|
|
||
| if 'ColData' in pileOfRows.keys(): | ||
| d = dict() |
There was a problem hiding this comment.
Stop using variable names like d. Provide more descriptive variable name. Bad coding practice
There was a problem hiding this comment.
I will keep in mind using descriptive variable names and updated above d with a proper name.
| for x in pileOfRows['ColData'][1:]: | ||
| vals.append(x['value']) | ||
| d['values'] = vals | ||
| self.parsed_metadata['data'].append(d) |
There was a problem hiding this comment.
No x, d variable names. Provide descriptive names
There was a problem hiding this comment.
Updated x,d types of variables with proper descriptive names.
| reports = self.day_wise_reports() | ||
| if reports: | ||
| for report in reports: | ||
| yield report |
There was a problem hiding this comment.
What is the difference between yield report and yield from report? I've seen in many places using yield from report
There was a problem hiding this comment.
-
yield from reportsandyieldinside for loops, both return generators with every element ofreports. -
The python generator will flush out after iteration over it and here,
reportsis a generator, and tap use last report fromreportsfor storing bookmark. -
If we use
yield from reportsthen no way to retrieve the last report after it so we usedyield with for loophere to utilize the loop's local variablereportto retrieve the last report.
tap-quickbooks/tap_quickbooks/streams.py
Line 260 in b6e8e4a
| table_name = 'Vendor' | ||
| additional_where = "Active IN (true, false)" | ||
|
|
||
| class ReportStream(Stream): |
There was a problem hiding this comment.
Please add more comments to the code to explain at each section what is being done
There was a problem hiding this comment.
Added more comments to the code for better code explanation.
| if 'Rows' in pileOfRows.keys(): | ||
| self.parse_report_rows(pileOfRows['Rows']) | ||
|
|
||
| if 'Row' in pileOfRows.keys(): | ||
| self.parse_report_rows(pileOfRows['Row']) |
There was a problem hiding this comment.
What is the difference between Rows and Row here?
There was a problem hiding this comment.
Rows is top-level information about profit and loss reports while Row is information about entries of reports. Documentation of the profit and loss report's metadata: documentation.
|
|
||
| return record_counts | ||
|
|
||
| def dt_to_ts(self, dtime): |
There was a problem hiding this comment.
Raising an exception after this for loop would prevent the test from getting back a None and failing in a confusing way in the case where the datetime format is unaccounted for.
Description of change
TDL-13967: Add ProfitAndLoss report stream
Finalized approach:
Manual QA steps
Risks
Rollback steps