Skip to content
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
15 changes: 14 additions & 1 deletion eu_einvoice/european_e_invoice/custom/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(
self.doc = None
self.item_tax_rates = set()
self.delivery_dates = []
self.vat_exemption_reason_text = ""

def get_einvoice(self) -> Document | None:
"""Return the einvoice document as a Python object."""
Expand All @@ -135,6 +136,9 @@ def get_einvoice(self) -> Document | None:
def create_einvoice(self):
"""Create the einvoice document as a Python object."""
self.doc = Document()
self.vat_exemption_reason_text = str(
frappe.db.get_single_value("E Invoice Settings", "vat_exemption_reason_text") or ""
).strip()

self._set_context()
self._set_header()
Expand Down Expand Up @@ -273,7 +277,10 @@ def _set_seller(self):
self._set_seller_address()

def _set_seller_id(self):
for row in self.customer.supplier_numbers:
supplier_numbers = getattr(self.customer, "supplier_numbers", None)
if not supplier_numbers:
return
for row in supplier_numbers:
if row.company == self.invoice.company and row.supplier_number:
self.doc.trade.agreement.seller.id = row.supplier_number
break
Expand Down Expand Up @@ -486,6 +493,7 @@ def _add_line_item(self, item: SalesInvoiceItem):
("Sales Taxes and Charges Template", self.invoice.taxes_and_charges),
]
).upper()
self._set_optional_vat_exemption_reason_text(li.settlement.trade_tax)

li.settlement.monetary_summation.total_amount = flt(item.net_amount, item.precision("net_amount"))
self.doc.trade.items.add(li)
Expand Down Expand Up @@ -614,8 +622,13 @@ def _add_empty_tax(self):
("Sales Taxes and Charges Template", self.invoice.taxes_and_charges),
]
).upper()
self._set_optional_vat_exemption_reason_text(trade_tax)
self.doc.trade.settlement.trade_tax.add(trade_tax)

def _set_optional_vat_exemption_reason_text(self, trade_tax: ApplicableTradeTax) -> None:
if self.vat_exemption_reason_text:
trade_tax.exemption_reason = self.vat_exemption_reason_text

def _add_delivery_date(self):
if self.delivery_dates:
delivery_date = sorted(self.delivery_dates)[-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2024, ALYF GmbH and contributors
# For license information, please see license.txt

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -279,6 +280,8 @@ def parse_tax(self, tax: ApplicableTradeTax):
t.basis_amount = flt_or_none(tax.basis_amount._value)
t.rate_applicable_percent = flt_or_none(tax.rate_applicable_percent._value)
t.calculated_amount = flt_or_none(tax.calculated_amount._value)
reason_text = tax.exemption_reason._text
t.vat_exemption_reason_text = str(reason_text).strip() if reason_text else None

def parse_payment_term(self, term: PaymentTerms):
if not term.partial_amount.children:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"error_action_on_save",
"error_action_on_submit",
"sales_invoice_number_field",
"section_break_bt120",
"vat_exemption_reason_text",
"section_break_yldr",
"auto_attach_xml",
"attach_field_for_xml_file"
Expand Down Expand Up @@ -74,13 +76,24 @@
"fieldname": "sales_invoice_number_field",
"fieldtype": "Autocomplete",
"label": "Sales Invoice Number Field"
},
{
"fieldname": "section_break_bt120",
"fieldtype": "Section Break",
"label": "VAT exemption (e-invoice)"
},
{
"description": "If set, written to BT-120 (<code>ram:ExemptionReason</code>) on VAT breakdowns where an exemption reason code is emitted. Left unset in the XML when empty.",
"fieldname": "vat_exemption_reason_text",
"fieldtype": "Small Text",
"label": "Default VAT exemption reason"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2026-02-06 17:52:09.990716",
"modified": "2026-04-21 12:00:00.000000",
"modified_by": "Administrator",
"module": "European e-Invoice",
"name": "E Invoice Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EInvoiceSettings(Document):
sales_invoice_number_field: DF.Autocomplete | None
validate_sales_invoice_on_save: DF.Check
validate_sales_invoice_on_submit: DF.Check
vat_exemption_reason_text: DF.SmallText | None
# end: auto-generated types

def before_validate(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"basis_amount",
"rate_applicable_percent",
"calculated_amount",
"vat_exemption_reason_text",
"tax_account"
],
"fields": [
Expand All @@ -35,6 +36,12 @@
"options": "currency",
"read_only": 1
},
{
"fieldname": "vat_exemption_reason_text",
"fieldtype": "Small Text",
"label": "VAT exemption reason",
"read_only": 1
},
{
"fieldname": "tax_account",
"fieldtype": "Link",
Expand All @@ -45,7 +52,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-09-26 21:18:13.837830",
"modified": "2026-04-21 14:00:00.000000",
"modified_by": "Administrator",
"module": "European e-Invoice",
"name": "E Invoice Trade Tax",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EInvoiceTradeTax(Document):
parenttype: DF.Data
rate_applicable_percent: DF.Percent
tax_account: DF.Link | None
vat_exemption_reason_text: DF.SmallText | None
# end: auto-generated types

pass
Loading
Loading