test: strengthen price_per_unit assertion, drop no-op quotation guard

This commit is contained in:
Nabin Hait
2026-07-02 23:29:48 +05:30
parent 2a8d26c0a7
commit 0ba43a17c1

View File

@@ -14,7 +14,10 @@ class TestSupplierQuotationComparison(ERPNextTestSuite):
"""The report lists Supplier Quotation item lines so quotes for the same item can """The report lists Supplier Quotation item lines so quotes for the same item can
be compared across suppliers.""" be compared across suppliers."""
def make_quotation(self, supplier, qty, rate): def make_quotation(self, supplier, qty, rate, uom=None):
item = {"item_code": ITEM, "qty": qty, "rate": rate, "warehouse": "_Test Warehouse - _TC"}
if uom:
item["uom"] = uom
sq = frappe.get_doc( sq = frappe.get_doc(
{ {
"doctype": "Supplier Quotation", "doctype": "Supplier Quotation",
@@ -22,9 +25,7 @@ class TestSupplierQuotationComparison(ERPNextTestSuite):
"company": COMPANY, "company": COMPANY,
"currency": "INR", "currency": "INR",
"transaction_date": "2026-06-01", "transaction_date": "2026-06-01",
"items": [ "items": [item],
{"item_code": ITEM, "qty": qty, "rate": rate, "warehouse": "_Test Warehouse - _TC"}
],
} }
) )
sq.insert() sq.insert()
@@ -40,7 +41,9 @@ class TestSupplierQuotationComparison(ERPNextTestSuite):
self.assertEqual(execute(None)[1], []) self.assertEqual(execute(None)[1], [])
def test_quotation_line_listed_with_price(self): def test_quotation_line_listed_with_price(self):
sq = self.make_quotation("_Test Supplier", qty=10, rate=100) # _Test UOM 1 converts at 10 stock units per qty, so price_per_unit
# (amount / stock_qty) diverges from base_rate and the division path is tested
sq = self.make_quotation("_Test Supplier", qty=10, rate=100, uom="_Test UOM 1")
rows = [r for r in self.run_report(item_code=ITEM) if r.get("quotation") == sq.name] rows = [r for r in self.run_report(item_code=ITEM) if r.get("quotation") == sq.name]
self.assertTrue(rows, "Supplier Quotation line missing from report") self.assertTrue(rows, "Supplier Quotation line missing from report")
@@ -49,13 +52,14 @@ class TestSupplierQuotationComparison(ERPNextTestSuite):
self.assertEqual(row["qty"], 10) self.assertEqual(row["qty"], 10)
self.assertEqual(row["base_rate"], 100) self.assertEqual(row["base_rate"], 100)
self.assertEqual(row["base_amount"], 1000) self.assertEqual(row["base_amount"], 1000)
self.assertEqual(row["price_per_unit"], 100) # 1000 amount / (10 qty * 10 conversion) = 10, distinct from the 100 base_rate
self.assertEqual(row["price_per_unit"], 10)
def test_compares_multiple_suppliers_for_item(self): def test_compares_multiple_suppliers_for_item(self):
sq1 = self.make_quotation("_Test Supplier", qty=10, rate=100) sq1 = self.make_quotation("_Test Supplier", qty=10, rate=100)
sq2 = self.make_quotation("_Test Supplier 1", qty=10, rate=120) sq2 = self.make_quotation("_Test Supplier 1", qty=10, rate=120)
quotes = {r["quotation"]: r for r in self.run_report(item_code=ITEM) if r.get("quotation")} quotes = {r["quotation"]: r for r in self.run_report(item_code=ITEM)}
self.assertIn(sq1.name, quotes) self.assertIn(sq1.name, quotes)
self.assertIn(sq2.name, quotes) self.assertIn(sq2.name, quotes)
self.assertEqual(quotes[sq1.name]["base_rate"], 100) self.assertEqual(quotes[sq1.name]["base_rate"], 100)