@@ -16,10 +16,10 @@ def _check_split_process(self):
16
16
# Check the picking state and condition before split
17
17
if self .state == "draft" :
18
18
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 ]):
20
20
raise UserError (
21
21
_ (
22
- "You must enter done quantity in order to split your "
22
+ "You must enter quantity in order to split your "
23
23
"picking in several ones."
24
24
)
25
25
)
@@ -29,38 +29,29 @@ def split_process(self):
29
29
for picking in self :
30
30
picking ._check_split_process ()
31
31
32
- # Split moves considering the qty_done on moves
32
+ # Split moves considering the quantity on moves
33
33
new_moves = self .env ["stock.move" ]
34
+ moves2remove = self .env ["stock.move" ]
34
35
for move in picking .move_ids :
35
36
rounding = move .product_uom .rounding
36
- qty_done = move .quantity_done
37
+ quantity = move .quantity
37
38
qty_initial = move .product_uom_qty
38
39
qty_diff_compare = float_compare (
39
- qty_done , qty_initial , precision_rounding = rounding
40
+ quantity , qty_initial , precision_rounding = rounding
40
41
)
41
42
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 )
48
46
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
59
47
new_move = self .env ["stock.move" ].create (new_move_vals )
60
48
else :
61
49
new_move = move
62
50
new_move ._action_confirm (merge = False )
63
51
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
64
55
65
56
# If we have new moves to move, create the backorder picking
66
57
if new_moves :
@@ -70,6 +61,12 @@ def split_process(self):
70
61
{"picking_id" : backorder_picking .id }
71
62
)
72
63
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 ()
73
70
74
71
def _create_split_backorder (self , default = None ):
75
72
"""Copy current picking with defaults passed, post message about
0 commit comments