1771
1771
wf_service.trg_write(uid, 'stock.picking', line.procurement_id.move_id.picking_id.id, cr)
1773
1773
self.pool.get('purchase.order.line').cancel_sol(cr, uid, line_ids, context=context)
1775
1774
return self.write(cr, uid, ids, {'state':'cancel'}, context=context)
1777
1776
def wkf_confirm_cancel(self, cr, uid, ids, context=None):
2501
2500
sol_to_update = {}
2501
sol_not_to_delete_ids = []
2502
ir_to_potentialy_cancel_ids = []
2503
sol_of_po_line_resourced_ids = []
2502
2504
for line in self.browse(cr, uid, ids, context=context):
2503
2505
sol_ids = self.get_sol_ids_from_pol_ids(cr, uid, [line.id], context=context)
2504
2506
for sol in sol_obj.browse(cr, uid, sol_ids, context=context):
2507
2509
sol_to_update[sol.id] += diff_qty
2508
2510
if line.has_to_be_resourced:
2509
2511
sol_obj.add_resource_line(cr, uid, sol, False, diff_qty, context=context)
2512
sol_of_po_line_resourced_ids.append(sol.id)
2513
if sol.order_id.procurement_request:
2514
# UFTP-82: do not delete IR line, cancel it
2515
sol_not_to_delete_ids.append(sol.id)
2516
if sol.order_id.id not in ir_to_potentialy_cancel_ids:
2517
ir_to_potentialy_cancel_ids.append(sol.order_id.id)
2511
2519
for sol in sol_to_update:
2520
context['update_or_cancel_line_not_delete'] = sol in sol_not_to_delete_ids
2512
2521
sol_obj.update_or_cancel_line(cr, uid, sol, sol_to_update[sol], context=context)
2522
del context['update_or_cancel_line_not_delete']
2524
# UFTP-82: IR and its PO is cancelled
2525
# IR cancel all lines that have to be cancelled
2526
# and cancel IR if all its lines cancelled
2527
if ir_to_potentialy_cancel_ids:
2528
for ir in self.pool.get('sale.order').browse(cr, uid, ir_to_potentialy_cancel_ids, context=context):
2530
# we change his state to 'cancel' if at least one line cancelled
2531
# we change his state to 'done' if all lines cancelled and resourced
2533
ir_new_state = 'cancel'
2534
lines_to_cancel_ids = []
2535
all_lines_resourced = True
2536
one_line_not_cancelled = False
2538
# check if at least one line is cancelled
2539
# or all lines cancel and resourced
2540
for irl in ir.order_line:
2541
line_cancelled = False
2542
if ir.is_ir_from_po_cancel and \
2543
(irl.state == 'cancel' or irl.state == 'exception'):
2544
# note PO sourced from IR, IR cancelled line can be in 'exception' as a 'cancelled' one
2545
line_cancelled = True
2546
if irl.id not in sol_of_po_line_resourced_ids:
2547
all_lines_resourced = False # one cancelled line not resourced
2548
if irl.state == 'exception':
2549
lines_to_cancel_ids.append(irl.id) # to be set to cancel
2550
if not line_cancelled:
2551
ir_new_state = False # no cancelled line left, then no change
2552
if ir_new_state and all_lines_resourced:
2553
# 'state change' flaged and all line resourced, state to done
2554
ir_new_state = 'done'
2556
if lines_to_cancel_ids:
2557
self.pool.get('sale.order.line').write(cr, uid, lines_to_cancel_ids,
2558
{'state': ir_new_state if ir_new_state else 'cancel'},
2561
self.pool.get('sale.order').write(cr, uid, ir.id,
2562
{'state': ir_new_state}, context=context)