[FIX] account_asset: cancel invoice

Extension of commit 9d14230d74. Deactivate the assets when the invoice
is cancelled, which is more logical.

opw-703108
This commit is contained in:
Nicolas Martinelli
2017-01-11 16:56:23 +01:00
parent cdf62af265
commit f60936fafe
@@ -12,14 +12,16 @@ import odoo.addons.decimal_precision as dp
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
@api.multi
def action_cancel(self):
res = super(AccountInvoice, self).action_cancel()
self.env['account.asset.asset'].sudo().search([('invoice_id', 'in', self.ids)]).write({'active': False})
return res
@api.multi
def action_move_create(self):
result = super(AccountInvoice, self).action_move_create()
for inv in self:
if 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})
context = dict(self.env.context)
# Within the context of an invoice,
# this default value is for the type of the invoice, not the type of the asset.