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) <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-06-20 19:42:03 +05:30
parent afb7c25141
commit b811dba5c2

View File

@@ -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",
)