simplify b2 url
This commit is contained in:
@@ -137,39 +137,11 @@ def get_invoice_links(page: Page) -> list[dict]:
|
||||
entry.update(meta)
|
||||
links.append(entry)
|
||||
|
||||
rows = page.locator("table.billing-table tbody tr, table#billingTable tbody tr, table tbody tr").all()
|
||||
for row in rows:
|
||||
anchors = row.locator("a[href*='billing_invoice'], a[href*='invoice']").all()
|
||||
for anchor in anchors:
|
||||
href = anchor.get_attribute("href") or ""
|
||||
text = anchor.inner_text().strip()
|
||||
if href:
|
||||
if not href.startswith("http"):
|
||||
href = f"{BASE_URL}/{href.lstrip('/')}"
|
||||
_add_link(href, text)
|
||||
|
||||
if not links:
|
||||
all_anchors = page.locator("a[href*='invoice']").all()
|
||||
for anchor in all_anchors:
|
||||
href = anchor.get_attribute("href") or ""
|
||||
text = anchor.inner_text().strip()
|
||||
if href and "invoice" in href.lower():
|
||||
if not href.startswith("http"):
|
||||
href = f"{BASE_URL}/{href.lstrip('/')}"
|
||||
_add_link(href, text)
|
||||
|
||||
print_links = page.locator("a.no-print[data-reference-object-id], a[data-reference-object-id]").all()
|
||||
for anchor in print_links:
|
||||
href = anchor.get_attribute("href") or ""
|
||||
ref_id = anchor.get_attribute("data-reference-object-id") or ""
|
||||
label = anchor.inner_text().strip() or ref_id
|
||||
|
||||
if href:
|
||||
if not href.startswith("http"):
|
||||
href = f"{BASE_URL}/{href.lstrip('/')}"
|
||||
_add_link(href, label)
|
||||
continue
|
||||
|
||||
if ref_id:
|
||||
_add_link(
|
||||
f"{BASE_URL}/billing_print_invoice.htm",
|
||||
@@ -179,7 +151,7 @@ def get_invoice_links(page: Page) -> list[dict]:
|
||||
)
|
||||
continue
|
||||
|
||||
logger.warning("Invoice link missing href and reference id")
|
||||
logger.warning("Invoice link missing reference id")
|
||||
|
||||
return links
|
||||
|
||||
@@ -266,7 +238,9 @@ def export_invoice_pdf(
|
||||
billing_url: str = BILLING_URL,
|
||||
) -> tuple[Page, Path]:
|
||||
invoice_page = None
|
||||
if invoice.get("reference_id"):
|
||||
if not invoice.get("reference_id"):
|
||||
raise RuntimeError("Invoice reference id is required to open the invoice popup")
|
||||
|
||||
page = _goto_with_retry(context, page, billing_url)
|
||||
selector = f"a[data-reference-object-id='{invoice['reference_id']}']"
|
||||
anchor = page.locator(selector).first
|
||||
@@ -282,16 +256,6 @@ def export_invoice_pdf(
|
||||
|
||||
invoice_page.wait_for_load_state("domcontentloaded")
|
||||
invoice_page.wait_for_url("**/billing_print_invoice.htm**", timeout=30000)
|
||||
else:
|
||||
page = _goto_with_retry(context, page, invoice["url"])
|
||||
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)
|
||||
|
||||
@@ -337,6 +301,9 @@ def download_all_invoices() -> list[Path]:
|
||||
billing_pages = ["b2", "groups"]
|
||||
|
||||
for billing_page in billing_pages:
|
||||
if billing_page == "b2":
|
||||
billing_url = f"{BILLING_URL}"
|
||||
else:
|
||||
billing_url = f"{BILLING_URL}?billing_page={billing_page}"
|
||||
page = _goto_with_retry(context, page, billing_url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user