From cb5d41da3b236611506ad07efb3476b7f88ba36f Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 14 Apr 2016 16:16:56 +0200 Subject: [PATCH] [FIX] account_asset: asset_create When creating assets from invoice lines, the system must check that assets have not already been created for the related invoice. If assets already exist then these assets have to be removed. Used case: - In the purchase journal, tick "allow canceling entries" - On a supplier invoice line, set an asset category - validate the invoice - cancel the invoice - set to draft - validate the invoice Before the fix: the asset was created twice. After the fix: A warning is raised if an asset already exists for the invoice. opw:674674 --- addons/account_asset/account_asset_invoice.py | 7 +++++++ addons/account_asset/i18n/account_asset.pot | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/addons/account_asset/account_asset_invoice.py b/addons/account_asset/account_asset_invoice.py index 38fea23fbe3..9212bc2f73c 100644 --- a/addons/account_asset/account_asset_invoice.py +++ b/addons/account_asset/account_asset_invoice.py @@ -19,7 +19,9 @@ # ############################################################################## +from openerp import SUPERUSER_ID from openerp.osv import fields, osv +from openerp.tools.translate import _ class account_invoice(osv.osv): @@ -45,6 +47,11 @@ class account_invoice_line(osv.osv): def asset_create(self, cr, uid, lines, context=None): context = context or {} asset_obj = self.pool.get('account.asset.asset') + for line in lines: + if line.invoice_id.number: + if asset_obj.search(cr, SUPERUSER_ID, [('code', '=', line.invoice_id.number)], context=context): + raise osv.except_osv(_('Warning!'), _('You already have assets with the reference %s.\nPlease delete these assets before creating new ones for this invoice.') % (line.invoice_id.number)) + for line in lines: if line.asset_category_id: vals = { diff --git a/addons/account_asset/i18n/account_asset.pot b/addons/account_asset/i18n/account_asset.pot index 8b7e9405ed5..56b547ebcdf 100644 --- a/addons/account_asset/i18n/account_asset.pot +++ b/addons/account_asset/i18n/account_asset.pot @@ -782,6 +782,12 @@ msgstr "" msgid "Year" msgstr "" +#. module: account_asset +#: code:addons/account_asset/account_asset_invoice.py:53 +#, python-format +msgid "You already have assets with the reference %s.\nPlease delete these assets before creating new ones for this invoice." +msgstr "" + #. module: account_asset #: code:addons/account_asset/account_asset.py:81 #, python-format