[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
This commit is contained in:
parent
f5eae92f12
commit
d812175390
|
@ -47,11 +47,12 @@ class account_invoice_line(osv.osv):
|
||||||
def asset_create(self, cr, uid, lines, context=None):
|
def asset_create(self, cr, uid, lines, context=None):
|
||||||
context = context or {}
|
context = context or {}
|
||||||
asset_obj = self.pool.get('account.asset.asset')
|
asset_obj = self.pool.get('account.asset.asset')
|
||||||
|
asset_ids = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.invoice_id.number:
|
if line.invoice_id.number:
|
||||||
if asset_obj.search(cr, SUPERUSER_ID, [('code', '=', line.invoice_id.number)], context=context):
|
#FORWARDPORT UP TO SAAS-6
|
||||||
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))
|
asset_ids += asset_obj.search(cr, SUPERUSER_ID, [('code', '=', line.invoice_id.number), ('company_id', '=', line.company_id.id)], context=context)
|
||||||
|
asset_obj.write(cr, SUPERUSER_ID, asset_ids, {'active': False})
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.asset_category_id:
|
if line.asset_category_id:
|
||||||
vals = {
|
vals = {
|
||||||
|
|
Loading…
Reference in New Issue