Download the full order CSV instead of re-running the report

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-22 08:34:27 +03:30
parent 2bf8c046c6
commit 0fa05ab48d
2 changed files with 15 additions and 34 deletions

View File

@@ -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]:
"""Prefer the filtered export. A failed post still returns the full CSV."""
if getattr(client, "session", None) is None:
return client.fetch_customer_orders()
# The report GET redirects to login until the client has signed in.
if hasattr(client, "login") and not getattr(client, "_logged_in", False):
client.login()
try:
return export_filtered_customer_orders(client, day, prefixes)
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()
"""Download the full CSV and let the local date and prefix checks drop rows.
A server-side filter re-runs the report after the page has already loaded
(~1.8s) to avoid downloading about 20KB. Direct export is faster.
ponytail: pass filter_state=report_filter_state(day, prefixes) if this
export starts taking more than a couple of seconds.
"""
return client.fetch_customer_orders()
def recent_customer_orders(username: str, password: str, client=None) -> dict: