fix: handle negative inventory inside a batch

This commit is contained in:
Ankush Menat 2022-02-19 19:36:28 +05:30 committed by Ankush Menat
parent d7ca83ef0b
commit aba7a7ce4e

View File

@ -742,13 +742,17 @@ class update_entries_after(object):
if actual_qty > 0:
stock_value_difference = incoming_rate * actual_qty
self.wh_data.stock_value += stock_value_difference
else:
outgoing_rate = get_batch_incoming_rate(item_code=sle.item_code, warehouse=sle.warehouse, batch_no=sle.batch_no, posting_date=sle.posting_date, posting_time=sle.posting_time, creation=sle.creation)
# TODO: negative stock handling
if outgoing_rate is None:
# This can *only* happen if qty available for the batch is zero.
# in such case fall back various other rates.
# future entries will correct the overall accounting as each
# batch individually uses moving average rates.
outgoing_rate = self.get_fallback_rate(sle)
stock_value_difference = outgoing_rate * actual_qty
self.wh_data.stock_value += stock_value_difference
self.wh_data.stock_value += stock_value_difference
if self.wh_data.qty_after_transaction:
self.wh_data.valuation_rate = self.wh_data.stock_value / self.wh_data.qty_after_transaction