mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-11 05:31:48 +00:00
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.
This commit is contained in:
@@ -1802,7 +1802,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);
|
||||
|
||||
@@ -1508,7 +1508,7 @@ def get_uom_conv_factor(uom: str | None, stock_uom: str | None):
|
||||
"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:
|
||||
@@ -1528,7 +1528,7 @@ def get_uom_conv_factor(uom: str | None, stock_uom: str | None):
|
||||
)
|
||||
|
||||
if intermediate_match:
|
||||
return intermediate_match[0].value
|
||||
return flt(intermediate_match[0].value, frappe.get_precision("UOM Conversion Factor", "value"))
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
||||
Reference in New Issue
Block a user