[FIX] purchase: cancel PO lines and set related procurements in exception on cancelation of a PO
This commit is contained in:
parent
db98434e85
commit
940b5beb26
|
@ -266,6 +266,22 @@ class purchase_order(osv.osv):
|
|||
|
||||
return super(purchase_order, self).unlink(cr, uid, unlink_ids, context=context)
|
||||
|
||||
def set_order_line_status(self, cr, uid, ids, status, context=None):
|
||||
line = self.pool.get('purchase.order.line')
|
||||
order_line_ids = []
|
||||
move_ids = []
|
||||
proc_obj = self.pool.get('procurement.order')
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
order_line_ids += [po_line.id for po_line in order.order_line]
|
||||
move_ids += [po_line.move_dest_id.id for po_line in order.order_line if po_line.move_dest_id]
|
||||
if order_line_ids:
|
||||
line.write(cr, uid, order_line_ids, {'state': status}, context=context)
|
||||
if order_line_ids and status == 'cancel':
|
||||
procs = proc_obj.search(cr, uid, [('move_id', 'in', move_ids)], context=context)
|
||||
if procs:
|
||||
proc_obj.write(cr, uid, procs, {'state': 'exception'}, context=context)
|
||||
return True
|
||||
|
||||
def button_dummy(self, cr, uid, ids, context=None):
|
||||
return True
|
||||
|
||||
|
@ -582,6 +598,10 @@ class purchase_order(osv.osv):
|
|||
return True
|
||||
return False
|
||||
|
||||
def wkf_action_cancel(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
|
||||
self.set_order_line_status(cr, uid, ids, 'cancel', context=context)
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for purchase in self.browse(cr, uid, ids, context=context):
|
||||
|
@ -601,9 +621,8 @@ class purchase_order(osv.osv):
|
|||
wf_service.trg_validate(uid, 'account.invoice', inv.id, 'invoice_cancel', cr)
|
||||
self.pool['purchase.order.line'].write(cr, uid, [l.id for l in purchase.order_line],
|
||||
{'state': 'cancel'})
|
||||
self.write(cr,uid,ids,{'state':'cancel'})
|
||||
|
||||
for (id, name) in self.name_get(cr, uid, ids):
|
||||
for id in ids:
|
||||
wf_service.trg_validate(uid, 'purchase.order', id, 'purchase_cancel', cr)
|
||||
return True
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<field name="name">cancel</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="flow_stop">True</field>
|
||||
<field name="action">write({'state':'cancel'})</field>
|
||||
<field name="action">wkf_action_cancel()</field>
|
||||
</record>
|
||||
<record id="act_except_invoice" model="workflow.activity">
|
||||
<field name="wkf_id" ref="purchase_order"/>
|
||||
|
|
Loading…
Reference in New Issue