[WIP] Use of trg_model for purchase workflow, but have to see why it does not work
bzr revid: jco@openerp.com-20130718131816-i2b2ga6updkmjmq0
This commit is contained in:
parent
9c2536bc8a
commit
e0f8a9d5a7
|
@ -719,6 +719,15 @@ class purchase_order(osv.osv):
|
|||
alldoneorcancel = False
|
||||
return cancel and alldoneorcancel
|
||||
|
||||
|
||||
def move_lines_get(self, cr, uid, ids, *args):
|
||||
res = []
|
||||
for order in self.browse(cr, uid, ids, context={}):
|
||||
for line in order.order_line:
|
||||
res += [x.id for x in line.move_ids]
|
||||
return res
|
||||
|
||||
|
||||
def action_picking_create(self, cr, uid, ids, context=None):
|
||||
picking_ids = []
|
||||
for order in self.browse(cr, uid, ids):
|
||||
|
|
|
@ -76,12 +76,14 @@
|
|||
<field name="kind">function</field>
|
||||
<field name="action">action_picking_create()</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record id="act_picking_done" model="workflow.activity">
|
||||
<field name="wkf_id" ref="purchase_order"/>
|
||||
<field name="name">picking_done</field>
|
||||
<field name="action">picking_done()</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="signal_send">subflow.delivery_done</field>
|
||||
</record>
|
||||
<record id="act_done" model="workflow.activity">
|
||||
<field name="wkf_id" ref="purchase_order"/>
|
||||
|
@ -171,6 +173,8 @@
|
|||
<record id="trans_picking_except_picking" model="workflow.transition">
|
||||
<field name="act_from" ref="act_picking"/>
|
||||
<field name="act_to" ref="act_except_picking"/>
|
||||
<field name="trigger_model">stock.move</field>
|
||||
<field name="trigger_expr_id">move_lines_get()</field>
|
||||
<field name="condition">test_moves_except()</field>
|
||||
</record>
|
||||
<record id="trans_invoice_except_invoice" model="workflow.transition">
|
||||
|
@ -181,7 +185,10 @@
|
|||
<record id="trans_picking_picking_done" model="workflow.transition">
|
||||
<field name="act_from" ref="act_picking"/>
|
||||
<field name="act_to" ref="act_picking_done"/>
|
||||
<field name="trigger_model">stock.move</field>
|
||||
<field name="trigger_expr_id">move_lines_get()</field>
|
||||
<field name="condition">test_moves_done()</field>
|
||||
|
||||
</record>
|
||||
<record id="trans_invoice_invoice_done" model="workflow.transition">
|
||||
<field name="act_from" ref="act_invoice"/>
|
||||
|
|
|
@ -31,20 +31,6 @@ 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
|
||||
#
|
||||
|
|
|
@ -1328,24 +1328,9 @@ class stock_move(osv.osv):
|
|||
raise osv.except_osv(_('Operation Forbidden!'),
|
||||
_('Quantities, Units of Measure, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator).'))
|
||||
result = super(stock_move, self).write(cr, uid, ids, vals, context=context)
|
||||
self._update_picking(cr, uid, ids, vals, context=context)
|
||||
return result
|
||||
|
||||
# update picking as the move changed
|
||||
def _update_picking(self, cr, uid, ids, vals, context=None):
|
||||
# FP Note: test if this would do the trick
|
||||
#for id in ids:
|
||||
# wf_service.trg_trigger(uid, 'stock.move', id, cr)
|
||||
if ('state' in vals) or ('picking_id' in vals):
|
||||
wf_service = netsvc.LocalService('workflow')
|
||||
done = {}
|
||||
for move in self.browse(cr, uid, ids, context):
|
||||
if move.picking_id and (move.picking_id.id not in done):
|
||||
wf_service.trg_write(uid, 'stock.picking', move.picking_id.id, cr)
|
||||
done[move.picking_id.id] = True
|
||||
for id in ids:
|
||||
wf_service.trg_trigger(uid, 'stock.move', id, cr)
|
||||
return True
|
||||
|
||||
|
||||
def _auto_init(self, cursor, context=None):
|
||||
res = super(stock_move, self)._auto_init(cursor, context=context)
|
||||
|
@ -1678,11 +1663,6 @@ class stock_move(osv.osv):
|
|||
self.action_assign(cr, uid, [move.move_dest_id.id], context=context)
|
||||
self.write(cr, uid, ids, {'state': 'done', 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}, context=context)
|
||||
|
||||
if move.picking_id:
|
||||
move.picking_id.refresh()
|
||||
if all([m.state in ('done', 'cancel') for m in move.picking_id.move_lines]):
|
||||
#finish the picking if it was the last move (we exclude the move we just set to done because we know the value and the browse record cache isn't up to date
|
||||
picking_obj.action_done(cr, uid, [move.picking_id.id], context=context)
|
||||
return True
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
|
Loading…
Reference in New Issue