diff --git a/README.md b/README.md index 4f34c05..363abc0 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,6 @@ 3. Create and checkout a new branch feature/student1FirstName_student2FirstName 4. Install dependencies: poetry install 5. Implemented two functions in terms.py. -6. Install the pre-commit hook: poetry run pre-commit install +6. Install the pre-commit hook: poetry run pre-commit install 7. Commit your code (passing pre-commit hook) and push the code. 8. Create a pull request to merge your feature branch into the upstream repo's main branch. diff --git a/response.xml b/response.xml index 3958409..c3ffaae 100644 --- a/response.xml +++ b/response.xml @@ -1,12 +1,12 @@ - + -80000001-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000001-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T17:54:23+00:00 +1758131663 1% 10 Net 30 true 30 @@ -14,10 +14,10 @@ 1.00 -80000002-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000002-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T17:54:23+00:00 +1758131663 2% 10 Net 30 true 30 @@ -25,10 +25,10 @@ 2.00 -80000003-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000003-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T17:54:23+00:00 +1758131663 Consignment true 90 @@ -36,10 +36,10 @@ 0.00 -80000004-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000004-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T17:54:23+00:00 +1758131663 Due on receipt true 0 @@ -47,21 +47,21 @@ 0.00 -80000005-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000005-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T18:01:45+00:00 +1758132105 Net 15 true 15 -0 +25 0.00 -80000006-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000006-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T17:54:23+00:00 +1758131663 Net 30 true 30 @@ -69,10 +69,10 @@ 0.00 -80000007-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000007-1758131663 +2025-09-17T17:54:23+00:00 +2025-09-17T17:54:23+00:00 +1758131663 Net 60 true 60 diff --git a/terms.py b/terms.py index 574a9d6..330eae4 100644 --- a/terms.py +++ b/terms.py @@ -2,7 +2,10 @@ import xml.etree.ElementTree as ET try: - from win32com.client import Dispatch, constants # poetry install pywin32 (32-bit) + from win32com.client import ( + Dispatch, + constants, + ) # Requires 32-bit Python for QB Desktop except ImportError: print("Please 'poetry add pywin32' (use 32-bit Python for QB Desktop).") sys.exit(1) @@ -10,12 +13,51 @@ def build_terms_query() -> str: """Return a minimal TermsQueryRq XML.""" - raise NotImplementedError() + qbxml = """ + + + + + All + + +""" + return qbxml def parse_and_print(response_xml: str) -> None: - """Parse response and print term name + discount days.""" - raise NotImplementedError() + """Parse response and print term name + discount information.""" + try: + root = ET.fromstring(response_xml) + except ET.ParseError as e: + print(f"Error parsing response XML: {e}") + return + + # Handle both StandardTermsRet and DateDrivenTermsRet + standard_terms = root.findall(".//StandardTermsRet") + date_driven_terms = root.findall(".//DateDrivenTermsRet") + + if not (standard_terms or date_driven_terms): + print("No terms found in response.") + return + + # Standard terms + for term in standard_terms: + name = term.findtext("Name", default="(unknown)") + discount_days = term.findtext("StdDiscountDays", default="N/A") + discount_pct = term.findtext("DiscountPct", default="N/A") + print( + f"[Standard] Term: {name}, Discount Days: {discount_days}, Discount %: {discount_pct}" + ) + + # Date-driven terms + for term in date_driven_terms: + name = term.findtext("Name", default="(unknown)") + discount_day = term.findtext("DiscountDayOfMonth", default="N/A") + discount_pct = term.findtext("DiscountPct", default="N/A") + print( + f"[DateDriven] Term: {name}, Discount Day: {discount_day}, Discount %: {discount_pct}" + ) def main(): @@ -32,8 +74,11 @@ def main(): request_xml = build_terms_query() response_xml = rp.ProcessRequest(ticket, request_xml) - with open("response.xml", "w") as file: + + # Save to file for debugging + with open("response.xml", "w", encoding="utf-8") as file: file.write(response_xml) + parse_and_print(response_xml) finally: