From 944f8e33537c69d88f2c1ea6fe6207059caaee6e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 13 Jun 2017 15:45:20 +0200 Subject: [PATCH] [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 2687571781a9518323b3c08ea7772ecb56eb39d1 --- addons/account/models/account_move.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f7c00e65dd3..8232d99f071 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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)