mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 22:51:49 +00:00
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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user