fix: round computed conversion factors to field precision

The inverse (1 / value) and intermediate-UOM branches of
get_uom_conv_factor returned raw float quotients like
0.4535922921968971, bypassing the precision the docfields now declare.
Same for the client-side back-calculation from an edited stock qty.
Round both to the UOM Conversion Factor value precision.

(cherry picked from commit ca5a673409)
This commit is contained in:
Mihir Kandoi
2026-08-07 17:47:50 +05:30
committed by Mergify
parent db49b03913
commit 206ed28924
2 changed files with 6 additions and 3 deletions

View File

@@ -1771,7 +1771,10 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
let item = frappe.get_doc(cdt, cdn);
item.conversion_factor = 1.0;
if (item.stock_qty) {
item.conversion_factor = flt(item.stock_qty) / flt(item.qty);
item.conversion_factor = flt(
flt(item.stock_qty) / flt(item.qty),
precision("conversion_factor", item)
);
}
refresh_field("conversion_factor", item.name, item.parentfield);

View File

@@ -1472,7 +1472,7 @@ def get_uom_conv_factor(uom, stock_uom):
"UOM Conversion Factor", {"to_uom": from_uom, "from_uom": to_uom}, ["value"], as_dict=1
)
if inverse_match:
return 1 / inverse_match.value
return flt(1 / inverse_match.value, frappe.get_precision("UOM Conversion Factor", "value"))
# This attempts to try and get conversion from intermediate UOM.
# case:
@@ -1495,7 +1495,7 @@ def get_uom_conv_factor(uom, stock_uom):
)
if intermediate_match:
return intermediate_match[0].value
return flt(intermediate_match[0].value, frappe.get_precision("UOM Conversion Factor", "value"))
@frappe.whitelist()