mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-25 13:03:02 +00:00
fix(stock): make Job Card secondary-item query Postgres-valid (GROUP BY)
get_secondary_items_from_job_card selected item_name/description/stock_uom/ bom_secondary_item alongside `group by item_code, secondary_item_type` (and an orderby on the non-grouped idx) -> arbitrary pick on MariaDB, GroupingError on Postgres. Wrap the non-grouped columns in Max() (Min(idx) for the orderby); they are item attributes / the secondary-item BOM link, constant per group, so MariaDB output is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ from collections import defaultdict
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, bold
|
from frappe import _, bold
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Max, Min, Sum
|
||||||
from frappe.utils import ceil, cint, flt, get_link_to_form
|
from frappe.utils import ceil, cint, flt, get_link_to_form
|
||||||
|
|
||||||
from erpnext.manufacturing.doctype.bom.bom import add_additional_cost
|
from erpnext.manufacturing.doctype.bom.bom import add_additional_cost
|
||||||
@@ -1005,11 +1005,14 @@ def get_secondary_items_from_job_card(work_order, jc_name=None):
|
|||||||
.select(
|
.select(
|
||||||
Sum(job_card_secondary_item.stock_qty).as_("stock_qty"),
|
Sum(job_card_secondary_item.stock_qty).as_("stock_qty"),
|
||||||
job_card_secondary_item.item_code,
|
job_card_secondary_item.item_code,
|
||||||
job_card_secondary_item.item_name,
|
# non-grouped columns are item attributes / the secondary-item BOM link, constant per
|
||||||
job_card_secondary_item.description,
|
# grouped (item_code, secondary_item_type) -> Max() keeps the GROUP BY valid on postgres
|
||||||
job_card_secondary_item.stock_uom,
|
# while returning the value MySQL picked arbitrarily.
|
||||||
|
Max(job_card_secondary_item.item_name).as_("item_name"),
|
||||||
|
Max(job_card_secondary_item.description).as_("description"),
|
||||||
|
Max(job_card_secondary_item.stock_uom).as_("stock_uom"),
|
||||||
job_card_secondary_item.secondary_item_type,
|
job_card_secondary_item.secondary_item_type,
|
||||||
job_card_secondary_item.bom_secondary_item,
|
Max(job_card_secondary_item.bom_secondary_item).as_("bom_secondary_item"),
|
||||||
)
|
)
|
||||||
.join(job_card_secondary_item)
|
.join(job_card_secondary_item)
|
||||||
.on(job_card_secondary_item.parent == job_card.name)
|
.on(job_card_secondary_item.parent == job_card.name)
|
||||||
@@ -1019,7 +1022,7 @@ def get_secondary_items_from_job_card(work_order, jc_name=None):
|
|||||||
& (job_card.docstatus == 1)
|
& (job_card.docstatus == 1)
|
||||||
)
|
)
|
||||||
.groupby(job_card_secondary_item.item_code, job_card_secondary_item.secondary_item_type)
|
.groupby(job_card_secondary_item.item_code, job_card_secondary_item.secondary_item_type)
|
||||||
.orderby(job_card_secondary_item.idx)
|
.orderby(Min(job_card_secondary_item.idx))
|
||||||
)
|
)
|
||||||
|
|
||||||
if jc_name:
|
if jc_name:
|
||||||
|
|||||||
Reference in New Issue
Block a user