From 8092d58d9c36d263a2218fa7b4e95636706faf77 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:15:46 +0530 Subject: [PATCH] fix: do not validate qc for scrap item (backport #44844) (#44853) fix: do not validate qc for scrap item (#44844) (cherry picked from commit a2c2b8b5ad1b9d991b5c5380860e271a01ab012f) Co-authored-by: rohitwaghchaure --- erpnext/controllers/stock_controller.py | 3 + .../doctype/stock_entry/test_stock_entry.py | 74 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index c1cb83657da..34556f725d4 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -999,6 +999,9 @@ class StockController(AccountsController): elif self.doctype == "Stock Entry" and row.t_warehouse: qi_required = True # inward stock needs inspection + if row.get("is_scrap_item"): + continue + if qi_required: # validate row only if inspection is required on item level self.validate_qi_presence(row) if self.docstatus == 1: diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index a26940462bf..05661d3a83a 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -970,6 +970,80 @@ class TestStockEntry(FrappeTestCase): self.assertRaises(frappe.ValidationError, ste.submit) + def test_quality_check_for_scrap_item(self): + from erpnext.manufacturing.doctype.work_order.work_order import ( + make_stock_entry as _make_stock_entry, + ) + + scrap_item = "_Test Scrap Item 1" + make_item(scrap_item, {"is_stock_item": 1, "is_purchase_item": 0}) + + bom_name = frappe.db.get_value("BOM Scrap Item", {"docstatus": 1}, "parent") + production_item = frappe.db.get_value("BOM", bom_name, "item") + + work_order = frappe.new_doc("Work Order") + work_order.production_item = production_item + work_order.update( + { + "company": "_Test Company", + "fg_warehouse": "_Test Warehouse 1 - _TC", + "production_item": production_item, + "bom_no": bom_name, + "qty": 1.0, + "stock_uom": frappe.db.get_value("Item", production_item, "stock_uom"), + "skip_transfer": 1, + } + ) + + work_order.get_items_and_operations_from_bom() + work_order.submit() + + stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Manufacture", 1)) + for row in stock_entry.items: + if row.s_warehouse: + make_stock_entry( + item_code=row.item_code, + target=row.s_warehouse, + qty=row.qty, + basic_rate=row.basic_rate or 100, + ) + + if row.is_scrap_item: + row.item_code = scrap_item + row.uom = frappe.db.get_value("Item", scrap_item, "stock_uom") + row.stock_uom = frappe.db.get_value("Item", scrap_item, "stock_uom") + + stock_entry.inspection_required = 1 + stock_entry.save() + + self.assertTrue([row.item_code for row in stock_entry.items if row.is_scrap_item]) + + for row in stock_entry.items: + if not row.is_scrap_item: + qc = frappe.get_doc( + { + "doctype": "Quality Inspection", + "reference_name": stock_entry.name, + "inspected_by": "Administrator", + "reference_type": "Stock Entry", + "inspection_type": "In Process", + "status": "Accepted", + "sample_size": 1, + "item_code": row.item_code, + } + ) + + qc_name = qc.submit() + row.quality_inspection = qc_name + + stock_entry.reload() + stock_entry.submit() + for row in stock_entry.items: + if row.is_scrap_item: + self.assertFalse(row.quality_inspection) + else: + self.assertTrue(row.quality_inspection) + def test_quality_check(self): item_code = "_Test Item For QC" if not frappe.db.exists("Item", item_code):