@@ -20,13 +20,14 @@ def _get_qty_done_by_product_lot(self, moves):
20
20
("move_id.scrapped" , "=" , False ),
21
21
],
22
22
["qty_done:sum" ],
23
- ["product_id" , "lot_id" ],
23
+ ["product_id" , "lot_id" , "move_id" ],
24
24
lazy = False ,
25
25
):
26
+ move_id = group .get ("move_id" )[0 ] if group .get ("move_id" ) else False
26
27
lot_id = group .get ("lot_id" )[0 ] if group .get ("lot_id" ) else False
27
28
product_id = group .get ("product_id" )[0 ]
28
29
qty_done = group .get ("qty_done" )
29
- res [(product_id , lot_id )] += qty_done
30
+ res [(product_id , move_id , lot_id )] += qty_done
30
31
return res
31
32
32
33
def prepare_sale_rma_data (self ):
@@ -38,19 +39,16 @@ def prepare_sale_rma_data(self):
38
39
moves = self .get_delivery_move ()
39
40
data = []
40
41
qty_done_by_product_lot = self ._get_qty_done_by_product_lot (moves )
41
- for (product_id , lot_id ), qty_done in qty_done_by_product_lot .items ():
42
+ for (product_id , move_id , lot_id ), qty_done in qty_done_by_product_lot .items ():
42
43
data .append (
43
- self ._prepare_sale_rma_data_line (moves , product_id , lot_id , qty_done )
44
+ self ._prepare_sale_rma_data_line (move_id , product_id , lot_id , qty_done )
44
45
)
45
46
return data
46
47
47
- def _prepare_sale_rma_data_line (self , moves , product_id , lot_id , qty_done ):
48
- moves = moves .move_line_ids .filtered (
49
- lambda ml , p_id = product_id , l_id = lot_id : ml .product_id .id == p_id
50
- and ml .lot_id .id == l_id
51
- ).move_id
48
+ def _prepare_sale_rma_data_line (self , move_id , product_id , lot_id , qty_done ):
49
+ move = self .env ["stock.move" ].browse (move_id )
52
50
quantity = qty_done
53
- for returned_move in moves .returned_move_ids .filtered (
51
+ for returned_move in move .returned_move_ids .filtered (
54
52
lambda r : r .state in ["partially_available" , "assigned" , "done" ]
55
53
):
56
54
if (
@@ -63,13 +61,14 @@ def _prepare_sale_rma_data_line(self, moves, product_id, lot_id, qty_done):
63
61
elif returned_move .state == "done" :
64
62
quantity -= returned_move .product_qty
65
63
quantity = float_round (
66
- quantity , precision_rounding = moves .product_id .uom_id .rounding
64
+ quantity , precision_rounding = move .product_id .uom_id .rounding
67
65
)
68
66
return {
69
- "product" : moves .product_id ,
67
+ "product" : move .product_id ,
70
68
"quantity" : quantity ,
71
- "uom" : moves .product_uom ,
72
- "picking" : moves .picking_id [ 0 ] ,
69
+ "uom" : move .product_uom ,
70
+ "picking" : move .picking_id ,
73
71
"sale_line_id" : self ,
74
72
"lot_id" : lot_id ,
73
+ "move" : move ,
75
74
}
0 commit comments