From f60936fafe37e381d582a1d6b8e84d0b2384e4ed Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 11 Jan 2017 16:53:46 +0100 Subject: [PATCH] [FIX] account_asset: cancel invoice Extension of commit 9d14230d74e. Deactivate the assets when the invoice is cancelled, which is more logical. opw-703108 --- addons/account_asset/models/account_invoice.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account_asset/models/account_invoice.py b/addons/account_asset/models/account_invoice.py index 3e45b722976..f9aa4e90907 100644 --- a/addons/account_asset/models/account_invoice.py +++ b/addons/account_asset/models/account_invoice.py @@ -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.