From dced21faf29523dd2c94b4bc5d6e79764509b581 Mon Sep 17 00:00:00 2001 From: kavin-114 Date: Tue, 3 Mar 2026 20:33:55 +0530 Subject: [PATCH] test: add unit test for FG Item selling price validation (cherry picked from commit 723993fdf69aaed40d8bcf24f40f3aef7de04d6d) --- .../doctype/sales_order/test_sales_order.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index cff84411231..4fffd1f801e 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -2472,6 +2472,49 @@ class TestSalesOrder(AccountsTestMixin, FrappeTestCase): si2 = make_sales_invoice(so.name) self.assertEqual(si2.items[0].qty, 20) + @change_settings("Selling Settings", {"validate_selling_price": 1}) + def test_selling_price_validation_for_manufactured_item(self): + """ + Unit test to check the selling price validation for manufactured item, without last purchae rate in Item master. + """ + + from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom + from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse + + # create a FG Item and RM Item + rm_item = make_item( + "_Test RM Item for SO selling validation", + {"is_stock_item": 1, "valuation_rate": 100, "stock_uom": "Nos"}, + ).name + rm_warehouse = create_warehouse("_Test RM SPV Warehouse") + fg_item = make_item("_Test FG Item for SO selling validation", {"is_stock_item": 1}).name + fg_warehouse = create_warehouse("_Test FG SPV Warehouse") + + # create BOM and inward entry for RM Item + bom_no = make_bom(item=fg_item, raw_materials=[rm_item]).name + make_stock_entry(item_code=rm_item, target=rm_warehouse, qty=10, rate=100) + + # create a manufacture entry, so system won't update the last purchase rate in Item master. + se = make_stock_entry(item_code=fg_item, qty=10, purpose="Manufacture", do_not_save=True) + + se.from_bom = 1 + se.use_multi_level_bom = 1 + se.bom_no = bom_no + se.fg_completed_qty = 1 + se.from_warehouse = rm_warehouse + se.to_warehouse = fg_warehouse + + se.get_items() + se.save() + se.submit() + + # check valuation of FG Item + self.assertEqual(se.items[1].valuation_rate, 100) + + # create a SO for FG Item with selling rate than valuation rate. + so = make_sales_order(item_code=fg_item, qty=10, rate=50, warehouse=fg_warehouse, do_not_save=1) + self.assertRaises(frappe.ValidationError, so.save) + def compare_payment_schedules(doc, doc1, doc2): for index, schedule in enumerate(doc1.get("payment_schedule")):