From 23c8e7dce80b606b141c8649e872e276911b9805 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 3 Jun 2019 11:58:21 +0200 Subject: [PATCH] account_asset: Do not loop on all the lines to search for one linked asset Before this change, the use of `mapped` on self did loop on all the move lines that are included in self to get the assets, what could be very costly for a simple write on a lot of move lines. As the goal is to raise an error only if at least one move is linked to an asset, we break the loop if the condition is fulfilled. --- account_asset_management/models/account_move.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index 6731af86a..a32ac9d58 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -115,8 +115,14 @@ class AccountMoveLine(models.Model): @api.multi def write(self, vals): + # Check if at least one asset is linked to a move + linked_asset = False + for move in self: + linked_asset = move.asset_id + if linked_asset: + break if ( - self.mapped('asset_id') and + linked_asset and set(vals).intersection(FIELDS_AFFECTS_ASSET_MOVE_LINE) and not ( self.env.context.get('allow_asset_removal') and