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.
This commit is contained in:
Mihir Kandoi
2026-06-23 18:41:22 +05:30
parent d48396cb11
commit 334f1cc6f0

View File

@@ -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}