mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-12 17:23:38 +00:00
fix: negative stock issue for higher precision
This commit is contained in:
@@ -2789,6 +2789,23 @@ class TestDeliveryNote(IntegrationTestCase):
|
||||
serial_batch_map[row.item_code].batch_no_valuation[entry.batch_no],
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
@@ -1176,7 +1176,11 @@ class update_entries_after:
|
||||
diff = self.wh_data.qty_after_transaction + flt(sle.actual_qty) - flt(self.reserved_stock)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user