Skip to content

Commit beabbb1

Browse files
Merge pull request #51900 from rohitwaghchaure/fixed-github-49961
fix: validation to check at-least one raw material for manufacture entry
2 parents 65c3020 + f003b3c commit beabbb1

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

erpnext/stock/doctype/stock_entry/stock_entry.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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

erpnext/stock/doctype/stock_entry/test_stock_entry.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,28 @@ def test_sample_retention_stock_entry(self):
23612361
self.assertEqual(target_sabb.entries[0].batch_no, batch)
23622362
self.assertEqual([entry.serial_no for entry in target_sabb.entries], serial_nos[:2])
23632363

2364+
def test_raw_material_missing_validation(self):
2365+
original_value = frappe.db.get_single_value("Manufacturing Settings", "material_consumption")
2366+
frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 0)
2367+
2368+
stock_entry = make_stock_entry(
2369+
item_code="_Test Item",
2370+
qty=1,
2371+
target="_Test Warehouse - _TC",
2372+
do_not_save=True,
2373+
)
2374+
2375+
stock_entry.purpose = "Manufacture"
2376+
stock_entry.stock_entry_type = "Manufacture"
2377+
stock_entry.items[0].is_finished_item = 1
2378+
2379+
self.assertRaises(
2380+
frappe.ValidationError,
2381+
stock_entry.save,
2382+
)
2383+
2384+
frappe.db.set_single_value("Manufacturing Settings", "material_consumption", original_value)
2385+
23642386

23652387
def make_serialized_item(self, **args):
23662388
args = frappe._dict(args)

0 commit comments

Comments
 (0)