From 81a0709dbdf320cbbc4e6a37a47f680f87ccb9df Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 21 Jun 2026 14:56:29 +0530 Subject: [PATCH] fix(stock): make get_incoming_value_for_serial_nos a staticmethod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It never references `self`. The deterministic-serial-value test added in #56249 called it as `get_incoming_value_for_serial_nos(None, sle, serial_nos)` — passing None for self, which is fragile: a future `self.*` access would fail with an opaque AttributeError. Declaring it @staticmethod makes the call honest (`get_incoming_value_for_serial_nos(sle, serial_nos)`) and is backward compatible — the method has no in-repo callers besides that test, and any `self.`-style call still binds correctly to a staticmethod. Addresses Greptile review feedback on #56249. --- .../doctype/stock_ledger_entry/test_stock_ledger_entry.py | 2 +- erpnext/stock/stock_ledger.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 57d1b32d978..a3905e0f4d8 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -77,7 +77,7 @@ class TestStockLedgerEntry(ERPNextTestSuite, StockTestMixin): mk_sle("MAT-SLE-TIE-B", 200) # later/larger name -> deterministic winner value = update_entries_after.get_incoming_value_for_serial_nos( - None, frappe._dict(company=company_a), [serial] + frappe._dict(company=company_a), [serial] ) # the latest (creation/name desc) same-date SLE wins -> 200 on both engines self.assertEqual(value, 200.0) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index f34b176b6cc..cfbcf779df9 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1473,7 +1473,8 @@ class update_entries_after: for item in sr.items: item.db_update() - def get_incoming_value_for_serial_nos(self, sle, serial_nos): + @staticmethod + def get_incoming_value_for_serial_nos(sle, serial_nos): # get rate from serial nos within same company all_serial_nos = frappe.get_all( "Serial No", fields=["purchase_rate", "name", "company"], filters={"name": ("in", serial_nos)}