Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Sales Invoice): allow empty profile, fetch default from Customer master (backport #76) #78

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 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 All @@ -20,6 +30,14 @@ def get_custom_fields():
"insert_after": "language",
"fieldtype": "Data",
},
{
"fieldname": "einvoice_profile",
"label": _("E Invoice Profile"),
"insert_after": "buyer_reference",
"fieldtype": "Select",
"options": PROFILE_OPTIONS,
"default": "EXTENDED",
},
],
"Sales Order": [
{
Expand Down Expand Up @@ -52,15 +70,9 @@ 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,
"fetch_from": "customer.einvoice_profile",
"fetch_if_empty": 1,
"print_hide": 1,
},
{
Expand All @@ -70,6 +82,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 +91,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
Loading