Merge lp:~unifield-team/unifield-server/us1294-sync-split-ship-IN into lp:unifield-server

Proposed by Quentin THEURET @Amaris
Status: Merged
Merged at revision: 3802
Proposed branch: lp:~unifield-team/unifield-server/us1294-sync-split-ship-IN
Merge into: lp:unifield-server
Diff against target: 102 lines (+43/-4)
1 file modified
bin/addons/sync_so/picking.py (+43/-4)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us1294-sync-split-ship-IN
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+295949@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/sync_so/picking.py'
2--- bin/addons/sync_so/picking.py 2016-05-24 08:26:21 +0000
3+++ bin/addons/sync_so/picking.py 2016-05-27 12:59:48 +0000
4@@ -202,6 +202,20 @@
5 context.update({'for_dpo': True})
6 return self.partial_shipped_fo_updates_in_po(cr, uid, source, out_info, context=context)
7
8+
9+ # US-1294: Add the shipped amount into the move lines
10+ def _add_to_shipped_moves(self, already_shipped_moves, move_id, quantity):
11+ found = False
12+ for elem in already_shipped_moves:
13+ if move_id in elem:
14+ # If the move line exists, then add the new shipped amount into line
15+ elem[move_id] += quantity
16+ found = True
17+ break
18+
19+ if not found:
20+ already_shipped_moves.append({move_id: quantity})
21+
22 def partial_shipped_fo_updates_in_po(self, cr, uid, source, out_info, context=None):
23 '''
24 ' This sync method is used for updating the IN of Project side when the OUT/PICK at Coordo side became done.
25@@ -269,6 +283,8 @@
26 for line in pack_data:
27 line_data = pack_data[line]
28
29+ #US-1294: Keep this list of pair (move_line: shipped_qty) as amount already shipped
30+ already_shipped_moves = []
31 # get the corresponding picking line ids
32 for data in line_data['data']:
33 ln = data.get('line_number')
34@@ -296,17 +312,31 @@
35
36 move_ids = move_obj.search(cr, uid, search_move, context=context)
37 if not move_ids:
38+ #US-1294: Reduce the search condition
39 del search_move[0]
40 move_ids = move_obj.search(cr, uid, search_move, context=context)
41
42+ #US-1294: If there is only one move line found, must check if this has already all taken in shipped moves list
43+ if move_ids and len(move_ids) == 1: # if there is only one move, take it for process
44+ move = move_obj.read(cr, uid, move_ids[0], ['product_qty'], context=context)
45+ for elem in already_shipped_moves:
46+ # If this move has already all shipped, do not take it anymore
47+ if move['id'] in elem and move['product_qty'] == elem[move['id']]:
48+ move_ids = False # search again
49+ break
50+
51 if not move_ids and original_qty_partial != -1:
52+ #US-1294: Reduce the search condition
53 search_move = [('picking_id', '=', in_id), ('line_number', '=', data.get('line_number')), ('original_qty_partial', '=', original_qty_partial)]
54 move_ids = move_obj.search(cr, uid, search_move, context=context)
55-
56+
57+ #US-1294: But still no move line with exact qty as the amount shipped
58 if not move_ids:
59+ #US-1294: Now search all moves of the given IN and line number
60 search_move = [('picking_id', '=', in_id), ('line_number', '=', data.get('line_number'))]
61- move_ids = move_obj.search(cr, uid, search_move, context=context)
62+ move_ids = move_obj.search(cr, uid, search_move, order='product_qty ASC', context=context)
63 if not move_ids:
64+ #US-1294: absolutely no moves -> probably they are closed, just show the error message then ignore
65 closed_in_id = so_po_common.get_in_id_by_state(cr, uid, po_id, po_name, ['done', 'cancel'], context)
66 if closed_in_id:
67 search_move = [('picking_id', '=', closed_in_id), ('line_number', '=', data.get('line_number'))]
68@@ -333,8 +363,15 @@
69 ('wizard_id', '=', in_processor),
70 ('move_id', '=', move['id']),
71 ], context=context)
72- if not line_proc_ids:
73+ if line_proc_ids:
74 diff = move['product_qty'] - orig_qty
75+ # US-1294: If the same move has already been chosen in the previous round, then the shipped amount must be taken into account
76+ for elem in already_shipped_moves:
77+ if move['id'] in elem:
78+ # taken into account the amount already shipped previously
79+ diff -= elem[move['id']]
80+ break
81+
82 if diff >= 0 and (not best_diff or diff < best_diff):
83 best_diff = diff
84 move_id = move['id']
85@@ -361,7 +398,7 @@
86 already_set_moves.append(move_id)
87 if not line_proc_ids:
88 data['ordered_quantity'] = data['quantity']
89- self.pool.get('stock.move.in.processor').create(cr, uid, data, context=context)
90+ move_proc.create(cr, uid, data, context=context)
91 else:
92 for line in move_proc.browse(cr, uid, line_proc_ids, context=context):
93 if line.product_id.id == data.get('product_id') and \
94@@ -373,6 +410,8 @@
95 else:
96 data['ordered_quantity'] = data['quantity']
97 move_proc.create(cr, uid, data, context=context)
98+ #US-1294: Add this move and quantity as already shipped, since it's added to the wizard for processing
99+ self._add_to_shipped_moves(already_shipped_moves, move_id, data['quantity'])
100
101 # for the last Shipment of an FO, no new INcoming shipment will be created --> same value as in_id
102 new_picking = self.do_incoming_shipment(cr, uid, in_processor, context)

Subscribers

People subscribed via source and target branches

to all changes: