File tree Expand file tree Collapse file tree
erpnext/stock/doctype/stock_entry Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,9 +278,30 @@ def validate(self):
278278
279279 self .validate_closed_subcontracting_order ()
280280 self .validate_subcontract_order ()
281+ self .validate_raw_materials_exists ()
281282
282283 super ().validate_subcontracting_inward ()
283284
285+ def validate_raw_materials_exists (self ):
286+ if self .purpose not in ["Manufacture" , "Repack" , "Disassemble" ]:
287+ return
288+
289+ if frappe .db .get_single_value ("Manufacturing Settings" , "material_consumption" ):
290+ return
291+
292+ raw_materials = []
293+ for row in self .items :
294+ if row .s_warehouse :
295+ raw_materials .append (row .item_code )
296+
297+ if not raw_materials :
298+ frappe .throw (
299+ _ (
300+ "At least one raw material item must be present in the stock entry for the type {0}"
301+ ).format (bold (self .purpose )),
302+ title = _ ("Raw Materials Missing" ),
303+ )
304+
284305 def set_serial_batch_for_disassembly (self ):
285306 if self .purpose != "Disassemble" :
286307 return
Original file line number Diff line number Diff line change @@ -2362,6 +2362,28 @@ def test_sample_retention_stock_entry(self):
23622362 self .assertEqual (target_sabb .entries [0 ].batch_no , batch )
23632363 self .assertEqual ([entry .serial_no for entry in target_sabb .entries ], serial_nos [:2 ])
23642364
2365+ def test_raw_material_missing_validation (self ):
2366+ original_value = frappe .db .get_single_value ("Manufacturing Settings" , "material_consumption" )
2367+ frappe .db .set_single_value ("Manufacturing Settings" , "material_consumption" , 0 )
2368+
2369+ stock_entry = make_stock_entry (
2370+ item_code = "_Test Item" ,
2371+ qty = 1 ,
2372+ target = "_Test Warehouse - _TC" ,
2373+ do_not_save = True ,
2374+ )
2375+
2376+ stock_entry .purpose = "Manufacture"
2377+ stock_entry .stock_entry_type = "Manufacture"
2378+ stock_entry .items [0 ].is_finished_item = 1
2379+
2380+ self .assertRaises (
2381+ frappe .ValidationError ,
2382+ stock_entry .save ,
2383+ )
2384+
2385+ frappe .db .set_single_value ("Manufacturing Settings" , "material_consumption" , original_value )
2386+
23652387
23662388def make_serialized_item (self , ** args ):
23672389 args = frappe ._dict (args )
You can’t perform that action at this time.
0 commit comments