From 23c8e7dce80b606b141c8649e872e276911b9805 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 3 Jun 2019 11:58:21 +0200 Subject: [PATCH 1/4] 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 From 620aaf923a934b5c0d1e78758eaba7771d142df8 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Mon, 3 Jun 2019 20:40:33 +0200 Subject: [PATCH 2/4] 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 " From 32af0111bff7e4244e2d969c13b2fca0adc853ac Mon Sep 17 00:00:00 2001 From: oca-travis Date: Wed, 19 Jun 2019 14:39:09 +0000 Subject: [PATCH 3/4] [UPD] Update account_asset_management.pot --- account_asset_management/i18n/account_asset_management.pot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/account_asset_management/i18n/account_asset_management.pot b/account_asset_management/i18n/account_asset_management.pot index 70d52d8c4..452a492c9 100644 --- a/account_asset_management/i18n/account_asset_management.pot +++ b/account_asset_management/i18n/account_asset_management.pot @@ -1005,7 +1005,7 @@ msgid "This amount represent the initial value of the asset.\n" msgstr "" #. module: account_asset_management -#: code:addons/account_asset_management/models/account_move.py:135 +#: code:addons/account_asset_management/models/account_move.py:139 #, python-format msgid "This option should only be used for a single id at a time." msgstr "" @@ -1070,7 +1070,7 @@ msgstr "" #. module: account_asset_management #: code:addons/account_asset_management/models/account_move.py:69 -#: code:addons/account_asset_management/models/account_move.py:130 +#: code:addons/account_asset_management/models/account_move.py:134 #, python-format msgid "You are not allowed to link an accounting entry to an asset.\n" "You should generate such entries from the asset." @@ -1109,7 +1109,7 @@ msgid "You cannot change an accounting entry linked to an asset depreciation lin msgstr "" #. module: account_asset_management -#: code:addons/account_asset_management/models/account_move.py:126 +#: code:addons/account_asset_management/models/account_move.py:130 #, python-format msgid "You cannot change an accounting item linked to an asset depreciation line." msgstr "" From 088773760a140dc1113efd257e29aef6407e859f Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Wed, 19 Jun 2019 15:49:12 +0000 Subject: [PATCH 4/4] account_asset_management 11.0.1.0.1 --- account_asset_management/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_asset_management/__manifest__.py b/account_asset_management/__manifest__.py index 080336d41..ee5f70bf3 100644 --- a/account_asset_management/__manifest__.py +++ b/account_asset_management/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'Assets Management', - 'version': '11.0.1.0.0', + 'version': '11.0.1.0.1', 'license': 'AGPL-3', 'depends': [ 'account_fiscal_year',