summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorCedric Snauwaert <csn@openerp.com>2013-04-18 11:00:11 +0200
committerCedric Snauwaert <csn@openerp.com>2013-04-18 11:00:11 +0200
commitb8d99e7aa320c8ddd8c7a2ffdbc6391a1a443d31 (patch)
tree4e9ba42868bb59a3abef8e6dcb89aafa9d9eb16c /addons
parentd279819af7810d191f772364578d763b915f4997 (diff)
[FIX]sale: fix workflow problem when deleting an invoice the workflow should go to invoice_exception state
bzr revid: csn@openerp.com-20130418090011-dyg175mvwrp8ilij
Diffstat (limited to 'addons')
-rw-r--r--addons/sale/sale.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index a6be2838171..7364932f91c 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -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: