mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-14 23:18:40 +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.
(cherry picked from commit ca5a673409)
This commit is contained in:
@@ -1771,7 +1771,10 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
let item = frappe.get_doc(cdt, cdn);
|
let item = frappe.get_doc(cdt, cdn);
|
||||||
item.conversion_factor = 1.0;
|
item.conversion_factor = 1.0;
|
||||||
if (item.stock_qty) {
|
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);
|
refresh_field("conversion_factor", item.name, item.parentfield);
|
||||||
|
|||||||
@@ -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
|
"UOM Conversion Factor", {"to_uom": from_uom, "from_uom": to_uom}, ["value"], as_dict=1
|
||||||
)
|
)
|
||||||
if inverse_match:
|
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.
|
# This attempts to try and get conversion from intermediate UOM.
|
||||||
# case:
|
# case:
|
||||||
@@ -1495,7 +1495,7 @@ def get_uom_conv_factor(uom, stock_uom):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if intermediate_match:
|
if intermediate_match:
|
||||||
return intermediate_match[0].value
|
return flt(intermediate_match[0].value, frappe.get_precision("UOM Conversion Factor", "value"))
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
Reference in New Issue
Block a user