From 64e822c8259ae7d7410a4e91c6181e8959a5d041 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 25 Apr 2016 17:11:34 +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 is created twice. After the fix: the asset is created once. opw:674674 Note: This is a cherry-pick of commits 9d14230 and 58a5b5e --- addons/account_asset/account_asset_invoice.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/account_asset/account_asset_invoice.py b/addons/account_asset/account_asset_invoice.py index e47d7cee668..c3e6add1042 100644 --- a/addons/account_asset/account_asset_invoice.py +++ b/addons/account_asset/account_asset_invoice.py @@ -17,8 +17,9 @@ class AccountInvoice(models.Model): result = super(AccountInvoice, self).action_number() for inv in self: if inv.number: - if self.env['account.asset.asset'].sudo().search([('code', '=', inv.number)]): - raise Warning(_('You already have assets with the reference %s.\nPlease delete these assets before creating new ones for this invoice.') % (inv.number,)) + asset_ids = self.env['account.asset.asset'].sudo().search([('invoice_id', '=', inv.id), ('company_id', '=', inv.company_id.id)]) + if asset_ids: + asset_ids.write({'active': False}) inv.invoice_line.asset_create() return result