From 620aaf923a934b5c0d1e78758eaba7771d142df8 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Mon, 3 Jun 2019 20:40:33 +0200 Subject: [PATCH] performance improvement --- .../models/account_move.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index a32ac9d58..e9cb04b1b 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -115,22 +115,20 @@ 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 ( - linked_asset and set(vals).intersection(FIELDS_AFFECTS_ASSET_MOVE_LINE) and not ( self.env.context.get('allow_asset_removal') and list(vals.keys()) == ['asset_id']) ): - raise UserError( - _("You cannot change an accounting item " - "linked to an asset depreciation line.")) + # 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: + raise UserError( + _("You cannot change an accounting item " + "linked to an asset depreciation line.")) if vals.get('asset_id'): raise UserError( _("You are not allowed to link "