49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""
|
|
Builds URLs for the two "jump out to somewhere else" actions: viewing a
|
|
ticket directly in JIRA, and looking up a shipping address on Google
|
|
Maps (matching the existing manual workflow of pasting an address into
|
|
Google when investigating a validation issue).
|
|
|
|
Deliberately just URL-building, no browser-launching here - that stays
|
|
in the UI layer (main_window.py / order_detail_dialog.py) via
|
|
webbrowser.open(), so this module has no GUI dependency and is easy to
|
|
test in isolation.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from urllib.parse import quote
|
|
|
|
from app import config
|
|
|
|
|
|
def jira_ticket_url(ticket_number: str | None) -> str | None:
|
|
if not ticket_number:
|
|
return None
|
|
jira_url = config.get("JIRA_URL", "").strip()
|
|
if not jira_url:
|
|
return None
|
|
base = jira_url.rstrip("/")
|
|
# JIRA_URL is meant to be the bare site domain - app/services/jira_service.py
|
|
# appends /rest/api/... itself for API calls, so that suffix should never
|
|
# be part of the setting value. Strip it defensively anyway, so a link
|
|
# here is always a normal web page rather than an API endpoint even if
|
|
# the setting was ever saved with that path already attached.
|
|
if "/rest/" in base:
|
|
base = base.split("/rest/")[0]
|
|
return f"{base}/browse/{ticket_number}"
|
|
|
|
|
|
def google_maps_search_url(shipping_info: dict | None) -> str | None:
|
|
info = shipping_info or {}
|
|
parts = [
|
|
info.get("address1", ""),
|
|
info.get("address2", ""),
|
|
info.get("city", ""),
|
|
info.get("state", ""),
|
|
info.get("zip", ""),
|
|
]
|
|
address = " ".join(p for p in parts if p).strip()
|
|
if not address:
|
|
return None
|
|
return f"https://www.google.com/maps/search/?api=1&query={quote(address)}"
|