Check roots of lines per company

issue10451
review363361004
This commit is contained in:
Sergi Almacellas Abellana
2021-05-28 09:03:22 +02:00
parent d42296ea02
commit fa2f71e2fe
+7 -2
View File
@@ -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