From 8fa0de522602a9b0966cad8d4221a568c3454b4d Mon Sep 17 00:00:00 2001 From: Bejaoui Souheil Date: Thu, 20 Jun 2019 19:19:51 +0200 Subject: [PATCH] Finish 12.0 migration of account_asset_management * 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. * performance improvement * [RMV] - Remove useless dependency In 12.0 account_fiscal_year is a standard feature no need to depend on oca module account_fiscal_year --- account_asset_management/__manifest__.py | 2 +- account_asset_management/models/account_move.py | 12 ++++++++---- .../static/description/index.html | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/account_asset_management/__manifest__.py b/account_asset_management/__manifest__.py index fc8fa453..a5cfefb3 100644 --- a/account_asset_management/__manifest__.py +++ b/account_asset_management/__manifest__.py @@ -6,7 +6,7 @@ 'version': '12.0.1.0.0', 'license': 'AGPL-3', 'depends': [ - 'account_fiscal_year', + 'account', ], 'excludes': ['account_asset'], 'author': "Noviat,Odoo Community Association (OCA)", diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index 6731af86..e9cb04b1 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -116,15 +116,19 @@ class AccountMoveLine(models.Model): @api.multi def write(self, vals): if ( - self.mapped('asset_id') 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 " diff --git a/account_asset_management/static/description/index.html b/account_asset_management/static/description/index.html index d74efd82..b189e935 100644 --- a/account_asset_management/static/description/index.html +++ b/account_asset_management/static/description/index.html @@ -3,7 +3,7 @@ - + Assets Management