refactor stock ledger to be thread safe

This commit is contained in:
Pratik Vyas
2013-09-18 18:31:03 +05:30
parent 5e16a69b35
commit 16371b7212

View File

@@ -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)
@@ -141,9 +143,11 @@ def validate_negative_stock(qty_after_transaction, sle):
""" """
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