From fa2f71e2fe927a9cc8bceda7b404339f6afeff0e Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Fri, 28 May 2021 09:03:22 +0200 Subject: [PATCH] Check roots of lines per company issue10451 review363361004 --- line.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/line.py b/line.py index 06789c69d8..8027ffaa8f 100644 --- a/line.py +++ b/line.py @@ -2,6 +2,7 @@ # this repository contains the full copyright notices and license terms. from decimal import Decimal from collections import defaultdict +from itertools import groupby from sql import Literal @@ -258,8 +259,11 @@ class MoveLine(ModelSQL, ModelView): roots = AnalyticAccount.search([ ('parent', '=', None), - ]) - roots = set(roots) + ], + order=[('company', 'ASC')]) + company2roots = { + company: set(roots) + for company, roots in groupby(roots, key=lambda r: r.company)} for line in lines: if not line.must_have_analytic: @@ -272,6 +276,7 @@ class MoveLine(ModelSQL, ModelView): for analytic_line in line.analytic_lines: amount = analytic_line.debit - analytic_line.credit amounts[analytic_line.account.root] += amount + roots = company2roots[line.move.company] if not roots <= set(amounts.keys()): line.analytic_state = 'draft' continue