@@ -329,11 +329,114 @@ def test_available_on_one_stock_location_with_shelf(self):
329329
330330 # We are in shelf context
331331 self .template .invalidate_recordset ()
332+ self .template .product_variant_ids .invalidate_recordset ()
333+ self .template .with_context (
334+ location = self .shelf .id
335+ )._compute_available_quantities_dict ()
336+ self .assertEqual (
337+ 15.0 ,
338+ self .template .with_context (location = self .shelf .id ).quantity_to_replenish ,
339+ )
332340 templates = self .template .with_context (location = self .shelf .id ).search (
333- [("quantity_to_replenish" , "=" , 5 .0 )]
341+ [("quantity_to_replenish" , "=" , 15 .0 )]
334342 )
335343 self .assertTrue (self .template .id in templates .ids )
336344
345+ def test_available_on_different_sublocation (self ):
346+ """
347+ Remove the existing orderpoints
348+
349+ Create a location structure like:
350+ - Stock
351+ - Area 1
352+ - Shelf 1
353+ - Area 2
354+ - Shelf 2
355+
356+ Create orderpoints for both areas.
357+
358+ Create ougoing moves for both shelves:
359+ - Shelf 1: 12.0
360+ - Shelf 2: 2.0
361+
362+ Global quantity to replenish should be 8.0
363+
364+ Quantity for Shelf 1 should be 6.0
365+
366+ """
367+ # Archive orderpoints
368+ self .env ["stock.location.orderpoint" ].search ([]).write ({"active" : False })
369+
370+ self .area_1 = self .env ["stock.location" ].create (
371+ {
372+ "name" : "Area 1" ,
373+ "location_id" : self .location_dest .id ,
374+ "usage" : "view" ,
375+ }
376+ )
377+
378+ self .shelf_1 = self .env ["stock.location" ].create (
379+ {"name" : "Shelf 1" , "location_id" : self .area_1 .id }
380+ )
381+
382+ self .area_2 = self .env ["stock.location" ].create (
383+ {
384+ "name" : "Area 2" ,
385+ "location_id" : self .location_dest .id ,
386+ "usage" : "view" ,
387+ }
388+ )
389+
390+ self .shelf_2 = self .env ["stock.location" ].create (
391+ {"name" : "Shelf 1" , "location_id" : self .area_2 .id }
392+ )
393+
394+ # Create an orderpoint by shelf
395+ self .location_dest = self .area_1
396+ (
397+ self .orderpoint_shelf_1 ,
398+ self .location_src_shelf_1 ,
399+ ) = self ._create_orderpoint_complete ("Area 1 Replenishment" , trigger = "manual" )
400+
401+ self .location_dest = self .area_2
402+ (
403+ self .orderpoint_shelf_2 ,
404+ self .location_src_shelf_2 ,
405+ ) = self ._create_orderpoint_complete ("Area 2 Replenishment" , trigger = "manual" )
406+
407+ # Set stock on replenishment locations
408+ self .env ["stock.quant" ].with_context (inventory_mode = True ).create (
409+ {
410+ "inventory_quantity" : 6.0 ,
411+ "location_id" : self .location_src_shelf_1 .id ,
412+ "product_id" : self .product .id ,
413+ }
414+ )._apply_inventory ()
415+ self .env ["stock.quant" ].with_context (inventory_mode = True ).create (
416+ {
417+ "inventory_quantity" : 4.0 ,
418+ "location_id" : self .location_src_shelf_2 .id ,
419+ "product_id" : self .product .id ,
420+ }
421+ )._apply_inventory ()
422+
423+ self .location_dest = self .shelf_1
424+ move = self ._create_outgoing_move (12 )
425+ self .assertEqual (move .state , "confirmed" )
426+
427+ self .location_dest = self .shelf_2
428+ move = self ._create_outgoing_move (2 )
429+ self .assertEqual (move .state , "confirmed" )
430+
431+ self .template .invalidate_recordset ()
432+ self .assertEqual (8.0 , self .template .quantity_to_replenish )
433+
434+ self .template .invalidate_recordset ()
435+ self .assertEqual (
436+ 6.0 ,
437+ self .template .with_context (location = self .shelf_1 .id ).quantity_to_replenish ,
438+ )
439+
337440 def test_action (self ):
338441 action = self .template .action_open_replenishments ()
339442 self .assertIn (
0 commit comments