mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 13:49:13 +00:00
refactor stock ledger to be thread safe
This commit is contained in:
@@ -10,7 +10,9 @@ import json
|
|||||||
# future reposting
|
# future reposting
|
||||||
class NegativeStockError(webnotes.ValidationError): pass
|
class NegativeStockError(webnotes.ValidationError): pass
|
||||||
|
|
||||||
_exceptions = []
|
_exceptions = webnotes.local('stockledger_exceptions')
|
||||||
|
|
||||||
|
# _exceptions = []
|
||||||
def update_entries_after(args, verbose=1):
|
def update_entries_after(args, verbose=1):
|
||||||
"""
|
"""
|
||||||
update valution rate and qty after transaction
|
update valution rate and qty after transaction
|
||||||
@@ -23,8 +25,8 @@ def update_entries_after(args, verbose=1):
|
|||||||
"posting_time": "12:00"
|
"posting_time": "12:00"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
global _exceptions
|
if not _exceptions:
|
||||||
_exceptions = []
|
webnotes.local.stockledger_exceptions = []
|
||||||
|
|
||||||
previous_sle = get_sle_before_datetime(args)
|
previous_sle = get_sle_before_datetime(args)
|
||||||
|
|
||||||
@@ -140,10 +142,12 @@ def validate_negative_stock(qty_after_transaction, sle):
|
|||||||
will not consider cancelled entries
|
will not consider cancelled entries
|
||||||
"""
|
"""
|
||||||
diff = qty_after_transaction + flt(sle.actual_qty)
|
diff = qty_after_transaction + flt(sle.actual_qty)
|
||||||
|
|
||||||
|
if not _exceptions:
|
||||||
|
webnotes.local.stockledger_exceptions = []
|
||||||
|
|
||||||
if diff < 0 and abs(diff) > 0.0001:
|
if diff < 0 and abs(diff) > 0.0001:
|
||||||
# negative stock!
|
# negative stock!
|
||||||
global _exceptions
|
|
||||||
exc = sle.copy().update({"diff": diff})
|
exc = sle.copy().update({"diff": diff})
|
||||||
_exceptions.append(exc)
|
_exceptions.append(exc)
|
||||||
return False
|
return False
|
||||||
@@ -277,4 +281,4 @@ def get_previous_sle(args, for_update=False):
|
|||||||
sle = get_stock_ledger_entries(args, ["name != %(sle)s",
|
sle = get_stock_ledger_entries(args, ["name != %(sle)s",
|
||||||
"timestamp(posting_date, posting_time) <= timestamp(%(posting_date)s, %(posting_time)s)"],
|
"timestamp(posting_date, posting_time) <= timestamp(%(posting_date)s, %(posting_time)s)"],
|
||||||
"desc", "limit 1", for_update=for_update)
|
"desc", "limit 1", for_update=for_update)
|
||||||
return sle and sle[0] or {}
|
return sle and sle[0] or {}
|
||||||
|
|||||||
Reference in New Issue
Block a user