mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
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:
committed by
OCA-git-bot
parent
76fcbbf145
commit
23c8e7dce8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user