46
46
picking_obj = self.pool.get('stock.picking')
47
purchase_obj = self.pool.get('purchase.order')
48
pol_obj = self.pool.get('purchase.order.line')
48
50
wf_service = netsvc.LocalService("workflow")
49
51
# depending on the button clicked the behavior is different
61
63
values = {'change_reason': change_reason}
62
64
# update the object
63
65
for obj in picking_obj.browse(cr, uid, picking_ids, context=context):
66
# purchase order line to re-source
65
69
obj.write({'change_reason': change_reason}, context=context)
67
wf_service.trg_validate(uid, 'stock.picking', obj.id, 'button_cancel', cr)
71
for move in obj.move_lines:
72
pol_ids.append(move.purchase_line_id.id)
68
74
# if full cancel (no resource), we updated corresponding out and correct po state
69
75
if cancel_type == 'update_out':
70
76
picking_obj.cancel_and_update_out(cr, uid, [obj.id], context=context)
78
pol_obj.write(cr, uid, pol_ids, {'has_to_be_resourced': True}, context=context)
79
pol_obj.cancel_sol(cr, uid, pol_ids, context=context)
82
wf_service.trg_validate(uid, 'stock.picking', obj.id, 'button_cancel', cr)
84
# correct the corresponding po manually if exists - should be in shipping exception
86
wf_service.trg_validate(uid, 'purchase.order', obj.purchase_id.id, 'picking_ok', cr)
87
purchase_obj.log(cr, uid, obj.purchase_id.id, _('The Purchase Order %s is %s%% received')%(obj.purchase_id.name, round(obj.purchase_id.shipped_rate,2)))
72
89
return {'type': 'ir.actions.act_window_close'}