Refactor to use write multi and remove debug code

This commit is contained in:
Sergi Almacellas Abellana 2016-02-18 11:31:50 +01:00
parent a74f822a00
commit 63ce1391bd
2 changed files with 22 additions and 20 deletions

View file

@ -1,7 +1,5 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import logging
import time
from itertools import chain
from trytond.model import ModelView, fields
@ -223,7 +221,6 @@ class MoveLine:
pool = Pool()
AnalyticLine = pool.get('analytic_account.line')
start_time = time.time()
todraft, tovalid = [], []
for line in lines:
analytic_lines_by_root = {}
@ -248,10 +245,6 @@ class MoveLine:
AnalyticLine.write(tovalid, {
'state': 'valid',
})
logging.getLogger(cls.__name__).debug(
"validate_analytic_lines(): %s seconds"
% (time.time() - start_time))
return todraft + tovalid
@classmethod
def create(cls, vlist):

View file

@ -442,23 +442,32 @@ class AnalyticLine:
return lines
@classmethod
def write(cls, lines, vals):
def write(cls, *args):
MoveLine = Pool().get('account.move.line')
if any(k not in cls._check_modify_exclude for k in vals):
cls.check_modify(lines)
actions = iter(args)
lines_to_check, all_lines = [], []
for lines, vals in zip(actions, actions):
if any(k not in cls._check_modify_exclude for k in vals):
lines_to_check.extend(lines)
all_lines.extend(lines)
cls.check_modify(lines_to_check)
move_lines = [l.move_line for l in lines if l.move_line]
super(AnalyticLine, cls).write(lines, vals)
move_lines += [l.move_line for l in lines if l.move_line]
move_lines = set([l.move_line for l in all_lines if l.move_line])
super(AnalyticLine, cls).write(*args)
move_lines |= set([l.move_line for l in all_lines if l.move_line])
if any(k not in cls._check_modify_exclude for k in vals):
cls.check_modify(lines)
MoveLine.validate_analytic_lines(list(set(move_lines)))
todraft_lines = [l for l in lines
if (not l.move_line and l.state != 'draft')]
cls.write(todraft_lines, {
lines_to_check = []
for lines, vals in zip(actions, actions):
if any(k not in cls._check_modify_exclude for k in vals):
lines_to_check.extend(lines)
cls.check_modify(lines_to_check)
MoveLine.validate_analytic_lines(list(move_lines))
todraft_lines = [l for l in all_lines
if (not l.move_line and l.state != 'draft')]
# Call super to avoid_recursion error:
if todraft_lines:
super(AnalyticLine, cls).write(todraft_lines, {
'state': 'draft',
})