From 334f1cc6f0f7e59210e1440da08809cd369ac617 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 23 Jun 2026 18:41:22 +0530 Subject: [PATCH] fix(stock): guard incorrect-serial valuation-rate division against a zero qty (Postgres) The Incorrect Serial No Valuation report computes stock_value_difference / actual_qty for every matching Stock Ledger Entry. A valuation-only Stock Reconciliation of serialized/batched stock writes an SLE with actual_qty = 0 and a non-zero stock_value_difference, and the or_filters (serial_no / serial_and_batch_bundle set) do not exclude it. MariaDB returns NULL for x/0; PostgreSQL raises `division by zero` and aborts the report. Using the get_all nested NULLIF form {"DIV": ["stock_value_difference", {"NULLIF": ["actual_qty", 0]}]} yields NULL on both engines, leaving MariaDB output unchanged. --- .../incorrect_serial_no_valuation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.py b/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.py index 101b6a21461..c7a256c7c57 100644 --- a/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.py +++ b/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.py @@ -115,7 +115,7 @@ def get_stock_ledger_entries(report_filters): "posting_time", "company", "warehouse", - {"DIV": ["stock_value_difference", "actual_qty"], "as": "valuation_rate"}, + {"DIV": ["stock_value_difference", {"NULLIF": ["actual_qty", 0]}], "as": "valuation_rate"}, ] filters = {"is_cancelled": 0}