From c8ea9f9f2e3c04922af0d5494c0b5ad648b95c82 Mon Sep 17 00:00:00 2001
From: "Claire Bretton (clbr)" <clbr@odoo.com>
Date: Tue, 21 Feb 2023 17:03:32 +0000
Subject: [PATCH] [FIX] account, l10n_ch: enable new taxes after module update

Swiss taxes retrieved by module update (and the update of taxes it triggers)
need to be active, even if the template data was set to inactive.

closes odoo/odoo#113001

Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
---
 addons/account/models/chart_template.py                    | 1 +
 addons/l10n_ch/migrations/11.1/end-migrate_update_taxes.py | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py
index d275de7df54d..03ef0d207644 100644
--- a/addons/account/models/chart_template.py
+++ b/addons/account/models/chart_template.py
@@ -212,6 +212,7 @@ def update_taxes_from_templates(cr, chart_template_xmlid):
         _notify_accountant_managers(outdated_taxes)
     if hasattr(chart_template, 'spoken_languages') and chart_template.spoken_languages:
         _process_taxes_translations(chart_template, new_template2tax)
+    return new_template2tax
 
 #  ---------------------------------------------------------------
 #   Account Templates: Account, Tax, Tax Code and chart. + Wizard
diff --git a/addons/l10n_ch/migrations/11.1/end-migrate_update_taxes.py b/addons/l10n_ch/migrations/11.1/end-migrate_update_taxes.py
index 6f14580a5581..81d93b5b9af1 100644
--- a/addons/l10n_ch/migrations/11.1/end-migrate_update_taxes.py
+++ b/addons/l10n_ch/migrations/11.1/end-migrate_update_taxes.py
@@ -1,6 +1,10 @@
 # Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import api, SUPERUSER_ID
 from odoo.addons.account.models.chart_template import update_taxes_from_templates
 
 
 def migrate(cr, version):
-    update_taxes_from_templates(cr, 'l10n_ch.l10nch_chart_template')
+    new_template_to_tax = update_taxes_from_templates(cr, 'l10n_ch.l10nch_chart_template')
+    _, new_tax_ids = zip(*new_template_to_tax)
+    env = api.Environment(cr, SUPERUSER_ID, {})
+    env['account.tax'].browse(new_tax_ids).active = True
-- 
GitLab