Skip to content

Commit

Permalink
feat: override download_pdf to attach XML
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Nov 18, 2024
1 parent e6fd1a2 commit 5201c0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 14 additions & 0 deletions eu_einvoice/european_e_invoice/custom/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,17 @@ def get_item_rate(item_tax_template: str | None, taxes: list[dict]) -> float | N
return tax_rates[0]

return None


@frappe.whitelist(allow_guest=True)
def download_pdf(
doctype: str, name: str, format=None, doc=None, no_letterhead=0, language=None, letterhead=None
):
from facturx import generate_from_binary
from frappe.utils.print_format import download_pdf as frappe_download_pdf

frappe_download_pdf(doctype, name, format, doc, no_letterhead, language, letterhead)

if doctype == "Sales Invoice":
xml_bytes = get_einvoice(name)
frappe.local.response.filecontent = generate_from_binary(frappe.local.response.filecontent, xml_bytes)
9 changes: 4 additions & 5 deletions eu_einvoice/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@

# Overriding Methods
# ------------------------------
#
# override_whitelisted_methods = {
# "frappe.desk.doctype.event.event.get_events": "eu_einvoice.event.get_events"
# }
#
override_whitelisted_methods = {
"frappe.utils.print_format.download_pdf": "eu_einvoice.european_e_invoice.custom.sales_invoice.download_pdf",
}

# each overriding function accepts a `data` argument;
# generated from the base implementation of the doctype dashboard,
# along with any modifications made in other Frappe apps
Expand Down

0 comments on commit 5201c0c

Please sign in to comment.