fix: address review comments

- restore mutated SLE after test via addCleanup
- explicit return False in has_difference
- comment the fifo_stock_diff guard for non-queue predecessors

(cherry picked from commit ef5f47fafd)
This commit is contained in:
Mihir Kandoi
2026-07-03 11:39:51 +05:30
committed by Mergify
parent 3571512101
commit 056195ce07
3 changed files with 10 additions and 0 deletions

View File

@@ -128,6 +128,7 @@ def add_fifo_fields(sle, prev_sle):
sle.fifo_valuation_diff = (
sle.valuation_rate - sle.fifo_valuation_rate if sle.fifo_valuation_rate else None
)
# prev row may not maintain a queue; H and H - F stay blank across the gap
if prev_sle and prev_sle.fifo_stock_value is not None:
sle.fifo_stock_diff = sle.fifo_stock_value - prev_sle.fifo_stock_value
sle.fifo_difference_diff = sle.fifo_stock_diff - sle.stock_value_difference

View File

@@ -51,6 +51,13 @@ class TestStockLedgerInvariantCheck(ERPNextTestSuite):
sle = frappe.get_last_doc(
"Stock Ledger Entry", {"item_code": item, "warehouse": WAREHOUSE, "is_cancelled": 0}
)
self.addCleanup(
frappe.db.set_value,
"Stock Ledger Entry",
sle.name,
"qty_after_transaction",
sle.qty_after_transaction,
)
frappe.db.set_value(
"Stock Ledger Entry", sle.name, "qty_after_transaction", sle.qty_after_transaction + 5
)

View File

@@ -297,3 +297,5 @@ def has_difference(row, float_precision, currency_precision, difference_in, valu
return True
elif difference_in not in ["Qty", "Value", "Valuation"] and (qty_diff or value_diff or valuation_diff):
return True
return False