mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-09 08:02:51 +00:00
refactor stock ledger to be thread safe
This commit is contained in:
@@ -10,7 +10,9 @@ import json
|
||||
# future reposting
|
||||
class NegativeStockError(webnotes.ValidationError): pass
|
||||
|
||||
_exceptions = []
|
||||
_exceptions = webnotes.local('stockledger_exceptions')
|
||||
|
||||
# _exceptions = []
|
||||
def update_entries_after(args, verbose=1):
|
||||
"""
|
||||
update valution rate and qty after transaction
|
||||
@@ -23,8 +25,8 @@ def update_entries_after(args, verbose=1):
|
||||
"posting_time": "12:00"
|
||||
}
|
||||
"""
|
||||
global _exceptions
|
||||
_exceptions = []
|
||||
if not _exceptions:
|
||||
webnotes.local.stockledger_exceptions = []
|
||||
|
||||
previous_sle = get_sle_before_datetime(args)
|
||||
|
||||
@@ -141,9 +143,11 @@ def validate_negative_stock(qty_after_transaction, sle):
|
||||
"""
|
||||
diff = qty_after_transaction + flt(sle.actual_qty)
|
||||
|
||||
if not _exceptions:
|
||||
webnotes.local.stockledger_exceptions = []
|
||||
|
||||
if diff < 0 and abs(diff) > 0.0001:
|
||||
# negative stock!
|
||||
global _exceptions
|
||||
exc = sle.copy().update({"diff": diff})
|
||||
_exceptions.append(exc)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user