mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-26 14:41:42 +01:00
Merge pull request #53135 from frappe/mergify/bp/version-15-hotfix/pr-53132
fix(selling): handle selling price validation for FG item (backport #53132)
This commit is contained in:
@@ -318,9 +318,10 @@ class SellingController(StockController):
|
||||
if is_internal_customer or not is_stock_item:
|
||||
continue
|
||||
|
||||
if item.get("incoming_rate") and item.base_net_rate < (
|
||||
rate_field = "valuation_rate" if self.doctype in ["Sales Order", "Quotation"] else "incoming_rate"
|
||||
if item.get(rate_field) and item.base_net_rate < (
|
||||
valuation_rate := flt(
|
||||
item.incoming_rate * (item.conversion_factor or 1), item.precision("base_net_rate")
|
||||
item.get(rate_field) * (item.conversion_factor or 1), item.precision("base_net_rate")
|
||||
)
|
||||
):
|
||||
throw_message(
|
||||
|
||||
@@ -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")):
|
||||
|
||||
Reference in New Issue
Block a user