~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to purchase_override/purchase.py

  • Committer: jf
  • Date: 2014-03-31 15:54:36 UTC
  • mfrom: (1994.19.8 uftp-82)
  • Revision ID: jfb@tempo-consulting.fr-20140331155436-4985vmglk95lbeak
Tags: pilot3.0b2, ref.week13
UFTP-82 [FIX] IR and FO content blanked after PO cancellation
lp:~unifield-team/unifield-wm/uftp-82

Show diffs side-by-side

added added

removed removed

Lines of Context:
1771
1771
                        wf_service.trg_write(uid, 'stock.picking', line.procurement_id.move_id.picking_id.id, cr)
1772
1772
 
1773
1773
        self.pool.get('purchase.order.line').cancel_sol(cr, uid, line_ids, context=context)
1774
 
 
1775
1774
        return self.write(cr, uid, ids, {'state':'cancel'}, context=context)
1776
1775
 
1777
1776
    def wkf_confirm_cancel(self, cr, uid, ids, context=None):
2213
2212
            # erase default code
2214
2213
            vals.update({'default_code':False})
2215
2214
            vals.update({'default_name':False})
2216
 
            
 
2215
 
2217
2216
            if 'comment' in vals:
2218
2217
                vals.update({'name':vals['comment']})
2219
2218
        # clear nomenclature filter values
2499
2498
            ids = [ids]
2500
2499
 
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)
2510
2518
 
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']
 
2523
 
 
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):
 
2529
                # new IR state:
 
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
 
2532
                # else NO CHANGE
 
2533
                ir_new_state = 'cancel'
 
2534
                lines_to_cancel_ids = []
 
2535
                all_lines_resourced = True
 
2536
                one_line_not_cancelled = False
 
2537
 
 
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'
 
2555
 
 
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'},
 
2559
                        context=context)
 
2560
                if ir_new_state:
 
2561
                    self.pool.get('sale.order').write(cr, uid, ir.id,
 
2562
                        {'state':  ir_new_state}, context=context)
2513
2563
 
2514
2564
        return True
2515
2565