diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index c5b30f58a77..4a1b5583e7e 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -692,9 +692,33 @@ class purchase_order(osv.osv):
todo_moves.append(move)
stock_move.action_confirm(cr, uid, todo_moves)
stock_move.force_assign(cr, uid, todo_moves)
- stock_picking.signal_button_confirm(cr, uid, [picking_id])
return [picking_id]
+ def test_moves_done(self, cr, uid, ids, context=None):
+ done = True
+ for purchase in self.browse(cr, uid, ids, context=context):
+ for line in purchase.order_line:
+ for move in line.move_ids:
+ if move.state != 'done':
+ done = False
+ return done
+
+
+ def test_moves_except(self, cr, uid, ids, context=None):
+ '''
+ If one of the pickings is cancel and the other pickings are done: except
+ '''
+ cancel = False
+ alldoneorcancel = True
+ for purchase in self.browse(cr, uid, ids, context=context):
+ for line in purchase.order_line:
+ for move in line.move_ids:
+ if move.state == 'cancel':
+ cancel = True
+ if move.state not in ['done', 'cancel']:
+ alldoneorcancel = False
+ return cancel and alldoneorcancel
+
def action_picking_create(self, cr, uid, ids, context=None):
picking_ids = []
for order in self.browse(cr, uid, ids):
diff --git a/addons/purchase/purchase_workflow.xml b/addons/purchase/purchase_workflow.xml
index 2088c109376..bc9ef988fd1 100644
--- a/addons/purchase/purchase_workflow.xml
+++ b/addons/purchase/purchase_workflow.xml
@@ -73,8 +73,7 @@
picking
- subflow
-
+ function
action_picking_create()
@@ -172,7 +171,7 @@
- subflow.cancel
+ test_moves_except()
@@ -182,7 +181,7 @@
- subflow.done
+ test_moves_done()
diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py
index 794ff220514..bff0c59f399 100644
--- a/addons/purchase/stock.py
+++ b/addons/purchase/stock.py
@@ -20,7 +20,7 @@
##############################################################################
from openerp.osv import fields, osv
-
+from openerp import netsvc
class stock_move(osv.osv):
_inherit = 'stock.move'
_columns = {
@@ -30,6 +30,21 @@ class stock_move(osv.osv):
}
+
+ def action_done(self, cr, uid, ids, context=None):
+ '''
+ THIS SHOULD BE REPLACED BY SOMETHING THAT WILL TRIGGER AUTOMATICALLY
+ DOES NOT WORK ANYWAYS
+ '''
+ res = super(stock_move, self).action_done(cr, uid, ids, context=context)
+ wf_service = netsvc.LocalService("workflow")
+ for move in self.browse(cr, uid, ids, context=context):
+ if move.purchase_line_id:
+ wf_service.trg_trigger(uid, 'purchase.order', move.purchase_line_id.order_id.id, cr)
+ return res
+
+
+
#
# Inherit of picking to add the link to the PO
#