From b811dba5c269a53ed50cc43f2e340f223173ba67 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sat, 20 Jun 2026 19:42:03 +0530 Subject: [PATCH] fix(stock): aggregate non-grouped cols in get_items_to_be_repost (PG #39) get_items_to_be_repost selected posting_date/posting_time/creation/posting_datetime alongside `group_by item_code, warehouse` with no aggregation -> arbitrary pick on MariaDB, GroupingError on Postgres. Wrap the four columns in `Min()` (earliest row per item+warehouse, the correct repost-start point; a single voucher's SLEs share posting_date/time per group -> MariaDB-identical). This is reached by every stock transaction submit/cancel via repost_future_sle_and_gle, so it unblocks the whole transaction-heavy stock suite on Postgres (e.g. test_purchase_receipt 105/105). Co-Authored-By: Claude Opus 4.8 (1M context) --- erpnext/stock/stock_ledger.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 91c9a36ee77..99dd4ae675f 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -381,7 +381,16 @@ def get_items_to_be_repost(voucher_type=None, voucher_no=None, doc=None, reposti items_to_be_repost = frappe.db.get_all( "Stock Ledger Entry", filters={"voucher_type": voucher_type, "voucher_no": voucher_no}, - fields=["item_code", "warehouse", "posting_date", "posting_time", "creation", "posting_datetime"], + fields=[ + "item_code", + "warehouse", + # aggregate the non-grouped columns (earliest row per item+warehouse) so the GROUP BY + # is valid on Postgres; a single voucher's entries share posting_date/time per group + {"MIN": "posting_date", "as": "posting_date"}, + {"MIN": "posting_time", "as": "posting_time"}, + {"MIN": "creation", "as": "creation"}, + {"MIN": "posting_datetime", "as": "posting_datetime"}, + ], order_by="creation asc", group_by="item_code, warehouse", )