[MERGE] Cancelling sale order should affect Procurements,production orders
authorRaphael Collet <rco@openerp.com>
Wed, 14 Sep 2011 14:17:35 +0000 (16:17 +0200)
committerRaphael Collet <rco@openerp.com>
Wed, 14 Sep 2011 14:17:35 +0000 (16:17 +0200)
bzr revid: rco@openerp.com-20110914141735-xysq4cvyagges1uc

addons/sale/sale.py

index 3f88edf..fea92c8 100644 (file)
@@ -501,6 +501,7 @@ class sale_order(osv.osv):
     
     def action_cancel(self, cr, uid, ids, context={}):
         ok = True
+        wf_service = netsvc.LocalService("workflow")
         sale_order_line_obj = self.pool.get('sale.order.line')
         for sale in self.browse(cr, uid, ids):
             for pick in sale.picking_ids:
@@ -508,9 +509,14 @@ class sale_order(osv.osv):
                     raise osv.except_osv(
                         _('Could not cancel sale order !'),
                         _('You must first cancel all packing attached to this sale order.'))
+                if pick.state == 'cancel':
+                    for mov in pick.move_lines:
+                        proc_ids = self.pool.get('mrp.procurement').search(cr, uid, [('move_id', '=', mov.id)])
+                        if proc_ids:
+                            for proc in proc_ids:
+                                wf_service.trg_validate(uid, 'mrp.procurement', proc, 'button_check', cr)
             for r in self.read(cr, uid, ids, ['picking_ids']):
                 for pick in r['picking_ids']:
-                    wf_service = netsvc.LocalService("workflow")
                     wf_service.trg_validate(uid, 'stock.picking', pick, 'button_cancel', cr)
             for inv in sale.invoice_ids:
                 if inv.state not in ('draft', 'cancel'):
@@ -519,7 +525,6 @@ class sale_order(osv.osv):
                         _('You must first cancel all invoices attached to this sale order.'))
             for r in self.read(cr, uid, ids, ['invoice_ids']):
                 for inv in r['invoice_ids']:
-                    wf_service = netsvc.LocalService("workflow")
                     wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr)
             sale_order_line_obj.write(cr, uid, [l.id for l in  sale.order_line],
                     {'state': 'cancel'})