@@ -8,7 +8,7 @@ def setUpClass(cls):
88 super ().setUpClass ()
99
1010 cls .partner = cls .env ["res.partner" ].create (
11- {"name" : "Test Devaluation Customer" , "customer_rank" : 1 }
11+ {"name" : "Test Devaluation Customer" }
1212 )
1313 cls .pricelist = cls .env ["product.pricelist" ].create (
1414 {"name" : "Test Devaluation Pricelist" }
@@ -26,10 +26,8 @@ def setUpClass(cls):
2626 cls .stock_location = cls .env .ref ("stock.stock_location_stock" )
2727 cls .customer_location = cls .env .ref ("stock.stock_location_customers" )
2828 cls .picking_type_out = cls .env .ref ("stock.picking_type_out" )
29- cls .picking_type_in = cls .env .ref ("stock.picking_type_in" )
3029 cls .uom_unit = cls .env .ref ("uom.product_uom_unit" )
3130
32- # Ensure stock availability
3331 cls .env ["stock.quant" ].with_context (inventory_mode = True ).create (
3432 {
3533 "product_id" : cls .product .id ,
@@ -67,19 +65,36 @@ def _create_outgoing_picking(self, qty=5.0):
6765 return picking
6866
6967 def _create_return (self , picking , qty ):
70- """Create a return for a picking using the stock return wizard."""
71- return_wizard = (
72- self .env ["stock.return.picking" ]
73- .with_context (active_id = picking .id , active_model = "stock.picking" )
74- .create ({})
68+ """Create a return for a picking manually linking returned moves."""
69+ return_type = picking .picking_type_id .return_picking_type_id or (
70+ picking .picking_type_id
7571 )
76- for line in return_wizard .product_return_moves :
77- if line .product_id == self .product :
78- line .quantity = qty
79- result = return_wizard .create_returns ()
80- return_picking = self .env ["stock.picking" ].browse (result ["res_id" ])
72+ return_picking = self .env ["stock.picking" ].create (
73+ {
74+ "partner_id" : picking .partner_id .id ,
75+ "picking_type_id" : return_type .id ,
76+ "location_id" : picking .location_dest_id .id ,
77+ "location_dest_id" : picking .location_id .id ,
78+ "origin" : "Return of %s" % picking .name ,
79+ }
80+ )
81+ original_move = picking .move_ids [0 ]
82+ self .env ["stock.move" ].create (
83+ {
84+ "name" : "Return of %s" % original_move .name ,
85+ "product_id" : self .product .id ,
86+ "product_uom_qty" : qty ,
87+ "product_uom" : self .uom_unit .id ,
88+ "picking_id" : return_picking .id ,
89+ "location_id" : picking .location_dest_id .id ,
90+ "location_dest_id" : picking .location_id .id ,
91+ "origin_returned_move_id" : original_move .id ,
92+ }
93+ )
94+ return_picking .action_confirm ()
95+ return_picking .action_assign ()
8196 for ml in return_picking .move_line_ids :
82- ml .qty_done = qty
97+ ml .qty_done = ml . reserved_uom_qty or qty
8398 return_picking ._action_done ()
8499 return return_picking
85100
0 commit comments