Skip to content

Commit

Permalink
[IMP] datev_export_xml: Check invoices before rendering to prevent ba…
Browse files Browse the repository at this point in the history
…dly described exceptions
  • Loading branch information
fkantelberg committed Jul 11, 2023
1 parent 18e280e commit a5a3c11
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions datev_export_xml/models/datev_xml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,26 @@ def check_xml_file(self, doc_name, root, xsd=None):
) from e
return True

@api.model
def _check_invoices(self, invoices):
# Check against double taxes
problems = invoices.browse()
for invoice in invoices:
if any(len(line.tax_ids) for line in invoice.invoice_line_ids):
problems |= invoice

if problems:
raise ValueError(
_(
"There are multiple taxes in the following invoices: %(invoices)s",
invoices=", ".join(problems.mapped("name")),
)
)

@api.model
def generate_xml_document(self, invoices, check_xsd=True):
self._check_invoices(invoices)

template = self.env.ref("datev_export_xml.export_invoice_document")
root = etree.fromstring(
template._render({"docs": invoices, "company": self.env.company}),
Expand Down

0 comments on commit a5a3c11

Please sign in to comment.