diff --git a/stock/stock_ledger.py b/stock/stock_ledger.py index f0619c7384d..0e8a341a4cd 100644 --- a/stock/stock_ledger.py +++ b/stock/stock_ledger.py @@ -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) @@ -140,10 +142,12 @@ def validate_negative_stock(qty_after_transaction, sle): will not consider cancelled entries """ 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 @@ -277,4 +281,4 @@ def get_previous_sle(args, for_update=False): sle = get_stock_ledger_entries(args, ["name != %(sle)s", "timestamp(posting_date, posting_time) <= timestamp(%(posting_date)s, %(posting_time)s)"], "desc", "limit 1", for_update=for_update) - return sle and sle[0] or {} \ No newline at end of file + return sle and sle[0] or {}