From bbe7580c9d5e5027f1a7ef51138260d9afc351e5 Mon Sep 17 00:00:00 2001 From: pandiyan Date: Thu, 23 Jul 2026 17:43:57 +0530 Subject: [PATCH] fix: typeerror in get_batches_by_oldest for mixed batch expiry sort on (expiry is none, expiry) so a null expiry_date is never order-compared against a datetime.date, which raised typeerror in python 3 when a warehouse held both dated and never-expiring batches. (cherry picked from commit 62c9f8ee3e7f8a6452f4bab9e5cc58f699f41e2d) --- erpnext/stock/doctype/batch/batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 5b8f9eade10..dc73e9ffddf 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -296,7 +296,7 @@ def get_batches_by_oldest(item_code, warehouse): """Returns the oldest batch and qty for the given item_code and warehouse""" batches = get_batch_qty(item_code=item_code, warehouse=warehouse) batches_dates = [[batch, frappe.get_value("Batch", batch.batch_no, "expiry_date")] for batch in batches] - batches_dates.sort(key=lambda tup: tup[1]) + batches_dates.sort(key=lambda tup: (tup[1] is None, tup[1])) return batches_dates