fix(edi): make Common Code docname lookup valid on Postgres

get_docnames_for issued SELECT DISTINCT on Dynamic Link.link_name while ordering by Dynamic Link.idx, a column absent from the select list. This is a raw frappe.qb query (run via .run(), not get_all/get_list), so the ORDER BY is emitted verbatim and PostgreSQL rejects it: 'for SELECT DISTINCT, ORDER BY expressions must appear in select list'. Order by link_name (the selected, distinct column) instead; same docnames on both engines, now deterministically ordered.
This commit is contained in:
Mihir Kandoi
2026-06-23 09:13:49 +05:30
parent ff737df55f
commit 9f1915800f

View File

@@ -116,7 +116,7 @@ def get_docnames_for(code_list: str, doctype: str, code: str) -> tuple[str]:
& (CommonCode.code_list == code_list)
)
.distinct()
.orderby(DynamicLink.idx)
.orderby(DynamicLink.link_name)
).run()
return tuple(d[0] for d in docnames) if docnames else ()