Skip to content

Commit

Permalink
feat: allow empty profile to disable einvoice creation
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Jan 24, 2025
1 parent 0fe1b28 commit dfa4a7f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
23 changes: 13 additions & 10 deletions eu_einvoice/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@


def get_custom_fields():
PROFILE_OPTIONS = "\n".join(
[
"",
"BASIC",
"EN 16931",
"EXTENDED",
"XRECHNUNG",
]
)

return {
"Purchase Invoice": [
{
Expand Down Expand Up @@ -52,15 +62,7 @@ def get_custom_fields():
"label": _("E Invoice Profile"),
"insert_after": "e_invoice_validation_section",
"fieldtype": "Select",
"options": "\n".join(
[
"BASIC",
"EN 16931",
"EXTENDED",
"XRECHNUNG",
]
),
"default": "EXTENDED",
"options": PROFILE_OPTIONS,
"print_hide": 1,
},
{
Expand All @@ -70,6 +72,7 @@ def get_custom_fields():
"fieldtype": "Check",
"read_only": 1,
"print_hide": 1,
"depends_on": "eval:!!doc.einvoice_profile",
},
{
"fieldname": "validation_errors",
Expand All @@ -78,7 +81,7 @@ def get_custom_fields():
"fieldtype": "Text",
"read_only": 1,
"print_hide": 1,
"depends_on": "eval:!doc.einvoice_is_correct",
"depends_on": "eval:doc.einvoice_profile && !doc.einvoice_is_correct",
},
],
}
6 changes: 5 additions & 1 deletion eu_einvoice/european_e_invoice/custom/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ frappe.ui.form.on("Sales Invoice", {
refresh: function (frm) {
frm.trigger("add_einvoice_button");

if (!frm.is_dirty() && !frm.doc.einvoice_is_correct) {
if (!frm.is_dirty() && !frm.doc.einvoice_is_correct && frm.doc.einvoice_profile) {
frm.dashboard.set_headline_alert(
__("Please note the validation errors of the e-invoice.")
);
}
},
add_einvoice_button: function (frm) {
if (frm.is_new() || !frm.doc.einvoice_profile) {
return;
}

frm.page.add_menu_item(__("Download eInvoice"), () => {
window.open(
`/api/method/eu_einvoice.european_e_invoice.custom.sales_invoice.download_xrechnung?invoice_id=${encodeURIComponent(
Expand Down
5 changes: 4 additions & 1 deletion eu_einvoice/european_e_invoice/custom/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ def validate_einvoice(doc: SalesInvoice):
doc.einvoice_is_correct = 0
doc.validation_errors = ""

if not doc.einvoice_profile:
return

try:
xml_string = get_einvoice(doc).decode()
except Exception:
Expand Down Expand Up @@ -900,7 +903,7 @@ def attach_xml_to_pdf(invoice_id: str, pdf_data: bytes) -> bytes:
frappe.log_error("Error converting PDF to PDF/A-3 using Ghostscript.")

level = frappe.db.get_value("Sales Invoice", invoice_id, "einvoice_profile")
if level == "XRECHNUNG":
if not level or level == "XRECHNUNG":
# XRECHNUNG does not support embedding into PDF
return pdf_data

Expand Down
2 changes: 1 addition & 1 deletion eu_einvoice/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

[post_model_sync]
# Patches added in this section will be executed after doctypes are migrated
execute:from eu_einvoice.install import after_install; after_install() # 8
execute:from eu_einvoice.install import after_install; after_install() # 10
eu_einvoice.patches.set_profile_in_sales_invoice # 3
eu_einvoice.patches.set_profile_in_import

0 comments on commit dfa4a7f

Please sign in to comment.