From 82da221b1fb761bdab84c4ffd3924809df2bec39 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Fri, 8 Jun 2018 14:48:37 +0200 Subject: [PATCH] [FIX] l10n_de: DATEV export compatiblity When invoicing a line with an account that has a tax, ensure that line has the same tax of accounts. This is required by DATEV and is common usage in Germany Was task 35289 Was PR #25202 --- addons/l10n_de/models/datev.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/addons/l10n_de/models/datev.py b/addons/l10n_de/models/datev.py index 082729970aa..1578b09050f 100644 --- a/addons/l10n_de/models/datev.py +++ b/addons/l10n_de/models/datev.py @@ -1,4 +1,6 @@ -from odoo import fields, models +from odoo import api, fields, models +from odoo.exceptions import UserError +from odoo.tools.translate import _ class AccountTaxTemplate(models.Model): _inherit = 'account.tax.template' @@ -14,3 +16,18 @@ class AccountTax(models.Model): _inherit = "account.tax" l10n_de_datev_code = fields.Char(size=2, help="2 digits code use by Datev") + +class AccountInvoice(models.Model): + _inherit = "account.invoice" + + def invoice_validate(self): + for invoice in self: + for line in invoice.invoice_line_ids: + account_tax = line.account_id.tax_ids.ids + if account_tax and invoice.company_id.country_id.code == 'DE': + account_name = line.account_id.name + for tax in line.invoice_line_tax_ids: + if tax.id not in account_tax: + raise UserError(_('Account %s does not authorize to have tax %s specified on the line. \ + Change the tax used in this invoice or remove all taxes from the account') % (account_name, tax.name)) + return super(AccountInvoice, self).invoice_validate() \ No newline at end of file