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.
This commit is contained in:
Akim Juillerat
2019-06-03 11:58:21 +02:00
committed by OCA-git-bot
parent 76fcbbf145
commit 23c8e7dce8

View File

@@ -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