From f3b4849e0cd373bc29068277a8b601c931a7406e Mon Sep 17 00:00:00 2001 From: Jan Grasnick Date: Fri, 3 Jan 2025 22:28:58 +0100 Subject: [PATCH] handle tax childs --- mixin.py | 20 ++++++++++++++----- template/Factur-X-1.07.2-extended/invoice.xml | 4 +--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mixin.py b/mixin.py index b5eed85..2879910 100644 --- a/mixin.py +++ b/mixin.py @@ -5,6 +5,7 @@ from decimal import Decimal +import datetime import html from trytond.exceptions import UserError from trytond.i18n import gettext @@ -100,21 +101,30 @@ class EdocumentMixin(object): """ get tax of invoice-line, fire exception if no/multiple taxes exists """ - if len(line.invoice_taxes) != 1: + if len(line.taxes) != 1: raise UserError(gettext( 'edocument_xrechnung.msg_linetax_invalid_number', linename=line.rec_name, - numtax=len(line.invoice_taxes))) + numtax=len(line.taxes))) + + tax = line.taxes[0] + date = line.invoice.accounting_date or line.invoice.invoice_date + for child in tax.childs: + start_date = tax.start_date or datetime.date.min + end_date = tax.end_date or datetime.date.max + if start_date <= date <= end_date: + tax = child + break allowed_cat = ['AE', 'L', 'M', 'E', 'S', 'Z', 'G', 'O', 'K', 'B'] - unece_category_code = self.get_category_code(line.invoice_taxes[0].tax) + unece_category_code = self.get_category_code(tax) if unece_category_code not in allowed_cat: raise UserError(gettext( 'edocument_xrechnung.msg_linetax_invalid_catcode', - taxname=line.invoice_taxes[0].tax.rec_name, + taxname=tax.rec_name, allowed=', '.join(allowed_cat))) - return line.invoice_taxes[0].tax + return tax def taxident_data(self, tax_identifier): """ get tax-scheme-id and codes diff --git a/template/Factur-X-1.07.2-extended/invoice.xml b/template/Factur-X-1.07.2-extended/invoice.xml index 8a7a664..09b8e4d 100644 --- a/template/Factur-X-1.07.2-extended/invoice.xml +++ b/template/Factur-X-1.07.2-extended/invoice.xml @@ -83,9 +83,7 @@ this repository contains the full copyright notices and license terms. --> ${line.quantity * this.type_sign} - - ${TradeTax(tax.tax)} - + ${TradeTax(this.invoice_line_tax(line))} ${line.amount}