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}