Skip to content

Commit

Permalink
fix: stock reservation issue while making Purchase Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Feb 28, 2025
1 parent fcf3749 commit 64985bf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,28 @@ def __init__(
self.new_items_found = False
self.distinct_item_warehouses = args.get("distinct_item_warehouses", frappe._dict())
self.affected_transactions: set[tuple[str, str]] = set()
self.reserved_stock = flt(self.args.reserved_stock)
self.reserved_stock = self.get_reserved_stock()

self.data = frappe._dict()
self.initialize_previous_data(self.args)
self.build()

def get_reserved_stock(self):
sre = frappe.qb.DocType("Stock Reservation Entry")
posting_datetime = get_combine_datetime(self.args.posting_date, self.args.posting_time)
query = (
frappe.qb.from_(sre)
.select(Sum(sre.reserved_qty) - Sum(sre.delivered_qty))
.where(
(sre.item_code == self.item_code)
& (sre.warehouse == self.args.warehouse)
& (sre.docstatus == 1)
& (sre.creation <= posting_datetime)
)
).run()

return flt(query[0][0]) if query else 0.0

def set_precision(self):
self.flt_precision = cint(frappe.db.get_default("float_precision")) or 2
self.currency_precision = get_field_precision(
Expand Down

0 comments on commit 64985bf

Please sign in to comment.