Skip to content

Commit

Permalink
fix: ignore Stock Reservation for future dated PR (backport #37979) (#…
Browse files Browse the repository at this point in the history
…37990)

fix: ignore Stock Reservation for future dated PR

(cherry picked from commit 33eedb9)

Co-authored-by: s-aga-r <[email protected]>
  • Loading branch information
mergify[bot] and s-aga-r authored Nov 8, 2023
1 parent 0e979b6 commit d74f0ef
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from frappe.desk.notifications import clear_doctype_notifications
from frappe.model.mapper import get_mapped_doc
from frappe.query_builder.functions import CombineDatetime
from frappe.utils import cint, flt, getdate, nowdate
from frappe.utils import cint, flt, get_datetime, getdate, nowdate
from pypika import functions as fn

import erpnext
Expand Down Expand Up @@ -829,8 +829,12 @@ def update_billing_status(self, update_modified=True):
update_billing_percentage(pr_doc, update_modified=update_modified)

def reserve_stock_for_sales_order(self):
if self.is_return or not cint(
frappe.db.get_single_value("Stock Settings", "auto_reserve_stock_for_sales_order_on_purchase")
if (
self.is_return
or not frappe.db.get_single_value("Stock Settings", "enable_stock_reservation")
or not frappe.db.get_single_value(
"Stock Settings", "auto_reserve_stock_for_sales_order_on_purchase"
)
):
return

Expand All @@ -851,6 +855,11 @@ def reserve_stock_for_sales_order(self):
so_items_details_map.setdefault(item.sales_order, []).append(item_details)

if so_items_details_map:
if get_datetime("{} {}".format(self.posting_date, self.posting_time)) > get_datetime():
return frappe.msgprint(
_("Cannot create Stock Reservation Entries for future dated Purchase Receipts.")
)

for so, items_details in so_items_details_map.items():
so_doc = frappe.get_doc("Sales Order", so)
so_doc.create_stock_reservation_entries(
Expand Down

0 comments on commit d74f0ef

Please sign in to comment.