simplify b2 url
This commit is contained in:
@@ -137,39 +137,11 @@ def get_invoice_links(page: Page) -> list[dict]:
|
|||||||
entry.update(meta)
|
entry.update(meta)
|
||||||
links.append(entry)
|
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()
|
print_links = page.locator("a.no-print[data-reference-object-id], a[data-reference-object-id]").all()
|
||||||
for anchor in print_links:
|
for anchor in print_links:
|
||||||
href = anchor.get_attribute("href") or ""
|
|
||||||
ref_id = anchor.get_attribute("data-reference-object-id") or ""
|
ref_id = anchor.get_attribute("data-reference-object-id") or ""
|
||||||
label = anchor.inner_text().strip() or ref_id
|
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:
|
if ref_id:
|
||||||
_add_link(
|
_add_link(
|
||||||
f"{BASE_URL}/billing_print_invoice.htm",
|
f"{BASE_URL}/billing_print_invoice.htm",
|
||||||
@@ -179,7 +151,7 @@ def get_invoice_links(page: Page) -> list[dict]:
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.warning("Invoice link missing href and reference id")
|
logger.warning("Invoice link missing reference id")
|
||||||
|
|
||||||
return links
|
return links
|
||||||
|
|
||||||
@@ -266,32 +238,24 @@ 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("reference_id"):
|
if not invoice.get("reference_id"):
|
||||||
page = _goto_with_retry(context, page, billing_url)
|
raise RuntimeError("Invoice reference id is required to open the invoice popup")
|
||||||
selector = f"a[data-reference-object-id='{invoice['reference_id']}']"
|
|
||||||
anchor = page.locator(selector).first
|
|
||||||
if anchor.count() > 0:
|
|
||||||
anchor.scroll_into_view_if_needed()
|
|
||||||
with page.expect_popup() as popup_info:
|
|
||||||
anchor.click()
|
|
||||||
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")
|
page = _goto_with_retry(context, page, billing_url)
|
||||||
invoice_page.wait_for_url("**/billing_print_invoice.htm**", timeout=30000)
|
selector = f"a[data-reference-object-id='{invoice['reference_id']}']"
|
||||||
|
anchor = page.locator(selector).first
|
||||||
|
if anchor.count() > 0:
|
||||||
|
anchor.scroll_into_view_if_needed()
|
||||||
|
with page.expect_popup() as popup_info:
|
||||||
|
anchor.click()
|
||||||
|
invoice_page = popup_info.value
|
||||||
else:
|
else:
|
||||||
page = _goto_with_retry(context, page, invoice["url"])
|
with page.expect_popup() as popup_info:
|
||||||
invoice_page = page
|
page.evaluate("printPayment", invoice["reference_id"])
|
||||||
invoice_page.wait_for_load_state("domcontentloaded")
|
invoice_page = popup_info.value
|
||||||
if "billing_print_invoice.htm" not in invoice_page.url:
|
|
||||||
with page.expect_popup() as popup_info:
|
invoice_page.wait_for_load_state("domcontentloaded")
|
||||||
page.evaluate("printPayment", invoice.get("reference_id"))
|
invoice_page.wait_for_url("**/billing_print_invoice.htm**", timeout=30000)
|
||||||
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)
|
||||||
|
|
||||||
@@ -337,7 +301,10 @@ def download_all_invoices() -> list[Path]:
|
|||||||
billing_pages = ["b2", "groups"]
|
billing_pages = ["b2", "groups"]
|
||||||
|
|
||||||
for billing_page in billing_pages:
|
for billing_page in billing_pages:
|
||||||
billing_url = f"{BILLING_URL}?billing_page={billing_page}"
|
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)
|
page = _goto_with_retry(context, page, billing_url)
|
||||||
|
|
||||||
page, groups = get_group_options(context, page, billing_url=billing_url)
|
page, groups = get_group_options(context, page, billing_url=billing_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user