Merge pull request #51591 from frappe/mergify/bp/version-14-hotfix/pr-51588

fix: negative stock issue for higher precision (backport #51586) (backport #51588)
This commit is contained in:
rohitwaghchaure
2026-01-08 16:11:20 +05:30
committed by GitHub
2 changed files with 22 additions and 1 deletions

View File

@@ -1507,6 +1507,23 @@ class TestDeliveryNote(FrappeTestCase):
self.assertEqual(stock_value_difference, 100.0 * 5)
def test_negative_stock_with_higher_precision(self):
original_flt_precision = frappe.db.get_default("float_precision")
frappe.db.set_single_value("System Settings", "float_precision", 7)
item_code = make_item(
"Test Negative Stock High Precision Item", properties={"is_stock_item": 1, "valuation_rate": 1}
).name
dn = create_delivery_note(
item_code=item_code,
qty=0.0000010,
do_not_submit=True,
)
self.assertRaises(frappe.ValidationError, dn.submit)
frappe.db.set_single_value("System Settings", "float_precision", original_flt_precision)
def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")

View File

@@ -715,7 +715,11 @@ class update_entries_after:
diff = self.wh_data.qty_after_transaction + flt(sle.actual_qty)
diff = flt(diff, self.flt_precision) # respect system precision
if diff < 0 and abs(diff) > 0.0001:
diff_threshold = 0.0001
if self.flt_precision > 4:
diff_threshold = 10 ** (-1 * self.flt_precision)
if diff < 0 and abs(diff) > diff_threshold:
# negative stock!
exc = sle.copy().update({"diff": diff})
self.exceptions.setdefault(sle.warehouse, []).append(exc)