From 96f1f1f10d67440891d684fd6e58433a4dacc1be Mon Sep 17 00:00:00 2001 From: Brice bib Bartoletti Date: Wed, 8 Jun 2022 09:20:28 +0000 Subject: [PATCH] [FIX] account: deterministic sorting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aim of this commit is to make `get_lines_in_hierarchy` yielding the lines in the same order even if 2 sequences are the same. The additionnal diff correct the iteration to get it in the same order in copy than in `get_lines_in_hierarchy`. closes odoo/odoo#93156 Task: None Pr-community: https://github.com/odoo/odoo/pull/93061 X-original-commit: decc29d59baee1398a4497097055a2332e2305d7 Signed-off-by: William André (wan) --- addons/account/models/account_tax_report.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/addons/account/models/account_tax_report.py b/addons/account/models/account_tax_report.py index 8825c004971..95c0c9a7b2b 100644 --- a/addons/account/models/account_tax_report.py +++ b/addons/account/models/account_tax_report.py @@ -54,11 +54,7 @@ class AccountTaxReport(models.Model): copied_report = super(AccountTaxReport, self).copy(default=copy_default) #This copies the report without its lines lines_map = {} # maps original lines to their copies (using ids) - lines_to_treat = list(self.line_ids.filtered(lambda x: not x.parent_id)) - while lines_to_treat: - line = lines_to_treat.pop() - lines_to_treat += list(line.children_line_ids) - + for line in self.get_lines_in_hierarchy(): copy = line.copy({'parent_id': lines_map.get(line.parent_id.id, None), 'report_id': copied_report.id}) lines_map[line.id] = copy.id @@ -69,10 +65,10 @@ class AccountTaxReport(models.Model): ar all directly followed by their children. """ self.ensure_one() - lines_to_treat = list(self.line_ids.filtered(lambda x: not x.parent_id).sorted(lambda x: x.sequence)) # Used as a stack, whose index 0 is the top + lines_to_treat = list(self.line_ids.filtered(lambda x: not x.parent_id)) # Used as a stack, whose index 0 is the top while lines_to_treat: to_yield = lines_to_treat[0] - lines_to_treat = list(to_yield.children_line_ids.sorted(lambda x: x.sequence)) + lines_to_treat[1:] + lines_to_treat = list(to_yield.children_line_ids) + lines_to_treat[1:] yield to_yield def get_checks_to_perform(self, amounts, carried_over): @@ -95,7 +91,7 @@ class AccountTaxReport(models.Model): class AccountTaxReportLine(models.Model): _name = "account.tax.report.line" _description = 'Account Tax Report Line' - _order = 'sequence' + _order = 'sequence, id' _parent_store = True name = fields.Char(