Skip to content

Commit

Permalink
Merge pull request #211 from efeone/aumms_item_report
Browse files Browse the repository at this point in the history
feat:Aumms Item Report
  • Loading branch information
muhammadmp authored Feb 12, 2024
2 parents 3e8d73c + 6a78624 commit 52b9bb2
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
Empty file.
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",
},

]
};
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"
}
]
}
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

0 comments on commit 52b9bb2

Please sign in to comment.