fix: ignore Stock Reservation for future dated PR
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index cbc1693..d905fe5 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -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
@@ -760,8 +760,12 @@
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
@@ -782,6 +786,11 @@
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(