[FIX] sale: fix in the workflow of the sale order that appeared on invoice deletion

bzr revid: qdp-launchpad@openerp.com-20130418163616-ob30cd73vxkoe31a
This commit is contained in:
Quentin (OpenERP) 2013-04-18 18:36:16 +02:00
commit af33bef989
1 changed files with 16 additions and 0 deletions

View File

@ -999,4 +999,20 @@ 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)
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)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: