[FIX]sale: fix workflow problem when deleting an invoice the workflow should go to invoice_exception state

bzr revid: csn@openerp.com-20130418090011-dyg175mvwrp8ilij
This commit is contained in:
Cedric Snauwaert 2013-04-18 11:00:11 +02:00
parent d279819af7
commit b8d99e7aa3
1 changed files with 18 additions and 0 deletions

View File

@ -999,4 +999,22 @@ class mail_compose_message(osv.Model):
wf_service.trg_validate(uid, 'sale.order', context['default_res_id'], 'quotation_sent', cr)
return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
#
# account.invoice is defined in module account
#
class account_invoice(osv.Model):
""" Overwrite unlink method of account invoice to send a trigger to the sale workflow upon invoice deletion """
_inherit = 'account.invoice'
def unlink(self, cr, uid, ids, context=None):
#Cancel invoice(s) first before deleting them so that if any sale order are associated with them
#it will trigger the workflow to put the sale order in an invoice exception state
#if we can't cancel all invoices, do nothing
invoice_ids = self.search(cr, uid, [('id', 'in', ids), ('state', 'in', ['draft', 'cancel'])], context=context)
if len(invoice_ids)==len(ids):
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)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: