fix: Maintain same rate in Stock Ledger until stock become positive (#27227) (#27478)

* fix: Maintain same rate in Stock Ledger until stock become positive

* fix: Maintain same rate in Stock Ledger until stock become positive

(cherry picked from commit 10754831c33b3459d5a45c98f875afa48a444627)

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
Frappe PR Bot 2021-09-15 17:07:58 +05:30 committed by GitHub
parent c5a77f60ed
commit d4d5e2786f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -681,11 +681,15 @@ class update_entries_after(object):
if self.wh_data.stock_queue[-1][1]==incoming_rate: if self.wh_data.stock_queue[-1][1]==incoming_rate:
self.wh_data.stock_queue[-1][0] += actual_qty self.wh_data.stock_queue[-1][0] += actual_qty
else: else:
# Item has a positive balance qty, add new entry
if self.wh_data.stock_queue[-1][0] > 0: if self.wh_data.stock_queue[-1][0] > 0:
self.wh_data.stock_queue.append([actual_qty, incoming_rate]) self.wh_data.stock_queue.append([actual_qty, incoming_rate])
else: else: # negative balance qty
qty = self.wh_data.stock_queue[-1][0] + actual_qty qty = self.wh_data.stock_queue[-1][0] + actual_qty
if qty > 0: # new balance qty is positive
self.wh_data.stock_queue[-1] = [qty, incoming_rate] self.wh_data.stock_queue[-1] = [qty, incoming_rate]
else: # new balance qty is still negative, maintain same rate
self.wh_data.stock_queue[-1][0] = qty
else: else:
qty_to_pop = abs(actual_qty) qty_to_pop = abs(actual_qty)
while qty_to_pop: while qty_to_pop: