+
+class account_invoice(osv.Model):
+ _inherit = 'account.invoice'
+
+ def unlink(self, cr, uid, ids, context=None):
+ """ Overwrite unlink method of account invoice to send a trigger to the sale workflow upon invoice deletion """
+ invoice_ids = self.search(cr, uid, [('id', 'in', ids), ('state', 'in', ['draft', 'cancel'])], context=context)
+ #if we can't cancel all invoices, do nothing
+ if len(invoice_ids) == len(ids):
+ #Cancel invoice(s) first before deleting them so that if any sale order is associated with them
+ #it will trigger the workflow to put the sale order in an 'invoice exception' state
+ wf_service = netsvc.LocalService("workflow")
+ for id in ids:
+ wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
+ return super(account_invoice, self).unlink(cr, uid, ids, context=context)
+