From b5aee6a9cda2eac395efdb26f83b684b9ac14721 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 5 Jul 2026 15:10:17 +0530 Subject: [PATCH] fix(buying): show earliest schedule date as required date When a Material Request lists the same item on multiple rows, the consolidated row showed Max(schedule_date), understating urgency. Use Min - the earliest date the item is needed. --- .../requested_items_to_order_and_receive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.py b/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.py index b6f9bb13795..d1d9bd8266c 100644 --- a/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.py +++ b/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.py @@ -6,7 +6,7 @@ import copy import frappe from frappe import _ -from frappe.query_builder.functions import Coalesce, Max, Sum +from frappe.query_builder.functions import Coalesce, Max, Min, Sum from frappe.utils import cint, date_diff, flt, getdate @@ -47,7 +47,7 @@ def get_data(filters): # non-grouped columns are constant per grouped mr.name / item_code -> Max() keeps the # GROUP BY valid on postgres while returning the same value MySQL picked. Max(mr.transaction_date).as_("date"), - Max(mr_item.schedule_date).as_("required_date"), + Min(mr_item.schedule_date).as_("required_date"), mr_item.item_code.as_("item_code"), Sum(Coalesce(mr_item.qty, 0)).as_("qty"), Sum(Coalesce(mr_item.stock_qty, 0)).as_("stock_qty"),