From 04fd425fb65a772038f46fc2f047564331b55627 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 26 Jun 2026 13:27:43 +0530 Subject: [PATCH] test: reuse BootStrapTestData master data to reduce runtime Co-Authored-By: Claude Opus 4.8 (1M context) --- .../test_purchase_receipt_trends.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/erpnext/stock/report/purchase_receipt_trends/test_purchase_receipt_trends.py b/erpnext/stock/report/purchase_receipt_trends/test_purchase_receipt_trends.py index 87511222754..bd11379ec29 100644 --- a/erpnext/stock/report/purchase_receipt_trends/test_purchase_receipt_trends.py +++ b/erpnext/stock/report/purchase_receipt_trends/test_purchase_receipt_trends.py @@ -3,7 +3,6 @@ import frappe -from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt from erpnext.stock.report.purchase_receipt_trends.purchase_receipt_trends import execute from erpnext.tests.utils import ERPNextTestSuite @@ -23,18 +22,25 @@ class TestPurchaseReceiptTrends(ERPNextTestSuite): filters.update(extra) return execute(filters)[1] + def get_item_totals(self, data, item): + # Row layout for based_on="Item", Yearly, no group_by: + # [item_code, item_name, currency, FY(Qty), FY(Amt), Total(Qty), Total(Amt)] + row = next((r for r in data if r[0] == item), None) + if row is None: + return 0, 0 + return row[3], row[4] + def test_receipt_qty_in_trend(self): - item = make_item(properties={"is_stock_item": 1, "is_purchase_item": 1}).name + item = "_Test Item" + + # The report sums ALL purchase receipts for the item in the fiscal year, so capture + # any pre-existing committed baseline and assert only this receipt's contribution. + base_qty, base_amt = self.get_item_totals(self.run_report(), item) + make_purchase_receipt( item_code=item, qty=10, rate=100, company="_Test Company", posting_date="2026-06-01" ) - data = self.run_report() - - # Row layout for based_on="Item", Yearly, no group_by: - # [item_code, item_name, currency, FY(Qty), FY(Amt), Total(Qty), Total(Amt)] - row = next(r for r in data if r[0] == item) - self.assertEqual(row[3], 10) # fiscal-year qty - self.assertEqual(row[4], 1000) # fiscal-year amount (10 * 100) - self.assertEqual(row[5], 10) # Total(Qty) - self.assertEqual(row[6], 1000) # Total(Amt) + qty, amt = self.get_item_totals(self.run_report(), item) + self.assertEqual(qty - base_qty, 10) # fiscal-year qty + self.assertEqual(amt - base_amt, 1000) # fiscal-year amount (10 * 100)