Skip to content

Commit

Permalink
fix: negative stock error
Browse files Browse the repository at this point in the history
(cherry picked from commit 6d513e2)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Feb 4, 2023
1 parent 6df730c commit e0cd6c2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def update_bin(self):
frappe.db.set_value("Bin", bin_name, updated_values, update_modified=True)


def get_previous_sle_of_current_voucher(args, exclude_current_voucher=False):
def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_voucher=False):
"""get stock ledger entries filtered by specific posting datetime conditions"""

args["time_format"] = "%H:%i:%s"
Expand All @@ -1076,13 +1076,13 @@ def get_previous_sle_of_current_voucher(args, exclude_current_voucher=False):
posting_date < %(posting_date)s or
(
posting_date = %(posting_date)s and
time_format(posting_time, %(time_format)s) < time_format(%(posting_time)s, %(time_format)s)
time_format(posting_time, %(time_format)s) {operator} time_format(%(posting_time)s, %(time_format)s)
)
)
order by timestamp(posting_date, posting_time) desc, creation desc
limit 1
for update""".format(
voucher_condition=voucher_condition
operator=operator, voucher_condition=voucher_condition
),
args,
as_dict=1,
Expand Down Expand Up @@ -1375,7 +1375,7 @@ def get_stock_reco_qty_shift(args):
stock_reco_qty_shift = flt(args.actual_qty)
else:
# reco is being submitted
last_balance = get_previous_sle_of_current_voucher(args, exclude_current_voucher=True).get(
last_balance = get_previous_sle_of_current_voucher(args, "<=", exclude_current_voucher=True).get(
"qty_after_transaction"
)

Expand Down

0 comments on commit e0cd6c2

Please sign in to comment.