[FIX] account: improve performance when validating an invoice

When doing a delete, the cache is cleared, putting an unlink in a loop
multiplies the number of requests made (for access rules, relational
field, recompute ...) by the number of rows. Doing it outside the loop
speeds up the validation of the invoice.

Backport of 10.0's 2687571781
This commit is contained in:
Christophe Matthieu
2017-06-14 10:15:47 +02:00
committed by Olivier Dony
parent 05ef0790c9
commit 944f8e3353
+1 -2
View File
@@ -1243,9 +1243,8 @@ class AccountMoveLine(models.Model):
""" Create analytic items upon validation of an account.move.line having an analytic account. This
method first remove any existing analytic item related to the line before creating any new one.
"""
self.mapped('analytic_line_ids').unlink()
for obj_line in self:
if obj_line.analytic_line_ids:
obj_line.analytic_line_ids.unlink()
if obj_line.analytic_account_id:
vals_line = obj_line._prepare_analytic_line()[0]
self.env['account.analytic.line'].create(vals_line)