[FIX] account: Improved performance when validating an invoice

When doing a delete, the cache is cleaned, putting an unlink in a loop
multiply the number of requests made (for access rules, relational
field, recompute ...) by the number of rows. The use of a mapped improves
the speed of validation of an invoice.
This commit is contained in:
Christophe Matthieu
2017-06-13 15:45:20 +02:00
parent 70d522eb31
commit 2687571781
+1 -2
View File
@@ -1246,9 +1246,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)