improve export by waiting for invoice page
This commit is contained in:
@@ -266,27 +266,32 @@ def export_invoice_pdf(
|
|||||||
billing_url: str = BILLING_URL,
|
billing_url: str = BILLING_URL,
|
||||||
) -> tuple[Page, Path]:
|
) -> tuple[Page, Path]:
|
||||||
invoice_page = None
|
invoice_page = None
|
||||||
if invoice.get("open_via_popup") and invoice.get("reference_id"):
|
if invoice.get("reference_id"):
|
||||||
page = _goto_with_retry(context, page, billing_url)
|
page = _goto_with_retry(context, page, billing_url)
|
||||||
selector = f"a[data-reference-object-id='{invoice['reference_id']}']"
|
selector = f"a[data-reference-object-id='{invoice['reference_id']}']"
|
||||||
anchor = page.locator(selector).first
|
anchor = page.locator(selector).first
|
||||||
if anchor.count() == 0:
|
if anchor.count() > 0:
|
||||||
try:
|
|
||||||
with page.expect_popup() as popup_info:
|
|
||||||
page.evaluate("printPayment", invoice["reference_id"])
|
|
||||||
invoice_page = popup_info.value
|
|
||||||
invoice_page.wait_for_load_state("domcontentloaded")
|
|
||||||
except Exception:
|
|
||||||
raise RuntimeError(f"Invoice link not found for reference id {invoice['reference_id']}")
|
|
||||||
else:
|
|
||||||
anchor.scroll_into_view_if_needed()
|
anchor.scroll_into_view_if_needed()
|
||||||
with page.expect_popup() as popup_info:
|
with page.expect_popup() as popup_info:
|
||||||
anchor.click()
|
anchor.click()
|
||||||
invoice_page = popup_info.value
|
invoice_page = popup_info.value
|
||||||
|
else:
|
||||||
|
with page.expect_popup() as popup_info:
|
||||||
|
page.evaluate("printPayment", invoice["reference_id"])
|
||||||
|
invoice_page = popup_info.value
|
||||||
|
|
||||||
invoice_page.wait_for_load_state("domcontentloaded")
|
invoice_page.wait_for_load_state("domcontentloaded")
|
||||||
|
invoice_page.wait_for_url("**/billing_print_invoice.htm**", timeout=30000)
|
||||||
else:
|
else:
|
||||||
page = _goto_with_retry(context, page, invoice["url"])
|
page = _goto_with_retry(context, page, invoice["url"])
|
||||||
invoice_page = page
|
invoice_page = page
|
||||||
|
invoice_page.wait_for_load_state("domcontentloaded")
|
||||||
|
if "billing_print_invoice.htm" not in invoice_page.url:
|
||||||
|
with page.expect_popup() as popup_info:
|
||||||
|
page.evaluate("printPayment", invoice.get("reference_id"))
|
||||||
|
invoice_page = popup_info.value
|
||||||
|
invoice_page.wait_for_load_state("domcontentloaded")
|
||||||
|
invoice_page.wait_for_url("**/billing_print_invoice.htm**", timeout=30000)
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user