mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-23 12:06:43 +00:00
fix(stock): make pick_list link query valid on Postgres (GROUP BY joined column)
get_pick_list_query selects Sales Order.customer (a joined table's column) while grouping only by Pick List.name. Postgres' functional-dependency relaxation applies to a table's own primary key, not to a joined table's columns, so the query raises GroupingError on Postgres. MariaDB arbitrary-picks and runs. customer is already pinned to a single value by `WHERE Sales Order.customer = filter`, so adding it to the GROUP BY is identical on MariaDB and valid on Postgres. Test (errors with GroupingError on the old code on Postgres, passes on both engines): - test_get_pick_list_query_postgres_valid: a submitted pick list for a customer is returned by the link query. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1372,7 +1372,10 @@ def get_pick_list_query(doctype: Any, txt: str, searchfield: Any, start: int, pa
|
||||
.where(PICK_LIST.status.isin(["Open", "Partly Delivered"]))
|
||||
.where(PICK_LIST.company == filters.get("company"))
|
||||
.where(SALES_ORDER.customer == filters.get("customer"))
|
||||
.groupby(PICK_LIST.name)
|
||||
# customer is from the joined Sales Order, not Pick List's PK, so Postgres rejects it as a bare
|
||||
# select under GROUP BY pick_list.name; it is pinned to one value by the filter above, so adding
|
||||
# it to the GROUP BY is valid on Postgres and identical on MariaDB.
|
||||
.groupby(PICK_LIST.name, SALES_ORDER.customer)
|
||||
)
|
||||
|
||||
if filters.get("sales_order"):
|
||||
|
||||
@@ -1964,3 +1964,23 @@ class TestPickList(ERPNextTestSuite):
|
||||
item_codes = [item.item_code for item in doc.items]
|
||||
self.assertIn(item1, item_codes)
|
||||
self.assertIn(item2, item_codes)
|
||||
|
||||
def test_get_pick_list_query_postgres_valid(self):
|
||||
"""get_pick_list_query selects Sales Order.customer (a joined-table column) under
|
||||
GROUP BY Pick List.name. Postgres rejects that bare column (PK functional dependency does
|
||||
not cross tables), so the link query raised GroupingError. customer is pinned to one value
|
||||
by the filter, so adding it to the GROUP BY is identical on MariaDB and valid on Postgres."""
|
||||
from erpnext.stock.doctype.pick_list.pick_list import get_pick_list_query
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
item = make_item().name
|
||||
make_stock_entry(item=item, to_warehouse=warehouse, qty=100, basic_rate=100)
|
||||
so = make_sales_order(item_code=item, qty=5, rate=100)
|
||||
pl = create_pick_list(so.name)
|
||||
pl.submit()
|
||||
|
||||
# must run without raising on either engine (GroupingError on Postgres before the fix)
|
||||
result = get_pick_list_query(
|
||||
"Pick List", "", "name", 0, 20, {"company": so.company, "customer": so.customer}
|
||||
)
|
||||
self.assertIn(pl.name, [row["name"] for row in result])
|
||||
|
||||
Reference in New Issue
Block a user