fix: manufacture entry with group_by support

(cherry picked from commit 3cf1ce8360)

# Conflicts:
#	erpnext/stock/doctype/stock_entry/stock_entry.py
This commit is contained in:
vorasmit
2026-04-01 23:42:36 +05:30
committed by Mergify
parent 20f81516cf
commit 841b507502

View File

@@ -2226,6 +2226,7 @@ class StockEntry(StockController):
# Finished goods
self.load_items_from_bom()
<<<<<<< HEAD
<<<<<<< HEAD
def get_items_from_manufacture_entry(self):
return frappe.get_all(
@@ -2257,36 +2258,45 @@ class StockEntry(StockController):
group_by="`tabStock Entry Detail`.`item_code`",
=======
def get_items_from_manufacture_stock_entry(self, stock_entry):
=======
def get_items_from_manufacture_stock_entry(self, stock_entry=None):
>>>>>>> 3cf1ce8360 (fix: manufacture entry with group_by support)
SE = frappe.qb.DocType("Stock Entry")
SED = frappe.qb.DocType("Stock Entry Detail")
query = frappe.qb.from_(SED).join(SE).on(SED.parent == SE.name).where(SE.docstatus == 1)
common_fields = [
SED.item_code,
SED.item_name,
SED.description,
SED.stock_uom,
SED.uom,
SED.basic_rate,
SED.conversion_factor,
SED.is_finished_item,
SED.type,
SED.is_legacy_scrap_item,
SED.bom_secondary_item,
SED.batch_no,
SED.serial_no,
SED.use_serial_batch_fields,
SED.s_warehouse,
SED.t_warehouse,
]
if stock_entry:
return (
query.select(SED.name, SED.qty, SED.transfer_qty, *common_fields)
.where(SE.name == stock_entry)
.orderby(SED.idx)
.run(as_dict=True)
)
return (
frappe.qb.from_(SED)
.join(SE)
.on(SED.parent == SE.name)
.select(
SED.name,
SED.item_code,
SED.item_name,
SED.description,
SED.qty,
SED.transfer_qty,
SED.stock_uom,
SED.uom,
SED.basic_rate,
SED.conversion_factor,
SED.is_finished_item,
SED.type,
SED.is_legacy_scrap_item,
SED.bom_secondary_item,
SED.batch_no,
SED.serial_no,
SED.use_serial_batch_fields,
SED.s_warehouse,
SED.t_warehouse,
)
.where(SE.name == stock_entry)
.where(SE.docstatus == 1)
query.select(Sum(SED.qty).as_("qty"), Sum(SED.transfer_qty).as_("transfer_qty"), *common_fields)
.where(SE.purpose == "Manufacture")
.where(SE.work_order == self.work_order)
.groupby(SED.item_code)
.orderby(SED.idx)
.run(as_dict=True)
>>>>>>> 1ed0124ad7 (fix: add support to fetch items based on manufacture stock entry; fix how it's done from work order)