From bb8f41d2a619b300b7cc9274bc6e82e314df0adb Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 27 Oct 2017 16:51:48 +0200 Subject: [PATCH] [FIX] account_asset: do not create move - Create an asset, post one line. - Go back to the asset => the button is green - Click again on the line => the button is orange There is no protection to prevent the user to post the same entry several times (a new account move is created every time it is clicked). We fix the JS widget, but we add an extra layer of protection at the Python level. opw-778756 --- addons/account_asset/i18n/account_asset.pot | 6 ++++++ addons/account_asset/models/account_asset.py | 2 ++ addons/account_asset/static/src/js/account_asset.js | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/account_asset/i18n/account_asset.pot b/addons/account_asset/i18n/account_asset.pot index d3da1903c2c..619c9d65d36 100644 --- a/addons/account_asset/i18n/account_asset.pot +++ b/addons/account_asset/i18n/account_asset.pot @@ -941,6 +941,12 @@ msgstr "" msgid "The number of depreciations needed to depreciate your asset" msgstr "" +#. module: account_asset +#: code:addons/account_asset/models/account_asset.py:477 +#, python-format +msgid "This depreciation is already linked to a journal entry! Please post or delete it." +msgstr "" + #. module: account_asset #: model:ir.ui.view,arch_db:account_asset.view_asset_depreciation_confirmation_wizard msgid "This wizard will post installment/depreciation lines for the selected month.
\n" diff --git a/addons/account_asset/models/account_asset.py b/addons/account_asset/models/account_asset.py index fd8d5efb8db..188ea8f5d16 100644 --- a/addons/account_asset/models/account_asset.py +++ b/addons/account_asset/models/account_asset.py @@ -473,6 +473,8 @@ class AccountAssetDepreciationLine(models.Model): created_moves = self.env['account.move'] prec = self.env['decimal.precision'].precision_get('Account') for line in self: + if line.move_id: + raise UserError(_('This depreciation is already linked to a journal entry! Please post or delete it.')) category_id = line.asset_id.category_id depreciation_date = self.env.context.get('depreciation_date') or line.depreciation_date or fields.Date.context_today(self) company_currency = line.asset_id.company_id.currency_id diff --git a/addons/account_asset/static/src/js/account_asset.js b/addons/account_asset/static/src/js/account_asset.js index 5fe995a98a8..9b3b4d9b3ee 100644 --- a/addons/account_asset/static/src/js/account_asset.js +++ b/addons/account_asset/static/src/js/account_asset.js @@ -25,8 +25,8 @@ var WidgetOnButton = core.list_widget_registry.get('field').extend({ } return $('
').append((this.parent_state === 'open')? $('