mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-19 01:18:43 +00:00
_get_avg_valuation_rate_from_bins divides Sum(stock_value) by Sum(actual_qty). The `Count(name) > 0` guard only proves a Bin row exists; Sum(actual_qty) can still be 0 (stock depleted, or per-warehouse quantities cancelling out), and the outer IfNull catches only NULL, not a 0 divisor. MariaDB returns NULL for x/0 (then IfNull -> 0.0); PostgreSQL raises `division by zero` and aborts BOM costing. Wrapping the divisor in NullIf(Sum(actual_qty), 0) keeps the identical 0.0 result on MariaDB and avoids the error on PostgreSQL.
Plan and manage manufacturing operations, bill of materials for manufacturing.