Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore Stock Reservation for future dated PR (backport #37979) #37990

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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