Skip to content

Commit 81af1fd

Browse files
committed
[MIG] stock_split_picking: Migration to 17.0
1 parent c3e26b3 commit 81af1fd

File tree

6 files changed

+297
-74
lines changed

6 files changed

+297
-74
lines changed

stock_split_picking/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Split picking",
99
"summary": "Split a picking in two not transferred pickings",
10-
"version": "16.0.1.0.3",
10+
"version": "17.0.1.0.0",
1111
"category": "Inventory",
1212
"author": "Camptocamp, "
1313
"Tecnativa, "

stock_split_picking/models/stock_picking.py

+18-21
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def _check_split_process(self):
1616
# Check the picking state and condition before split
1717
if self.state == "draft":
1818
raise UserError(_("Mark as todo this picking please."))
19-
if all([x.qty_done == 0.0 for x in self.move_line_ids]):
19+
if all([x.quantity == 0.0 for x in self.move_line_ids]):
2020
raise UserError(
2121
_(
22-
"You must enter done quantity in order to split your "
22+
"You must enter quantity in order to split your "
2323
"picking in several ones."
2424
)
2525
)
@@ -29,38 +29,29 @@ def split_process(self):
2929
for picking in self:
3030
picking._check_split_process()
3131

32-
# Split moves considering the qty_done on moves
32+
# Split moves considering the quantity on moves
3333
new_moves = self.env["stock.move"]
34+
moves2remove = self.env["stock.move"]
3435
for move in picking.move_ids:
3536
rounding = move.product_uom.rounding
36-
qty_done = move.quantity_done
37+
quantity = move.quantity
3738
qty_initial = move.product_uom_qty
3839
qty_diff_compare = float_compare(
39-
qty_done, qty_initial, precision_rounding=rounding
40+
quantity, qty_initial, precision_rounding=rounding
4041
)
4142
if qty_diff_compare < 0:
42-
qty_split = qty_initial - qty_done
43-
qty_uom_split = move.product_uom._compute_quantity(
44-
qty_split, move.product_id.uom_id, rounding_method="HALF-UP"
45-
)
46-
# Empty list is returned for moves with zero qty_done.
47-
new_move_vals = move._split(qty_uom_split)
43+
qty_split = qty_initial - quantity
44+
# Empty list is returned for moves with zero quantity.
45+
new_move_vals = move._split(qty_split)
4846
if new_move_vals:
49-
for move_line in move.move_line_ids:
50-
if move_line.reserved_qty and move_line.qty_done:
51-
# To avoid an error
52-
# when picking is partially available
53-
try:
54-
move_line.write(
55-
{"reserved_uom_qty": move_line.qty_done}
56-
)
57-
except UserError:
58-
continue
5947
new_move = self.env["stock.move"].create(new_move_vals)
6048
else:
6149
new_move = move
6250
new_move._action_confirm(merge=False)
6351
new_moves |= new_move
52+
# Remove the move if the quantity is 0
53+
if float_compare(quantity, 0, precision_rounding=rounding) == 0:
54+
moves2remove |= move
6455

6556
# If we have new moves to move, create the backorder picking
6657
if new_moves:
@@ -70,6 +61,12 @@ def split_process(self):
7061
{"picking_id": backorder_picking.id}
7162
)
7263
new_moves._action_assign()
64+
for move2remove in moves2remove:
65+
if move2remove.exists():
66+
# You can not delete moves linked to another operation,
67+
# first cancel the move and then delete it.
68+
move2remove._action_cancel()
69+
move2remove.unlink()
7370

7471
def _create_split_backorder(self, default=None):
7572
"""Copy current picking with defaults passed, post message about

0 commit comments

Comments
 (0)