Download the full order CSV instead of re-running the report
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -253,19 +253,14 @@ def export_filtered_customer_orders(client, day: date, prefixes: list[str]) -> t
|
|||||||
|
|
||||||
|
|
||||||
def _load_order_export(client, day: date, prefixes: list[str]) -> tuple[str, str]:
|
def _load_order_export(client, day: date, prefixes: list[str]) -> tuple[str, str]:
|
||||||
"""Prefer the filtered export. A failed post still returns the full CSV."""
|
"""Download the full CSV and let the local date and prefix checks drop rows.
|
||||||
if getattr(client, "session", None) is None:
|
|
||||||
return client.fetch_customer_orders()
|
A server-side filter re-runs the report after the page has already loaded
|
||||||
# The report GET redirects to login until the client has signed in.
|
(~1.8s) to avoid downloading about 20KB. Direct export is faster.
|
||||||
if hasattr(client, "login") and not getattr(client, "_logged_in", False):
|
ponytail: pass filter_state=report_filter_state(day, prefixes) if this
|
||||||
client.login()
|
export starts taking more than a couple of seconds.
|
||||||
try:
|
"""
|
||||||
return export_filtered_customer_orders(client, day, prefixes)
|
return client.fetch_customer_orders()
|
||||||
except Exception as exc:
|
|
||||||
if login_rejected(str(exc)):
|
|
||||||
raise
|
|
||||||
# A broken filter post must not blank the page. The full CSV still filters locally.
|
|
||||||
return client.fetch_customer_orders()
|
|
||||||
|
|
||||||
|
|
||||||
def recent_customer_orders(username: str, password: str, client=None) -> dict:
|
def recent_customer_orders(username: str, password: str, client=None) -> dict:
|
||||||
|
|||||||
@@ -156,31 +156,17 @@ class SystemGroupLoginTests(unittest.TestCase):
|
|||||||
self.assertEqual(posted["filterItemName"], "pp.code")
|
self.assertEqual(posted["filterItemName"], "pp.code")
|
||||||
self.assertEqual(posted["operands"][0]["value"], "KR")
|
self.assertEqual(posted["operands"][0]["value"], "KR")
|
||||||
|
|
||||||
def test_filtered_export_logs_in_first(self):
|
def test_load_uses_direct_export(self):
|
||||||
calls = []
|
seen = {}
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self):
|
def fetch_customer_orders(self, **kwargs):
|
||||||
self.session = object()
|
seen.update(kwargs)
|
||||||
self._logged_in = False
|
|
||||||
|
|
||||||
def login(self):
|
|
||||||
calls.append("login")
|
|
||||||
self._logged_in = True
|
|
||||||
|
|
||||||
def fetch_customer_orders(self):
|
|
||||||
calls.append("full")
|
|
||||||
return "full", "text/csv"
|
return "full", "text/csv"
|
||||||
|
|
||||||
client = Client()
|
body, ctype = _load_order_export(Client(), date(2026, 3, 21), ["KR"])
|
||||||
with patch(
|
self.assertEqual((body, ctype), ("full", "text/csv"))
|
||||||
"slips.crm_orders.export_filtered_customer_orders",
|
self.assertNotIn("filter_state", seen)
|
||||||
return_value=("filtered", "text/csv"),
|
|
||||||
) as filtered:
|
|
||||||
body, ctype = _load_order_export(client, date(2026, 3, 21), ["KR"])
|
|
||||||
self.assertEqual(calls, ["login"])
|
|
||||||
self.assertEqual((body, ctype), ("filtered", "text/csv"))
|
|
||||||
filtered.assert_called_once()
|
|
||||||
|
|
||||||
|
|
||||||
class CrmSessionTests(TestCase):
|
class CrmSessionTests(TestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user