-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from efeone/aumms_item_report
feat:Aumms Item Report
- Loading branch information
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
20 changes: 20 additions & 0 deletions
20
aumms/aumms/report/aumms_items_summary_report/aumms_items_summary_report.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2024, efeone and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.query_reports["Aumms Items Summary report"] = { | ||
"filters": [ | ||
|
||
{ | ||
"label":__("Item Group"), | ||
"fieldname":"item_group", | ||
"fieldtype":"Link", | ||
"options":"AuMMS Item Group" | ||
}, | ||
{ | ||
"label":__("Item Code"), | ||
"fieldname":"item_code", | ||
"fieldtype":"Data", | ||
}, | ||
|
||
] | ||
}; |
33 changes: 33 additions & 0 deletions
33
aumms/aumms/report/aumms_items_summary_report/aumms_items_summary_report.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"add_total_row": 0, | ||
"columns": [], | ||
"creation": "2024-02-07 10:18:53.941930", | ||
"disabled": 0, | ||
"docstatus": 0, | ||
"doctype": "Report", | ||
"filters": [], | ||
"idx": 0, | ||
"is_standard": "Yes", | ||
"letter_head": "Sawa_gold", | ||
"letterhead": null, | ||
"modified": "2024-02-07 10:30:29.645973", | ||
"modified_by": "Administrator", | ||
"module": "AuMMS", | ||
"name": "Aumms Items Summary report", | ||
"owner": "Administrator", | ||
"prepared_report": 0, | ||
"ref_doctype": "AuMMS Item", | ||
"report_name": "Aumms Items Summary report", | ||
"report_type": "Script Report", | ||
"roles": [ | ||
{ | ||
"role": "System Manager" | ||
}, | ||
{ | ||
"role": "Sales Manager" | ||
}, | ||
{ | ||
"role": "AuMMS Manager" | ||
} | ||
] | ||
} |
107 changes: 107 additions & 0 deletions
107
aumms/aumms/report/aumms_items_summary_report/aumms_items_summary_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright (c) 2024, efeone and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe import _ | ||
|
||
def execute(filters=None): | ||
if not filters: | ||
filters = {} | ||
|
||
if "item_code" not in filters: | ||
filters["item_code"] = None | ||
|
||
columns = get_columns(filters) | ||
data = get_data(filters) | ||
return columns, data | ||
|
||
def get_columns(filters): | ||
columns = [ | ||
|
||
{ | ||
"label": _("Item Group"), | ||
"fieldname": "item_group", | ||
"fieldtype": "Link", | ||
"options": "AuMMS Item Group", | ||
"width": 180 | ||
}, | ||
{ | ||
"label": _("Item Code"), | ||
"fieldname": "item_code", | ||
"fieldtype": "Data", | ||
"width": 250 | ||
}, | ||
{ | ||
"label": _("Item Count"), | ||
"fieldname": "item_count", | ||
"fieldtype": "Int", | ||
"width": 120 | ||
}, | ||
{ | ||
"label": _("Item Group Count"), | ||
"fieldname": "item_group_count", | ||
"fieldtype": "Int", | ||
"width": 150 | ||
}, | ||
] | ||
return columns | ||
|
||
def get_data(filters): | ||
# query = """ | ||
# SELECT | ||
# ai.item_group, | ||
# ai.item_code, | ||
# item_counts.item_count | ||
# FROM | ||
# `tabAuMMS Item` ai | ||
# JOIN | ||
# (SELECT item_group, COUNT(*) AS item_count | ||
# FROM `tabAuMMS Item` | ||
# GROUP BY item_group) AS item_counts | ||
# ON ai.item_group = item_counts.item_group | ||
# WHERE 1=1 | ||
# """ | ||
query = """ | ||
SELECT | ||
CASE WHEN ROW_NUMBER() OVER (PARTITION BY grouped_items.item_group ORDER BY ai.item_code) = 1 | ||
THEN grouped_items.item_group | ||
ELSE '' | ||
END AS item_group, | ||
CASE WHEN ROW_NUMBER() OVER (PARTITION BY grouped_items.item_group ORDER BY ai.item_code) = 1 | ||
THEN grouped_items.item_group_count | ||
ELSE NULL | ||
END AS item_group_count, | ||
ai.item_code, | ||
COUNT(*) AS item_count | ||
FROM | ||
(SELECT | ||
item_group, | ||
COUNT(*) AS item_group_count | ||
FROM | ||
`tabAuMMS Item` | ||
GROUP BY | ||
item_group) AS grouped_items | ||
JOIN | ||
`tabAuMMS Item` AS ai | ||
ON | ||
grouped_items.item_group = ai.item_group | ||
""" | ||
|
||
combine_where = 0 | ||
if filters.get("item_code"): | ||
query += " WHERE ai.item_code like '%{0}%'".format(filters.get("item_code")) | ||
combine_where = 1 | ||
|
||
if filters.get("item_group"): | ||
if combine_where: | ||
query += " AND ai.item_group = '{0}'".format(filters.get("item_group")) | ||
else: | ||
query += " WHERE ai.item_group = '{0}'".format(filters.get("item_group")) | ||
|
||
query += " GROUP BY ai.item_code" | ||
# query += " ORDER BY ai.item_group, ai.item_code, item_counts.item_count;" | ||
|
||
# Execute the query and fetch data | ||
data = frappe.db.sql(query, as_dict=True) | ||
|
||
return data |