Add VAT exemption code on tax

Closes #14573
This commit is contained in:
Cédric Krier
2026-02-04 10:12:56 +01:00
parent a88c575fcc
commit e7294b45c7
12 changed files with 304 additions and 4 deletions
+1
View File
@@ -1,3 +1,4 @@
* Use VATEX as tax exemption reason code
* Add support for Python 3.14
* Remove support for Python 3.9
* Fill payment means
+15 -2
View File
@@ -194,7 +194,7 @@ class Invoice(Model):
class Tax(namedtuple(
'Tax',
('type', 'rate', 'unece_category_code', 'unece_code',
'legal_notice'))):
'vatex_code', 'legal_notice'))):
@classmethod
def from_line(cls, line):
return Tax(
@@ -202,6 +202,7 @@ class Invoice(Model):
rate=line.tax.rate,
unece_category_code=line.tax.unece_category_code,
unece_code=line.tax.unece_code,
vatex_code=getattr(line.tax, 'vatex_code', ''),
legal_notice=line.legal_notice or '')
TaxLine = namedtuple('TaxLine', ('base', 'amount', 'tax'))
for group, lines in groupby(sorted(
@@ -570,8 +571,11 @@ class Invoice(Model):
],
('company', '=', company.id),
])
order = []
if hasattr(Tax, 'vatex_code'):
order.append(('vatex_code', 'ASC NULLS LAST'))
try:
tax, = Tax.search(domain, limit=1)
tax, = Tax.search(domain, limit=1, order=order)
except ValueError:
raise InvoiceError(gettext(
'edocument_ubl.msg_tax_not_found',
@@ -1135,6 +1139,8 @@ class Invoice(Model):
@classmethod
def _parse_2_tax_category(cls, tax_category):
pool = Pool()
Tax = pool.get('account.tax')
domain = [
('parent', '=', None),
]
@@ -1148,6 +1154,13 @@ class Invoice(Model):
if percent:
domain.append(('type', '=', 'percentage'))
domain.append(('rate', '=', Decimal(percent) / 100))
if (hasattr(Tax, 'vatex_code')
and (tax_exemption_reason_code := tax_category.findtext(
'./{*}TaxExemptionReasonCode'))):
domain.append(['OR',
('vatex_code', '=', tax_exemption_reason_code),
('vatex_code', '=', None),
])
return domain
@classmethod
@@ -84,6 +84,7 @@ this repository contains the full copyright notices and license terms. -->
<py:def function="TaxCategory(tax)">
<cbc:ID py:if="tax.unece_category_code">${tax.unece_category_code}</cbc:ID>
<cbc:Percent py:if="tax.type == 'percentage'">${format((tax.rate * 100).normalize(), 'f')}</cbc:Percent>
<cbc:TaxExemptionReasonCode py:if="getattr(tax, 'vatex_code', None)">${tax.vatex_code}</cbc:TaxExemptionReasonCode>
<cbc:TaxExemptionReason py:if="tax.legal_notice">${tax.legal_notice}</cbc:TaxExemptionReason>
<cac:TaxScheme py:if="tax.unece_code">
<cbc:ID>${tax.unece_code}</cbc:ID>