@@ -211,6 +211,7 @@ def test_pick_list_shows_serial_no_for_serialized_item(self):
211211 "qty" : 1000 ,
212212 "stock_qty" : 1000 ,
213213 "conversion_factor" : 1 ,
214+ "warehouse" : "_Test Warehouse - _TC" ,
214215 "sales_order" : so .name ,
215216 "sales_order_item" : so .items [0 ].name ,
216217 }
@@ -268,6 +269,119 @@ def test_pick_list_shows_batch_no_for_batched_item(self):
268269 pr1 .cancel ()
269270 pr2 .cancel ()
270271
272+ def test_pick_list_warehouse_for_batched_item (self ):
273+ """
274+ Test that pick list respects company based warehouse assignment for batched items.
275+
276+ This test verifies that when creating a pick list for a batched item,
277+ the system correctly identifies and assigns the appropriate warehouse
278+ based on the company.
279+ """
280+ from erpnext .stock .doctype .batch .test_batch import make_new_batch
281+
282+ batch_company = frappe .get_doc (
283+ {"doctype" : "Company" , "company_name" : "Batch Company" , "default_currency" : "INR" }
284+ )
285+ batch_company .insert ()
286+
287+ batch_warehouse = frappe .get_doc (
288+ {
289+ "doctype" : "Warehouse" ,
290+ "warehouse_name" : "Batch Warehouse" ,
291+ "company" : batch_company .name ,
292+ }
293+ )
294+ batch_warehouse .insert ()
295+
296+ batch_item = frappe .db .exists ("Item" , "Batch Warehouse Item" )
297+ if not batch_item :
298+ batch_item = create_item ("Batch Warehouse Item" )
299+ batch_item .has_batch_no = 1
300+ batch_item .create_new_batch = 1
301+ batch_item .save ()
302+ else :
303+ batch_item = frappe .get_doc ("Item" , "Batch Warehouse Item" )
304+
305+ batch_no = make_new_batch (item_code = batch_item .name , batch_id = "B-WH-ITEM-001" )
306+
307+ make_stock_entry (
308+ item_code = batch_item .name ,
309+ qty = 5 ,
310+ company = batch_company .name ,
311+ to_warehouse = batch_warehouse .name ,
312+ batch_no = batch_no .name ,
313+ rate = 100.0 ,
314+ )
315+ make_stock_entry (
316+ item_code = batch_item .name ,
317+ qty = 5 ,
318+ to_warehouse = "_Test Warehouse - _TC" ,
319+ batch_no = batch_no .name ,
320+ rate = 100.0 ,
321+ )
322+
323+ pick_list = frappe .get_doc (
324+ {
325+ "doctype" : "Pick List" ,
326+ "company" : batch_company .name ,
327+ "purpose" : "Material Transfer" ,
328+ "locations" : [
329+ {
330+ "item_code" : batch_item .name ,
331+ "qty" : 10 ,
332+ "stock_qty" : 10 ,
333+ "conversion_factor" : 1 ,
334+ }
335+ ],
336+ }
337+ )
338+
339+ pick_list .set_item_locations ()
340+ self .assertEqual (len (pick_list .locations ), 1 )
341+ self .assertEqual (pick_list .locations [0 ].qty , 5 )
342+ self .assertEqual (pick_list .locations [0 ].batch_no , batch_no .name )
343+ self .assertEqual (pick_list .locations [0 ].warehouse , batch_warehouse .name )
344+
345+ def test_pick_list_warehouse_validation (self ):
346+ """check if the warehouse validations are triggered"""
347+ from erpnext .stock .doctype .pick_list .pick_list import (
348+ IncorrectWarehouseValidationError ,
349+ MissingWarehouseValidationError ,
350+ )
351+
352+ warehouse_item = create_item ("Warehouse Item" )
353+ temp_company = frappe .get_doc (
354+ {"doctype" : "Company" , "company_name" : "Temp Company" , "default_currency" : "INR" }
355+ ).insert ()
356+ temp_warehouse = frappe .get_doc (
357+ {"doctype" : "Warehouse" , "warehouse_name" : "Temp Warehouse" , "company" : temp_company .name }
358+ ).insert ()
359+
360+ make_stock_entry (item_code = warehouse_item .name , qty = 10 , rate = 100.0 , to_warehouse = temp_warehouse .name )
361+
362+ pick_list = frappe .get_doc (
363+ {
364+ "doctype" : "Pick List" ,
365+ "company" : temp_company .name ,
366+ "purpose" : "Material Transfer" ,
367+ "pick_manually" : 1 ,
368+ "locations" : [
369+ {
370+ "item_code" : warehouse_item .name ,
371+ "qty" : 5 ,
372+ "stock_qty" : 5 ,
373+ "conversion_factor" : 1 ,
374+ }
375+ ],
376+ }
377+ )
378+
379+ self .assertRaises (MissingWarehouseValidationError , pick_list .insert )
380+ pick_list .locations [0 ].warehouse = "_Test Warehouse - _TC"
381+ self .assertRaises (IncorrectWarehouseValidationError , pick_list .insert )
382+ pick_list .locations [0 ].warehouse = temp_warehouse .name
383+ pick_list .insert ()
384+
271385 def test_pick_list_for_batched_and_serialised_item (self ):
272386 # check if oldest batch no and serial nos are picked
273387 item = frappe .db .exists ("Item" , {"item_name" : "Batched and Serialised Item" })
0 commit comments