From 515ea2afb507a40656cc636dd7e9b19a6ebeee21 Mon Sep 17 00:00:00 2001 From: "Paolo Gatti (pgi)" Date: Mon, 15 Apr 2024 16:11:03 +0200 Subject: [PATCH] [FIX] account: Delay of account.tax.repartition_line_ids must clear MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we delay the creation of `repartition_line_ids`, the `account.tax` gets created with default `base` and `tax` repartition lines, which we must get rid of when we update the tax with the delayed repartition lines. related PR: #148370 task-3607459 closes odoo/odoo#157918 Signed-off-by: William André (wan) --- addons/account/models/chart_template.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index 20f68f394e5..d8739530f2c 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -537,6 +537,15 @@ class AccountChartTemplate(models.AbstractModel): to_be_removed = [] for field_name, field_val in vals.items(): if should_delay(created_models, yet_to_be_created_models, model, field_name, field_val): + # Default repartition lines will be created when we create account.tax + # If we delay the creation of repartition_line_ids, then we must get rid of the defaults + if ( + model == 'account.tax' and 'repartition_line_ids' in field_name + and not self.ref(xml_id, raise_if_not_found=False) + and all(isinstance(x, tuple | list) for x in field_val) + and all(int(x[0]) in Command for x in field_val) + ): + field_val = [Command.clear()] + field_val to_be_removed.append(field_name) to_delay[xml_id][field_name] = field_val for field_name in to_be_removed: