From a5d169f1a81ca64f2b047288f2d8aa3446171ef5 Mon Sep 17 00:00:00 2001 From: "Claire Bretton (clbr)" Date: Tue, 9 Jan 2024 15:43:50 +0000 Subject: [PATCH] [FIX] l10n_ch: fix data migration In a previous commit we fixed Swiss localization's taxes data. We changed two children taxes that had wrong tax_type_use since it depends on their parents. This could raise the python constraint `_check_children_scope()` which is preventing some databases to correctly update their taxes. See https://github.com/odoo/odoo/commit/7b07df873535446f97abc1de9176b9332de5cb07 closes odoo/odoo#150669 X-original-commit: 90e064140b88b77d75686558106f79664da4af48 Signed-off-by: Olivier Colson (oco) Signed-off-by: Claire Bretton (clbr) --- .../migrations/11.1/post-migrate_update_taxes.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/l10n_ch/migrations/11.1/post-migrate_update_taxes.py b/addons/l10n_ch/migrations/11.1/post-migrate_update_taxes.py index 6b420315510..90d6585ef5e 100644 --- a/addons/l10n_ch/migrations/11.1/post-migrate_update_taxes.py +++ b/addons/l10n_ch/migrations/11.1/post-migrate_update_taxes.py @@ -5,4 +5,17 @@ from odoo import api, SUPERUSER_ID def migrate(cr, version): env = api.Environment(cr, SUPERUSER_ID, {}) for company in env['res.company'].search([('chart_template', '=', 'ch')]): + # We had corrupted data, handle the correction so the tax update can proceed. + # See https://github.com/odoo/odoo/commit/7b07df873535446f97abc1de9176b9332de5cb07 + taxes_to_check = (f'{company.id}_vat_purchase_81_reverse', f'{company.id}_vat_77_purchase_reverse') + tax_ids = env['ir.model.data'].search([ + ('name', 'in', taxes_to_check), + ('model', '=', 'account.tax'), + ]).mapped('res_id') + for tax in env['account.tax'].browse(tax_ids).with_context(active_test=False): + for child in tax.children_tax_ids: + if child.type_tax_use not in ('none', tax.type_tax_use): + # set the child to it's parent's value + child.type_tax_use = tax.type_tax_use + env['account.chart.template'].try_loading('ch', company)