4183 lines
271 KiB
JSON
4183 lines
271 KiB
JSON
[
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2024-12-24 19:11:37.533049",
|
|
"module": "Asset Lite",
|
|
"name": "Test SUP vs Score Report",
|
|
"prepared_report": 0,
|
|
"query": "SELECT\n supplier,\n supplier_score\nFROM\n `tabSupplier Scorecard`\nORDER BY\n supplier_score DESC;",
|
|
"ref_doctype": "Supplier Scorecard",
|
|
"reference_report": "SUP Scorecard",
|
|
"report_name": "Test SUP vs Score Report",
|
|
"report_script": null,
|
|
"report_type": "Query Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Test SUP vs Score Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:10.967185",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Frequency",
|
|
"prepared_report": 0,
|
|
"query": "select\r\n custom_asset_names as Item,\r\n SUM(CASE WHEN maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS Planned,\r\n SUM(CASE WHEN maintenance_status = 'Completed' THEN 1 ELSE 0 END) as \"Completed\",\r\n SUM(CASE WHEN maintenance_status = 'Cancelled' THEN 1 ELSE 0 END) as \"Cancelled\",\r\n SUM(CASE WHEN maintenance_status = 'Overdue' THEN 1 ELSE 0 END) as \"Overdue\",\r\n COUNT(custom_asset_names) as \"Total Count\"\r\nfrom \r\n `tabAsset Maintenance Log`\r\ngroup by\r\n custom_asset_names",
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset Maintenance Frequency",
|
|
"report_script": "",
|
|
"report_type": "Query Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Frequency",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Frequency",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Frequency",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:12.617127",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Assignees Status Count",
|
|
"prepared_report": 0,
|
|
"query": "select item_name as \"Item Name\", maintenance_status as \"Maintenance Status\", assign_to_name as \"Assigned To\", sum(case when due_date = completion_date AND maintenance_status ='Completed' then 1 else 0 end) as \"Completed On Time\" ,sum(case when completion_date < due_date and maintenance_status = 'Completed' then 1 else 0 end) as \"Completed Within Time\",sum(case when completion_date >due_date then 1 else 0 end ) as \"Delay In Completion\",sum(case when maintenance_status = 'Planned' AND completion_date IS null AND due_date > current_date() then 1 else 0 end ) as \"Pending\",sum(case when maintenance_status = 'Planned' AND completion_date IS null AND due_date < current_date() then 1 else 0 end) as \"Overdue\" , sum(case when maintenance_status = 'Cancelled' then 1 else 0 end) as \"Cancelled\" from `tabAsset Maintenance Log` group by assign_to_name",
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset Maintenance Assignees Status Count",
|
|
"report_script": "",
|
|
"report_type": "Query Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Assignees Status Count",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignees Status Count",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignees Status Count",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:12.387500",
|
|
"module": "Asset Lite",
|
|
"name": "Asset wise Count",
|
|
"prepared_report": 0,
|
|
"query": "select item_name as \"Item Name\", maintenance_status as \"Maintenance Status\", sum(case when due_date = completion_date AND maintenance_status ='Completed' then 1 else 0 end) as \"Completed On Time\" ,sum(case when completion_date < due_date and maintenance_status = 'Completed' then 1 else 0 end) as \"Completed Within Time\",sum(case when completion_date >due_date then 1 else 0 end ) as \"Delay In Completion\",sum(case when maintenance_status = 'Planned' AND completion_date IS null AND due_date > current_date() then 1 else 0 end ) as \"Pending\",sum(case when maintenance_status = 'Planned' AND completion_date IS null AND due_date < current_date() then 1 else 0 end) as \"Overdue\" , sum(case when maintenance_status = 'Cancelled' then 1 else 0 end) as \"Cancelled\" from `tabAsset Maintenance Log` group by item_name",
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset wise Count",
|
|
"report_script": null,
|
|
"report_type": "Query Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset wise Count",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset wise Count",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "report_type",
|
|
"fieldtype": "Select",
|
|
"label": "Report Type",
|
|
"mandatory": 0,
|
|
"options": "Monthly\nQuarterly\nYearly",
|
|
"parent": "Biomedical PPM",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Data",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Biomedical PPM",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.584198",
|
|
"module": "Asset Lite",
|
|
"name": "Biomedical PPM",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "PPM OF CT SCAN MACHINE",
|
|
"reference_report": null,
|
|
"report_name": "Biomedical PPM",
|
|
"report_script": "def get_ppm_report(filters):\r\n # Define the columns for the report\r\n columns = [\r\n {\"label\": _(\"Timeframe\"), \"fieldname\": \"timeframe\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": _(\"CT Scan Machine PPM Count\"), \"fieldname\": \"ct_scan\", \"fieldtype\": \"Int\", \"width\": 250},\r\n {\"label\": _(\"MRI Scan Machine PPM Count\"), \"fieldname\": \"mri_scan\", \"fieldtype\": \"Int\", \"width\": 250}\r\n ]\r\n\r\n # Get the selected year, default to current year if not provided\r\n year = filters.get(\"year\") or frappe.utils.now_datetime().year\r\n\r\n # Determine the type of report - monthly, quarterly, or yearly\r\n report_type = filters.get(\"report_type\") # Example values: 'Monthly', 'Quarterly', 'Yearly'\r\n\r\n # Initialize SQL query for data aggregation based on the selected timeframe\r\n if report_type == \"Monthly\":\r\n query = f\"\"\"\r\n SELECT\r\n month AS timeframe,\r\n SUM(CASE WHEN dt.name = 'PPM OF CT SCAN MACHINE' THEN 1 ELSE 0 END) AS ct_scan,\r\n SUM(CASE WHEN dt.name = 'PPM OF MRI SCAN MACHINE' THEN 1 ELSE 0 END) AS mri_scan\r\n FROM (\r\n SELECT 'PPM OF CT SCAN MACHINE' AS name, month, year FROM `tabPPM OF CT SCAN MACHINE` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF MRI SCAN MACHINE' AS name, month, year FROM `tabPPM OF MRI SCAN MACHINE` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY month, year\r\n ORDER BY MONTH(STR_TO_DATE(month, '%M'))\r\n \"\"\"\r\n elif report_type == \"Quarterly\":\r\n query = f\"\"\"\r\n SELECT\r\n CONCAT('Q', QUARTER(STR_TO_DATE(month, '%M'))) AS timeframe,\r\n SUM(CASE WHEN dt.name = 'PPM OF CT SCAN MACHINE' THEN 1 ELSE 0 END) AS ct_scan,\r\n SUM(CASE WHEN dt.name = 'PPM OF MRI SCAN MACHINE' THEN 1 ELSE 0 END) AS mri_scan\r\n FROM (\r\n SELECT 'PPM OF CT SCAN MACHINE' AS name, month, year FROM `tabPPM OF CT SCAN MACHINE` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF MRI SCAN MACHINE' AS name, month, year FROM `tabPPM OF MRI SCAN MACHINE` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY QUARTER(STR_TO_DATE(month, '%M')), year\r\n ORDER BY QUARTER(STR_TO_DATE(month, '%M'))\r\n \"\"\"\r\n else: # Yearly\r\n query = f\"\"\"\r\n SELECT\r\n year AS timeframe,\r\n SUM(CASE WHEN dt.name = 'PPM OF CT SCAN MACHINE' THEN 1 ELSE 0 END) AS ct_scan,\r\n SUM(CASE WHEN dt.name = 'PPM OF MRI SCAN MACHINE' THEN 1 ELSE 0 END) AS mri_scan\r\n FROM (\r\n SELECT 'PPM OF CT SCAN MACHINE' AS name, month, year FROM `tabPPM OF CT SCAN MACHINE` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF MRI SCAN MACHINE' AS name, month, year FROM `tabPPM OF MRI SCAN MACHINE` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY year\r\n ORDER BY year\r\n \"\"\"\r\n\r\n # Execute the SQL query to get the result\r\n result = frappe.db.sql(query, as_dict=1)\r\n\r\n # Prepare report summary\r\n report_summary = [\r\n {\"value\": sum(row['ct_scan'] for row in result), \"label\": \"Total CT Scan Machine PPM\"},\r\n {\"value\": sum(row['mri_scan'] for row in result), \"label\": \"Total MRI Scan Machine PPM\"},\r\n {\"value\": sum(row['ct_scan'] for row in result) + sum(row['mri_scan'] for row in result), \"label\": \"Total PPM\"}\r\n ]\r\n\r\n # Prepare data for the charts\r\n labels = [row.get(\"timeframe\") for row in result]\r\n ct_scan = [row.get(\"ct_scan\") for row in result]\r\n mri_scan = [row.get(\"mri_scan\") for row in result]\r\n\r\n # Create a bar chart configuration\r\n bar_chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"CT Scan Machine PPM Count\", \"values\": ct_scan, \"chartType\": \"bar\"},\r\n {\"name\": \"MRI Scan Machine PPM Count\", \"values\": mri_scan, \"chartType\": \"bar\"}\r\n ]\r\n },\r\n \"colors\": [\"#52B2BF\", \"#01796F\"],\r\n \"barOptions\": {\"stacked\": 0},\r\n \"axisOptions\": {\"xIsSeries\": 1, \"yAxisMin\": 0}\r\n }\r\n\r\n # Create a line chart configuration\r\n line_chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"CT Scan Machine PPM Count\", \"values\": ct_scan, \"chartType\": \"line\"},\r\n {\"name\": \"MRI Scan Machine PPM Count\", \"values\": mri_scan, \"chartType\": \"line\"}\r\n ]\r\n },\r\n \"colors\": [\"#52B2BF\", \"#01796F\"],\r\n \"axisOptions\": {\"xIsSeries\": 1, \"yAxisMin\": 0}\r\n }\r\n\r\n return columns, result, None, {\"bar\": bar_chart, \"line\": line_chart}, report_summary\r\n\r\ndata = get_ppm_report(filters)\r\n\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Biomedical PPM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Biomedical PPM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Biomedical PPM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:12.518262",
|
|
"module": "Asset Lite",
|
|
"name": "PPM report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "PPM OF FIRE ALARM DEVICES",
|
|
"reference_report": null,
|
|
"report_name": "PPM report",
|
|
"report_script": "def get_result():\r\n # Define the columns for the report\r\n columns = [\r\n {\"label\": _(\"Month\"), \"fieldname\": \"month\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": _(\"Fire Alarm Devices PPM Count\"), \"fieldname\": \"fire_alarm_count\", \"fieldtype\": \"Int\", \"width\": 250},\r\n {\"label\": _(\"Electrical Panels PPM Count\"), \"fieldname\": \"electrical_panels_count\", \"fieldtype\": \"Int\", \"width\": 250}\r\n ]\r\n\r\n # Filter by the selected year\r\n year = frappe.utils.now_datetime().year\r\n\r\n # Initialize the SQL query for data aggregation\r\n query = f\"\"\"\r\n SELECT\r\n month,\r\n SUM(CASE WHEN dt.name = 'PPM OF FIRE ALARM DEVICES' THEN 1 ELSE 0 END) AS fire_alarm_count,\r\n SUM(CASE WHEN dt.name = 'PPM OF ELECTRICAL PANELS' THEN 1 ELSE 0 END) AS electrical_panels_count\r\n FROM (\r\n SELECT 'PPM OF FIRE ALARM DEVICES' AS name, month, year FROM `tabPPM OF FIRE ALARM DEVICES` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF ELECTRICAL PANELS' AS name, month, year FROM `tabPPM OF ELECTRICAL PANELS` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY month, year\r\n ORDER BY MONTH(STR_TO_DATE(month, '%M'))\r\n \"\"\"\r\n\r\n result = frappe.db.sql(query, as_dict=1)\r\n\r\n # Prepare report summary\r\n report_summary = [\r\n {\"value\": sum(row['fire_alarm_count'] for row in result), \"label\": \"Total Fire Alarm PPM\"},\r\n {\"value\": sum(row['electrical_panels_count'] for row in result), \"label\": \"Total Electrical Panels PPM\"},\r\n {\"value\": sum(row['fire_alarm_count'] for row in result) + sum(row['electrical_panels_count'] for row in result), \"label\": \"Total PPM\"}\r\n ]\r\n\r\n # Prepare data for the chart\r\n labels = [row.get(\"month\") for row in result]\r\n fire_alarm_count = [row.get(\"fire_alarm_count\") for row in result]\r\n electrical_panels_count = [row.get(\"electrical_panels_count\") for row in result]\r\n\r\n # Create a chart configuration\r\n chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"Fire Alarm Devices PPM Count\", \"values\": fire_alarm_count, \"chartType\": \"bar\"},\r\n {\"name\": \"Electrical Panels PPM Count\", \"values\": electrical_panels_count, \"chartType\": \"bar\"}\r\n ]\r\n },\r\n \"colors\": [\"#52B2BF\", \"#01796F\"],\r\n \"barOptions\": {\"stacked\": 0}, # Stacked bar chart\r\n }\r\n\r\n return columns, result, None, chart, report_summary\r\n\r\ndata = get_result()\r\n\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PPM report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "PPM report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "PPM report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PPM report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:12.485284",
|
|
"module": "Asset Lite",
|
|
"name": "PPM report based on Status",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "PPM OF FIRE ALARM DEVICES",
|
|
"reference_report": null,
|
|
"report_name": "PPM report based on Status",
|
|
"report_script": "def get_simple_ppm_status_report():\r\n # Define the columns for the report\r\n columns = [\r\n {\"label\": _(\"PPM Type\"), \"fieldname\": \"ppm_type\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": _(\"Sent to technician\"), \"fieldname\": \"sent_to_technician\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": _(\"Pending Approval Count\"), \"fieldname\": \"pending_approval\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": _(\"Approved Count\"), \"fieldname\": \"approved_count\", \"fieldtype\": \"Int\", \"width\": 200}\r\n ]\r\n\r\n # SQL query to get the counts of PPMs based on their workflow states\r\n query = \"\"\"\r\n SELECT\r\n ppm_type,\r\n SUM(CASE WHEN workflow_state = 'Sent to technician' THEN 1 ELSE 0 END) AS sent_to_technician,\r\n SUM(CASE WHEN workflow_state = 'Pending Approval' THEN 1 ELSE 0 END) AS pending_approval,\r\n SUM(CASE WHEN workflow_state = 'Approved' THEN 1 ELSE 0 END) AS approved_count\r\n FROM (\r\n \r\n SELECT 'PPM OF CT SCAN MACHINE' AS ppm_type, workflow_state FROM `tabPPM OF CT SCAN MACHINE`\r\n UNION ALL\r\n SELECT 'PPM OF MRI SCAN MACHINE' AS ppm_type, workflow_state FROM `tabPPM OF MRI SCAN MACHINE`\r\n ) AS dt\r\n GROUP BY ppm_type\r\n ORDER BY ppm_type\r\n \"\"\"\r\n\r\n # Execute the SQL query to get the result\r\n result = frappe.db.sql(query, as_dict=1)\r\n\r\n # Prepare report summary\r\n report_summary = [\r\n {\"value\": sum(row['sent_to_technician'] for row in result), \"label\": \"Total Sent To Technician\"},\r\n {\"value\": sum(row['pending_approval'] for row in result), \"label\": \"Total Pending For Approval\"},\r\n {\"value\": sum(row['approved_count'] for row in result), \"label\": \"Total Approved\"}\r\n ]\r\n\r\n # Prepare data for the charts\r\n labels = [row.get(\"ppm_type\") for row in result]\r\n sent_to_technician = [row.get(\"sent_to_technician\") for row in result]\r\n pending_approval = [row.get(\"pending_approval\") for row in result]\r\n approved_count = [row.get(\"approved_count\") for row in result]\r\n\r\n # Create a bar chart configuration\r\n bar_chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"Pending Approval\", \"values\": pending_approval, \"chartType\": \"bar\"},\r\n {\"name\": \"Sent To Technician\", \"values\": sent_to_technician, \"chartType\": \"bar\"},\r\n {\"name\": \"Approved\", \"values\": approved_count, \"chartType\": \"bar\"}\r\n ]\r\n },\r\n \"colors\": [\"#CCCCB7\", \"#52B2BF\", \"#008000\"], # Example colors for each status\r\n \"barOptions\": {\"stacked\": 0}, # Separate bars for each status\r\n }\r\n\r\n # Return the columns, result data, chart configuration, and report summary\r\n return columns, result, None, bar_chart, report_summary\r\n\r\n# Example usage\r\ndata = get_simple_ppm_status_report()\r\n\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PPM report based on Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "PPM report based on Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "PPM report based on Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PPM report based on Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "report_type",
|
|
"fieldtype": "Select",
|
|
"label": "Report Type",
|
|
"mandatory": 0,
|
|
"options": "Monthly\nQuarterly\nYearly",
|
|
"parent": "PPM monthly reports",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Data",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "PPM monthly reports",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:12.548948",
|
|
"module": "Asset Lite",
|
|
"name": "PPM monthly reports",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "PPM OF FIRE ALARM DEVICES",
|
|
"reference_report": null,
|
|
"report_name": "PPM monthly reports",
|
|
"report_script": "def get_ppm_report(filters):\r\n # Define the columns for the report\r\n columns = [\r\n {\"label\": _(\"Timeframe\"), \"fieldname\": \"timeframe\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": _(\"Fire Alarm Devices PPM Count\"), \"fieldname\": \"fire_alarm_count\", \"fieldtype\": \"Int\", \"width\": 250},\r\n {\"label\": _(\"Electrical Panels PPM Count\"), \"fieldname\": \"electrical_panels_count\", \"fieldtype\": \"Int\", \"width\": 250}\r\n ]\r\n\r\n # Get the selected year, default to current year if not provided\r\n year = filters.get(\"year\") or frappe.utils.now_datetime().year\r\n\r\n # Determine the type of report - monthly, quarterly, or yearly\r\n report_type = filters.get(\"report_type\") # Example values: 'Monthly', 'Quarterly', 'Yearly'\r\n\r\n # Initialize SQL query for data aggregation based on the selected timeframe\r\n if report_type == \"Monthly\":\r\n query = f\"\"\"\r\n SELECT\r\n month AS timeframe,\r\n SUM(CASE WHEN dt.name = 'PPM OF FIRE ALARM DEVICES' THEN 1 ELSE 0 END) AS fire_alarm_count,\r\n SUM(CASE WHEN dt.name = 'PPM OF ELECTRICAL PANELS' THEN 1 ELSE 0 END) AS electrical_panels_count\r\n FROM (\r\n SELECT 'PPM OF FIRE ALARM DEVICES' AS name, month, year FROM `tabPPM OF FIRE ALARM DEVICES` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF ELECTRICAL PANELS' AS name, month, year FROM `tabPPM OF ELECTRICAL PANELS` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY month, year\r\n ORDER BY MONTH(STR_TO_DATE(month, '%M'))\r\n \"\"\"\r\n elif report_type == \"Quarterly\":\r\n query = f\"\"\"\r\n SELECT\r\n CONCAT('Q', QUARTER(STR_TO_DATE(month, '%M'))) AS timeframe,\r\n SUM(CASE WHEN dt.name = 'PPM OF FIRE ALARM DEVICES' THEN 1 ELSE 0 END) AS fire_alarm_count,\r\n SUM(CASE WHEN dt.name = 'PPM OF ELECTRICAL PANELS' THEN 1 ELSE 0 END) AS electrical_panels_count\r\n FROM (\r\n SELECT 'PPM OF FIRE ALARM DEVICES' AS name, month, year FROM `tabPPM OF FIRE ALARM DEVICES` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF ELECTRICAL PANELS' AS name, month, year FROM `tabPPM OF ELECTRICAL PANELS` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY QUARTER(STR_TO_DATE(month, '%M')), year\r\n ORDER BY QUARTER(STR_TO_DATE(month, '%M'))\r\n \"\"\"\r\n else: # Yearly\r\n query = f\"\"\"\r\n SELECT\r\n year AS timeframe,\r\n SUM(CASE WHEN dt.name = 'PPM OF FIRE ALARM DEVICES' THEN 1 ELSE 0 END) AS fire_alarm_count,\r\n SUM(CASE WHEN dt.name = 'PPM OF ELECTRICAL PANELS' THEN 1 ELSE 0 END) AS electrical_panels_count\r\n FROM (\r\n SELECT 'PPM OF FIRE ALARM DEVICES' AS name, month, year FROM `tabPPM OF FIRE ALARM DEVICES` WHERE year = '{year}'\r\n UNION ALL\r\n SELECT 'PPM OF ELECTRICAL PANELS' AS name, month, year FROM `tabPPM OF ELECTRICAL PANELS` WHERE year = '{year}'\r\n ) AS dt\r\n GROUP BY year\r\n ORDER BY year\r\n \"\"\"\r\n\r\n # Execute the SQL query to get the result\r\n result = frappe.db.sql(query, as_dict=1)\r\n\r\n # Prepare report summary\r\n report_summary = [\r\n {\"value\": sum(row['fire_alarm_count'] for row in result), \"label\": \"Total Fire Alarm PPM\"},\r\n {\"value\": sum(row['electrical_panels_count'] for row in result), \"label\": \"Total Electrical Panels PPM\"},\r\n {\"value\": sum(row['fire_alarm_count'] for row in result) + sum(row['electrical_panels_count'] for row in result), \"label\": \"Total PPM\"}\r\n ]\r\n\r\n # Prepare data for the charts\r\n labels = [row.get(\"timeframe\") for row in result]\r\n fire_alarm_count = [row.get(\"fire_alarm_count\") for row in result]\r\n electrical_panels_count = [row.get(\"electrical_panels_count\") for row in result]\r\n\r\n # Create a bar chart configuration\r\n bar_chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"Fire Alarm Devices PPM Count\", \"values\": fire_alarm_count, \"chartType\": \"bar\"},\r\n {\"name\": \"Electrical Panels PPM Count\", \"values\": electrical_panels_count, \"chartType\": \"bar\"}\r\n ]\r\n },\r\n \"colors\": [\"#52B2BF\", \"#01796F\"],\r\n \"barOptions\": {\"stacked\": 0},\r\n \"axisOptions\": {\"xIsSeries\": 1, \"yAxisMin\": 0}\r\n }\r\n\r\n # Create a line chart configuration\r\n line_chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"Fire Alarm Devices PPM Count\", \"values\": fire_alarm_count, \"chartType\": \"line\"},\r\n {\"name\": \"Electrical Panels PPM Count\", \"values\": electrical_panels_count, \"chartType\": \"line\"}\r\n ]\r\n },\r\n \"colors\": [\"#52B2BF\", \"#01796F\"],\r\n \"axisOptions\": {\"xIsSeries\": 1, \"yAxisMin\": 0}\r\n }\r\n\r\n return columns, result, None, {\"bar\": bar_chart, \"line\": line_chart}, report_summary\r\n\r\ndata = get_ppm_report(filters)\r\n\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PPM monthly reports",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "PPM monthly reports",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "PPM monthly reports",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PPM monthly reports",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2024-10-01 10:26:27.837456",
|
|
"module": "Asset Lite",
|
|
"name": "Work Order counts",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Work Order counts",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Work Order counts",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order counts",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.417277",
|
|
"module": "Asset Lite",
|
|
"name": "PPM Status",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "PPM",
|
|
"reference_report": null,
|
|
"report_name": "PPM Status",
|
|
"report_script": "def get_simple_ppm_status_report():\n # Define the columns for the report\n columns = [\n {\"label\": _(\"PPM Template\"), \"fieldname\": \"ppm_template\", \"fieldtype\": \"Data\", \"width\": 150},\n {\"label\": _(\"Sent to technician\"), \"fieldname\": \"sent_to_technician\", \"fieldtype\": \"Int\", \"width\": 200},\n {\"label\": _(\"Pending Approval Count\"), \"fieldname\": \"pending_approval\", \"fieldtype\": \"Int\", \"width\": 200},\n {\"label\": _(\"Approved Count\"), \"fieldname\": \"approved_count\", \"fieldtype\": \"Int\", \"width\": 200}\n ]\n\n # SQL query to get the counts of PPMs based on their workflow states and template\n query = \"\"\"\n SELECT\n data AS ppm_template,\n SUM(CASE WHEN workflow_state = 'Sent to technician' THEN 1 ELSE 0 END) AS sent_to_technician,\n SUM(CASE WHEN workflow_state = 'Pending Approval' THEN 1 ELSE 0 END) AS pending_approval,\n SUM(CASE WHEN workflow_state = 'Approved' THEN 1 ELSE 0 END) AS approved_count\n FROM `tabPPM`\n GROUP BY data\n ORDER BY data\n \"\"\"\n\n # Execute the SQL query to get the result\n result = frappe.db.sql(query, as_dict=1)\n\n # Prepare report summary\n report_summary = [\n {\"value\": sum(row['sent_to_technician'] for row in result), \"label\": \"Total Sent To Technician\"},\n {\"value\": sum(row['pending_approval'] for row in result), \"label\": \"Total Pending For Approval\"},\n {\"value\": sum(row['approved_count'] for row in result), \"label\": \"Total Approved\"}\n ]\n\n # Prepare data for the charts\n labels = [row.get(\"ppm_template\") for row in result]\n sent_to_technician = [row.get(\"sent_to_technician\") for row in result]\n pending_approval = [row.get(\"pending_approval\") for row in result]\n approved_count = [row.get(\"approved_count\") for row in result]\n\n # Create a bar chart configuration\n bar_chart = {\n \"data\": {\n \"labels\": labels,\n \"datasets\": [\n {\"name\": \"Pending Approval\", \"values\": pending_approval, \"chartType\": \"bar\"},\n {\"name\": \"Sent To Technician\", \"values\": sent_to_technician, \"chartType\": \"bar\"},\n {\"name\": \"Approved\", \"values\": approved_count, \"chartType\": \"bar\"}\n ]\n },\n \"colors\": [\"#CCCCB7\", \"#52B2BF\", \"#008000\"], # Example colors for each status\n \"barOptions\": {\"stacked\": 0}, # Separate bars for each status\n }\n\n # Return the columns, result data, chart configuration, and report summary\n return columns, result, None, bar_chart, report_summary\n\n# Example usage\ndata = get_simple_ppm_status_report()",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PPM Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "PPM Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PPM Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "report_type",
|
|
"fieldtype": "Select",
|
|
"label": "Report Type",
|
|
"mandatory": 0,
|
|
"options": "Monthly\nQuarterly\nYearly",
|
|
"parent": "PPM Template Counts",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Data",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "PPM Template Counts",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.450767",
|
|
"module": "Asset Lite",
|
|
"name": "PPM Template Counts",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "PPM",
|
|
"reference_report": null,
|
|
"report_name": "PPM Template Counts",
|
|
"report_script": "def get_ppm_report(filters):\n # Define the columns for the report\n columns = [\n {\"label\": _(\"Timeframe\"), \"fieldname\": \"timeframe\", \"fieldtype\": \"Data\", \"width\": 150}\n ]\n\n # Get the selected year, default to current year if not provided\n year = filters.get(\"year\") or frappe.utils.now_datetime().year\n\n # Determine the type of report - monthly, quarterly, or yearly\n report_type = filters.get(\"report_type\") # Example values: 'Monthly', 'Quarterly', 'Yearly'\n\n # Get distinct data field values from the PPM doctype\n templates = frappe.db.sql(\"\"\"\n SELECT DISTINCT data \n FROM `tabPPM`\n \"\"\", as_dict=True)\n\n # Add dynamic columns for each data field found in the PPM doctype\n for template in templates:\n columns.append({\n \"label\": _(f\"{template['data']} PPM Count\"), \n \"fieldname\": template['data'].replace(\" \", \"_\").lower(), # Simple scrub replacement\n \"fieldtype\": \"Int\", \n \"width\": 250\n })\n\n # Initialize SQL query for data aggregation based on the selected timeframe\n if report_type == \"Monthly\":\n query = f\"\"\"\n SELECT\n month AS timeframe,\n data,\n COUNT(name) AS ppm_count\n FROM `tabPPM`\n WHERE year = '{year}'\n GROUP BY month, data\n ORDER BY MONTH(STR_TO_DATE(month, '%M'))\n \"\"\"\n elif report_type == \"Quarterly\":\n query = f\"\"\"\n SELECT\n CONCAT('Q', QUARTER(STR_TO_DATE(month, '%M'))) AS timeframe,\n data,\n COUNT(name) AS ppm_count\n FROM `tabPPM`\n WHERE year = '{year}'\n GROUP BY QUARTER(STR_TO_DATE(month, '%M')), data\n ORDER BY QUARTER(STR_TO_DATE(month, '%M'))\n \"\"\"\n else: # Yearly\n query = f\"\"\"\n SELECT\n year AS timeframe,\n data,\n COUNT(name) AS ppm_count\n FROM `tabPPM`\n WHERE year = '{year}'\n GROUP BY year, data\n ORDER BY year\n \"\"\"\n\n # Execute the SQL query to get the result\n result = frappe.db.sql(query, as_dict=True)\n\n # Organize the result in a structured way\n data = []\n grouped_result = {}\n\n for row in result:\n timeframe = row[\"timeframe\"]\n template = row[\"data\"].replace(\" \", \"_\").lower() # Simple scrub replacement\n\n if timeframe not in grouped_result:\n grouped_result[timeframe] = {tmpl['data'].replace(\" \", \"_\").lower(): 0 for tmpl in templates}\n grouped_result[timeframe][\"timeframe\"] = timeframe\n\n grouped_result[timeframe][template] = row[\"ppm_count\"]\n\n # Convert grouped result to a list of rows\n for timeframe, counts in grouped_result.items():\n data.append(counts)\n\n # Prepare report summary dynamically\n report_summary = [\n {\"value\": sum(row[template['data'].replace(\" \", \"_\").lower()] for row in data), \"label\": f\"Total {template['data']} PPM\"}\n for template in templates\n ]\n\n # Prepare data for the charts\n labels = [row.get(\"timeframe\") for row in data]\n chart_datasets = []\n\n for template in templates:\n chart_datasets.append({\n \"name\": f\"{template['data']} PPM Count\",\n \"values\": [row.get(template['data'].replace(\" \", \"_\").lower(), 0) for row in data],\n \"chartType\": \"bar\"\n })\n\n # Create a bar chart configuration\n bar_chart = {\n \"data\": {\n \"labels\": labels,\n \"datasets\": chart_datasets\n },\n \"colors\": [\"#52B2BF\", \"#01796F\", \"#D4AF37\"], # Example colors, can add more dynamically\n \"barOptions\": {\"stacked\": 0},\n \"axisOptions\": {\"xIsSeries\": 1, \"yAxisMin\": 0}\n }\n\n return columns, data, None, bar_chart, report_summary\n\n# Example usage\ndata = get_ppm_report(filters)\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PPM Template Counts",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "PPM Template Counts",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PPM Template Counts",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "from_date",
|
|
"fieldtype": "Date",
|
|
"label": "From Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "to_date",
|
|
"fieldtype": "Date",
|
|
"label": "To Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "item_code",
|
|
"fieldtype": "Link",
|
|
"label": "Item Code",
|
|
"mandatory": 0,
|
|
"options": "Item",
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.351949",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset Maintenance Report",
|
|
"report_script": "def get_result(filters):\n additional_filters = \"\"\n filter_fields = ['item_code','from_date','to_date'] \n \n for field in filter_fields:\n if filters.get(field):\n if field == \"from_date\":\n additional_filters = additional_filters + f\" AND due_date >= '{filters.get(field)}'\"\n if field == \"to_date\":\n additional_filters = additional_filters + f\" AND due_date <= '{filters.get(field)}'\"\n if field == \"item_code\":\n additional_filters = additional_filters + f\" AND item_code = '{filters.get(field)}'\"\n \n \n \n result=frappe.db.sql(f\"\"\" SELECT am.item_code as item_code, am.asset_maintenance as asset_maintenance, am.maintenance_status as maintenance_status,am.assign_to_name as assign_to_name, am.due_date as due_date from `tabAsset Maintenance Log` as am where am.maintenance_status = 'Planned' {additional_filters} \"\"\")\n\n columns = [\n {\n \"label\": _(\"Item Code\"),\n \"fieldname\": \"item_code\",\n \"fieldtype\": \"Link\",\n \"options\": \"Item\",\n \"width\": 160,\n },\n {\n \"label\": _(\"Asset Maintenance\"),\n \"fieldname\": \"asset_maintenance\",\n \"fieldtype\": \"Link\",\n \"options\": \"Asset Maintenance\",\n \"width\": 160,\n },\n \n {\n \"label\": _(\"Maintenance Status\"),\n \"fieldname\": \"maintenance_status\",\n \"fieldtype\": \"Data\",\n \n \"width\": 160,\n },\n {\n \"label\": _(\"Assigned To\"),\n \"fieldname\": \"assign_to_name\",\n \"fieldtype\": \"Data\",\n \n \"width\": 160,\n },\n {\n \"label\": _(\"Due Date\"),\n \"fieldname\": \"due_date\",\n \"fieldtype\": \"Date\",\n \n \"width\": 160,\n },\n ]\n \n return columns, result, None,None, None\ndata = get_result(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "from_date",
|
|
"fieldtype": "Date",
|
|
"label": "From Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "to_date",
|
|
"fieldtype": "Date",
|
|
"label": "To Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.298283",
|
|
"module": "Asset Lite",
|
|
"name": "Due Calibiration Date",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Item",
|
|
"reference_report": null,
|
|
"report_name": "Due Calibiration Date",
|
|
"report_script": "def execute(filters):\r\n columns = [\r\n {\"label\": \"Item Code\", \"fieldname\": \"item_code\", \"fieldtype\": \"Link\",\"options\":\"Item\", \"width\": 150},\r\n {\"label\": \"Item Name\", \"fieldname\": \"item_name\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Calibration Due Date\", \"fieldname\": \"custom_next_due_calibration_date\", \"fieldtype\": \"Date\", \"width\": 150},\r\n \r\n ]\r\n\r\n result = []\r\n \r\n if not filters:\r\n filters = {}\r\n\r\n # Calculate today's date and the date 60 days from now using frappe.utils\r\n from_date = filters.get(\"from_date\") or frappe.utils.today()\r\n to_date = filters.get(\"to_date\") or frappe.utils.add_days(frappe.utils.today(), 60)\r\n\r\n # Fetch items with calibration due date within the next 60 days\r\n items = frappe.db.get_list(\"Item\", \r\n filters={\r\n \"custom_next_due_calibration_date\": [\"between\", [from_date, to_date]],\r\n \"item_group\":\"Tools\"\r\n },\r\n fields=[\"name\", \"item_code\", \"item_name\", \"custom_next_due_calibration_date\", \"status\"],\r\n order_by=\"modified desc\" # Ensures ordering without causing SQL syntax errors\r\n \r\n )\r\n\r\n for item in items:\r\n # Calculate the days remaining until the calibration due date\r\n days_remaining = (frappe.utils.getdate(item.get(\"custom_next_due_calibration_date\")) - frappe.utils.getdate(frappe.utils.today())).days\r\n result.append({\r\n \"item_code\": item.get(\"item_code\"),\r\n \"item_name\": item.get(\"item_name\"),\r\n \"custom_next_due_calibration_date\": item.get(\"custom_next_due_calibration_date\"),\r\n \"days_remaining\": days_remaining,\r\n \"status\": item.get(\"status\")\r\n })\r\n\r\n # Add chart configuration\r\n chart = {\r\n \"data\": {\r\n \"labels\": [f\"{d['item_code']} ({d['custom_next_due_calibration_date']})\" for d in result],\r\n \"datasets\": [\r\n {\r\n \"name\": \"Days Remaining\",\r\n \"values\": [d[\"days_remaining\"] for d in result]\r\n }\r\n \r\n ]\r\n },\r\n \"type\": \"bar\", # You can also use 'line' or other chart types\r\n \"colors\": [\"#7cd6fd\"],\r\n }\r\n\r\n\r\n return columns, result, None, chart\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Item Manager"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Sales User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Stock User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Stock Manager"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Desk User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Purchase User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Due Calibiration Date",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "supplier",
|
|
"fieldtype": "Link",
|
|
"label": "Supplier",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "Asset ID",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.775945",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Count (Supplier)",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Count (Supplier)",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n supplier = filters.get(\"supplier\")\r\n\r\n # Query to fetch asset names, departments, status, and location\r\n if supplier:\r\n query = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n supplier\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n supplier = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, supplier, as_dict=True)\r\n else:\r\n # If no department is selected, return all assets\r\n query_no_department = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n supplier\r\n FROM\r\n `tabAsset`\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query_no_department, as_dict=True)\r\n\r\n # Create a dictionary to count assets per department\r\n supplier_count = {}\r\n \r\n for row in result:\r\n dept = row['supplier']\r\n if dept in supplier_count:\r\n supplier_count[dept] = supplier_count[dept] + 1 # Increment count\r\n else:\r\n supplier_count[dept] = 1 # Initialize count\r\n\r\n # Prepare data for the chart\r\n chart_labels = list(supplier_count.keys()) # Departments\r\n chart_values = list(supplier_count.values()) # Count of assets\r\n\r\n # Define the columns to be displayed in the report\r\n columns = [\r\n {\"fieldname\": \"name\", \"label\": \"Asset ID\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"supplier\", \"label\": \"Supplier\", \"fieldtype\": \"Link\", \"options\":\"Supplier\",\"width\": 100},\r\n \r\n ]\r\n\r\n # Configure the chart to show the number of assets per department\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Department names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Number of Assets\",\r\n \"values\": chart_values # Count of assets for each department\r\n }\r\n ]\r\n },\r\n \"type\": \"pie\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#ECAD4B\",\"#39E4A5\",\"#B4CD29\"] # Customize the color as needed\r\n }\r\n\r\n return columns, result, None, chart\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "manufacturer",
|
|
"fieldtype": "Data",
|
|
"label": "Manufacturer",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.937552",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Count (Manufacturer)",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Count (Manufacturer)",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n manufacturer = filters.get(\"manufacturer\")\r\n\r\n # Query to fetch asset names, departments, status, and location\r\n if manufacturer:\r\n query = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n custom_manufacturer\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n manufacturer = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, manufacturer, as_dict=True)\r\n else:\r\n # If no department is selected, return all assets\r\n query_no_department = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n custom_manufacturer\r\n FROM\r\n `tabAsset`\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query_no_department, as_dict=True)\r\n\r\n # Create a dictionary to count assets per department\r\n manufacturer_count = {}\r\n \r\n for row in result:\r\n dept = row['custom_manufacturer']\r\n if dept in manufacturer_count:\r\n manufacturer_count[dept] = manufacturer_count[dept] + 1 # Increment count\r\n else:\r\n manufacturer_count[dept] = 1 # Initialize count\r\n\r\n # Prepare data for the chart\r\n chart_labels = list(manufacturer_count.keys()) # Departments\r\n chart_values = list(manufacturer_count.values()) # Count of assets\r\n\r\n # Define the columns to be displayed in the report\r\n columns = [\r\n {\"fieldname\": \"name\", \"label\": \"Asset ID\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"manufacturer_count\", \"label\": \"Manufacturer\", \"fieldtype\": \"Data\", \"width\": 100},\r\n \r\n ]\r\n\r\n # Configure the chart to show the number of assets per department\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Department names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Number of Assets\",\r\n \"values\": chart_values # Count of assets for each department\r\n }\r\n ]\r\n },\r\n \"type\": \"pie\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#ECAD4B\",\"#39E4A5\",\"#B4CD29\"] # Customize the color as needed\r\n }\r\n\r\n return columns, result, None, chart\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Manufacturer)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.896457",
|
|
"module": "Asset Lite",
|
|
"name": "Employee",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Employee",
|
|
"reference_report": null,
|
|
"report_name": "Employee",
|
|
"report_script": "def execute(filters=None):\r\n # Define columns\r\n columns = [\r\n {\"fieldname\": \"employee_id\", \"label\": \"Employee ID\", \"fieldtype\": \"Link\", \"options\": \"Employee\", \"width\": 150},\r\n {\"fieldname\": \"employee_name\", \"label\": \"Employee Name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"fieldname\": \"date_of_joining\", \"label\": \"Date of Joining\", \"fieldtype\": \"Date\", \"width\": 150},\r\n {\"fieldname\": \"years_completed\", \"label\": \"Years Completed\", \"fieldtype\": \"Int\", \"width\": 100},\r\n ]\r\n\r\n # Build SQL query\r\n query = \"\"\"\r\n SELECT\r\n emp.name AS employee_id,\r\n emp.employee_name,\r\n emp.date_of_joining,\r\n TIMESTAMPDIFF(YEAR, emp.date_of_joining, CURDATE()) AS years_completed\r\n FROM\r\n `tabEmployee` emp\r\n WHERE\r\n emp.status = 'Active'\r\n \"\"\"\r\n\r\n # Apply filters safely\r\n if filters.get(\"department\"):\r\n query += \" AND emp.department = %(department)s\"\r\n if filters.get(\"date_of_joining_from\"):\r\n query += \" AND emp.date_of_joining >= %(date_of_joining_from)s\"\r\n if filters.get(\"date_of_joining_to\"):\r\n query += \" AND emp.date_of_joining <= %(date_of_joining_to)s\"\r\n\r\n query =query+ \" ORDER BY emp.date_of_joining DESC\"\r\n\r\n # Execute query\r\n result = frappe.db.sql(query, filters, as_dict=True) or []\r\n\r\n return columns, result\r\n\r\ndata=execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Employee",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "HR Manager"
|
|
},
|
|
{
|
|
"parent": "Employee",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "HR User"
|
|
},
|
|
{
|
|
"parent": "Employee",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
},
|
|
{
|
|
"parent": "Employee",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Employee",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-01-09 15:22:29.321581",
|
|
"module": "Asset Lite",
|
|
"name": "MTBF",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "MTBF",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "MTBF",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 1,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "from_date",
|
|
"fieldtype": "Date",
|
|
"label": "From Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "to_date",
|
|
"fieldtype": "Date",
|
|
"label": "To Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.337516",
|
|
"module": "Asset Lite",
|
|
"name": "Technicians working Hours",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Technicians working Hours",
|
|
"report_script": "def execute(filters):\r\n # Define the columns for the report\r\n columns = [\r\n {\"label\": \"Engineer\", \"fieldname\": \"engineer\", \"fieldtype\": \"Link\", \"options\": \"User\", \"width\": 200},\r\n {\"label\": \"Technician Name\", \"fieldname\": \"technician_name\", \"fieldtype\": \"Data\", \"width\": 200}, # New Column\r\n {\"label\": \"Total Hours Spent\", \"fieldname\": \"total_hours\", \"fieldtype\": \"Float\", \"width\": 150}\r\n ]\r\n\r\n # Prepare conditions and parameters\r\n conditions = []\r\n params = {}\r\n\r\n # Add date range filter if provided\r\n if filters.get(\"from_date\") and filters.get(\"to_date\"):\r\n conditions.append(\"t.creation BETWEEN %(start_date)s AND %(end_date)s\")\r\n params[\"start_date\"] = f\"{filters['from_date']} 00:00:00\"\r\n params[\"end_date\"] = f\"{filters['to_date']} 23:59:59\"\r\n\r\n # SQL Query to fetch technician details\r\n query = f\"\"\"\r\n SELECT\r\n t.assigned_technician AS engineer,\r\n u.full_name AS technician_name, -- Fetch Technician's Name from tabUser\r\n SUM(t.total_hours_spent) AS total_hours\r\n FROM\r\n `tabWork_Order` t\r\n LEFT JOIN \r\n `tabUser` u ON u.name = t.assigned_technician\r\n WHERE\r\n t.docstatus = 1\r\n GROUP BY\r\n t.assigned_technician, u.full_name\r\n \"\"\"\r\n\r\n # Execute the query with parameters\r\n result = frappe.db.sql(query, params, as_dict=True)\r\n\r\n return columns, result\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Technicians working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset_name",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 1,
|
|
"options": "Asset",
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.853806",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Hisotry",
|
|
"prepared_report": 0,
|
|
"query": "SELECT \n asset.name AS \"Asset\",\n asset.asset_name AS \"Asset Name\",\n asset.status AS \"Asset Status\",\n asset.location AS \"Location\",\n work_order.name AS \"Work Order\",\n work_order.status AS \"Work Order Status\"\nFROM `tabAsset` asset\nLEFT JOIN `tabAsset Maintenance` maintenance ON maintenance.custom_asset_name = asset.name\nLEFT JOIN `tabWork Order` work_order ON work_order.asset_name = asset.name\n\n\nWHERE %(asset_name)s IS NULL OR asset.name = %(asset_name)s\n",
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Hisotry",
|
|
"report_script": null,
|
|
"report_type": "Query Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Hisotry",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 1,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": "frappe.query_reports[\"Repair Cost\"] = {\n filters: [\n {\n fieldname: \"year\",\n label: __(\"Year\"),\n fieldtype: \"Int\",\n default: new Date().getFullYear(), // Current Year\n reqd: 1 // Make it mandatory\n },\n {\n fieldname: \"month\",\n label: __(\"Month\"),\n fieldtype: \"Select\",\n options: [\n \n \" \", \"January\", \"February\", \"March\", \"April\", \"May\", \"June\",\n \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"\n ],\n default: new Date().toLocaleString('default', { month: 'long' }), // Current Month Name\n reqd: 0 // Make it mandatory\n },\n \n {\n fieldname: \"class\",\n label: __(\"Class\"),\n fieldtype: \"Select\",\n options: [\n \"\",\"Class A\",\"Class B\",\"Class C\"\n ],\n \n },\n {\n fieldname: \"vendor\",\n label: __(\"Vendor\"),\n fieldtype: \"Link\",\n options: \"Supplier\"\n },\n {\n fieldname: \"asset_name\",\n label: __(\"Asset\"),\n fieldtype: \"Link\",\n options: \"Asset\"\n \n },\n {\n fieldname: \"work_order\",\n label: __(\"Work Order\"),\n fieldtype: \"Link\",\n options: \"Work_Order\"\n \n },\n {\n fieldname: \"department\",\n label: __(\"Department\"),\n fieldtype: \"Link\",\n options: \"Department\"\n \n }\n \n \n ]\n};",
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.413060",
|
|
"module": "Asset Lite",
|
|
"name": "Repair Cost Per Asset",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Repair Cost Per Asset",
|
|
"report_script": "\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # Ensure Year is provided\r\n if not filters.get('year'):\r\n frappe.throw(_(\"Please select a Year to proceed.\"))\r\n\r\n def get_days_in_month(year: int, month_name: str) -> int:\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12,\r\n }\r\n month = month_map.get(month_name)\r\n month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\n # Handle leap year for February\r\n if month == 2:\r\n if (int(year) % 4 == 0 and int(year) % 100 != 0) or (int(year) % 400 == 0):\r\n return 29\r\n else:\r\n return 28\r\n else:\r\n return month_days[month - 1]\r\n\r\n def get_dates_of_month(year: int, month_name: str) -> list:\r\n total_days = get_days_in_month(year, month_name)\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12,\r\n }\r\n month = month_map.get(month_name)\r\n return [f\"{year}-{month:02d}-{day:02d}\" for day in range(1, total_days + 1)]\r\n\r\n columns = [\r\n {\"label\": \"Asset\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Link\",\"options\": \"Asset\", \"width\": 200},\r\n {\"label\": \"Work Order\", \"fieldname\": \"work_order\", \"fieldtype\": \"Link\",\"options\": \"Work_Order\", \"width\": 200},\r\n {\"label\": \"Item\", \"fieldname\": \"item_code\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Quantity\", \"fieldname\": \"quantity\", \"fieldtype\": \"Float\", \"width\": 120},\r\n {\"label\": \"Amount\", \"fieldname\": \"amount\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n ]\r\n\r\n result1 = []\r\n year = filters.get('year')\r\n month = filters.get('month')\r\n department = filters.get('department') # Optional department filter\r\n asset_class = filters.get('class') # Optional class filter\r\n vendor = filters.get('vendor') # Optional vendor filter\r\n asset_name = filters.get('asset_name')\r\n work_order = filters.get('work_order')\r\n\r\n \r\n \r\n if asset:\r\n where_conditions.append(\"ar.asset = %(asset)s\") \r\n if work_order:\r\n where_conditions.append(\"ar.name = %(work_order)s\")\r\n\r\n # Construct final WHERE clause\r\n where_clause = \" AND \".join(where_conditions)\r\n\r\n # Fetch data for Work Orders, Material Requests, and Purchase Orders\r\n results = frappe.db.sql(\r\n f\"\"\"\r\n SELECT \r\n ar.name AS work_order, \r\n ar.asset AS asset, \r\n si.item_code, \r\n SUM(si.consumed_quantity) AS quantity, \r\n SUM(si.total_value) AS amount\r\n FROM `tabWork_Order` ar\r\n JOIN `tabAsset Repair Consumed Item` si ON si.parent = ar.name\r\n WHERE {where_clause}\r\n AND ar.creation BETWEEN %(start_date)s AND %(end_date)s\r\n GROUP BY ar.name, ar.asset, si.item_code;\r\n ORDER BY amount ASC\r\n \"\"\",\r\n {\r\n \"start_date\": dates_in_month[0] if month else None,\r\n \"end_date\": dates_in_month[-1] if month else None,\r\n \"year\": year,\r\n \"work_order\": work_order,\r\n \"asset\": asset,\r\n },\r\n as_dict=True\r\n )\r\n\r\n ## Prepare final report data\r\n # for row in results:\r\n # result1.append({\r\n # \"asset_name\": row.get(\"asset_name\"),\r\n # \"work_order\": row.get(\"work_order\"),\r\n # \"item_code\": row.get(\"item_code\"),\r\n # \"quantity\": float(row.get(\"quantity\") or 0),\r\n # \"amount\": float(row.get(\"amount\") or 0),\r\n # })\r\n \r\n for row in results:\r\n if row.get(\"item_code\"): # **Ensures only rows with an item_code are included**\r\n result1.append({\r\n \"asset_name\": row.get(\"asset\"),\r\n \"work_order\": row.get(\"work_order\"),\r\n \"item_code\": row.get(\"item_code\"),\r\n \"quantity\": float(row.get(\"quantity\") or 0),\r\n \"amount\": float(row.get(\"amount\") or 0),\r\n })\r\n\r\n return columns, result1\r\n\r\ndata=execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Repair Cost Per Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [
|
|
{
|
|
"fieldname": "asset_name",
|
|
"fieldtype": "Link",
|
|
"label": "Asset Name",
|
|
"options": null,
|
|
"parent": "Test work_order",
|
|
"parentfield": "columns",
|
|
"parenttype": "Report",
|
|
"width": 0
|
|
}
|
|
],
|
|
"disabled": 1,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset_name",
|
|
"fieldtype": "Link",
|
|
"label": "Asset Name",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Test work_order",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:10.917005",
|
|
"module": "Asset Lite",
|
|
"name": "Test work_order",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Test work_order",
|
|
"report_script": "def execute(filters=None):\r\n # Define columns for the report\r\n columns = [\r\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"fieldname\": \"asset_category\", \"label\": \"Asset Category\", \"fieldtype\": \"Link\", \"options\": \"Asset Category\", \"width\": 120},\r\n {\"fieldname\": \"work_order\", \"label\": \"Work Order\", \"fieldtype\": \"Link\", \"options\": \"Work Order\", \"width\": 120},\r\n {\"fieldname\": \"work_order_status\", \"label\": \"Work Order Status\", \"fieldtype\": \"Select\", \"options\": \"\\nOpen\\nWork In Progress\\nPending Review\\nCompleted\\nCancelled\\nClosed\", \"width\": 120},\r\n {\"fieldname\": \"work_order_type\", \"label\": \"Work Order Type\", \"fieldtype\": \"Link\", \"options\": \"Issue Type\", \"width\": 100},\r\n ]\r\n\r\n # Initialize an empty list to store report data\r\n data = []\r\n asset_name = filters.get(\"asset_name\") \r\n asset_filters = {}\r\n if asset_name:\r\n asset_filters['asset_name'] = asset_name\r\n \r\n\r\n \r\n # Fetch all assets\r\n assets = frappe.get_all(\"Asset\", filters={'name':asset_name},fields=[\"name\", \"asset_name\", \"asset_category\"])\r\n \r\n \r\n\r\n if not assets:\r\n frappe.msgprint(\"No Assets found.\", alert=True)\r\n return columns, data # Return empty report if no assets exist\r\n\r\n # Loop through each asset\r\n for asset in assets:\r\n # Fetch linked Work Orders for the current asset\r\n work_orders = frappe.get_all(\r\n \"Work_Order\",\r\n filters={\"asset\": asset.name}, # Ensure \"asset\" is the correct field linking Work Orders to Assets\r\n fields=[\"name\", \"repair_status\", \"work_order_type\"]\r\n )\r\n\r\n # If there are no work orders, still add the asset details\r\n if not work_orders:\r\n data.append({\r\n \"asset_name\": asset.asset_name,\r\n \"asset_category\": asset.asset_category,\r\n \"work_order\": None,\r\n \"work_order_status\": None,\r\n \"work_order_type\": None\r\n })\r\n else:\r\n # Loop through each work order and add a row to the report\r\n for work_order in work_orders:\r\n data.append({\r\n \"asset_name\": asset.asset_name,\r\n \"asset_category\": asset.asset_category,\r\n \"work_order\": work_order.name,\r\n \"work_order_status\": work_order.repair_status, \r\n \"work_order_type\": work_order.work_order_type\r\n })\r\n\r\n return columns, data\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Test work_order",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Sales Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "PPM Planner",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:10.743010",
|
|
"module": "Asset Lite",
|
|
"name": "PPM Planner",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "PPM Planner",
|
|
"report_script": "def execute(filters=None):\r\n \r\n def get_next_due_date(current_date, periodicity):\r\n \"\"\"Calculate the next due date based on periodicity without imports.\"\"\"\r\n if periodicity == \"Daily\":\r\n return frappe.utils.add_days(current_date, 1)\r\n elif periodicity == \"Weekly\":\r\n return frappe.utils.add_days(current_date, 7)\r\n elif periodicity == \"Monthly\":\r\n return frappe.utils.add_months(current_date, 1)\r\n elif periodicity == \"Quarterly\":\r\n return frappe.utils.add_months(current_date, 3)\r\n elif periodicity == \"Half-yearly\":\r\n return frappe.utils.add_months(current_date, 6)\r\n elif periodicity == \"Yearly\":\r\n return frappe.utils.add_years(current_date, 1)\r\n elif periodicity == \"2 Yearly\":\r\n return frappe.utils.add_years(current_date, 2)\r\n elif periodicity == \"3 Yearly\":\r\n return frappe.utils.add_years(current_date, 3)\r\n else:\r\n return frappe.utils.add_months(current_date, 1) # Default: Monthly\r\n\r\n #if not filters or not filters.get(\"asset\"):\r\n #frappe.throw(\"Please select an Asset to generate the report.\")\r\n\r\n asset_id = filters.get(\"asset\")\r\n\r\n # Fetch maintenance logs with \"Planned\" status\r\n maintenance_logs = frappe.get_all(\r\n \"Asset Maintenance Log\",\r\n filters={\"asset_name\": asset_id, \"maintenance_status\": \"Planned\"},\r\n fields=[\"name\", \"due_date\", \"periodicity\", \"custom_asset_names\",\"asset_name\",\"maintenance_type\",\"assign_to_name\"]\r\n )\r\n\r\n data = []\r\n max_date = frappe.utils.getdate(frappe.utils.add_years(frappe.utils.today(), 5)) # Convert to date object\r\n \r\n for log in maintenance_logs:\r\n due_date = frappe.utils.getdate(log[\"due_date\"]) # Convert to date object\r\n periodicity = log[\"periodicity\"]\r\n \r\n # Fetch Serial Number from Asset\r\n serial_number = frappe.db.get_value(\"Asset\", log[\"asset_name\"], \"custom_serial_number\") or \"N/A\"\r\n\r\n # Generate due dates for the next 5 years\r\n for _ in range(60): # Max 5 years for Monthly periodicity\r\n data.append({\r\n \"asset_name\": log[\"asset_name\"],\r\n \"custom_asset_names\": log[\"custom_asset_names\"],\r\n \"due_date\": due_date,\r\n \"serial_number\": serial_number,\r\n \"periodicity\": log[\"periodicity\"],\r\n \"maintenance_type\": log[\"maintenance_type\"],\r\n \"assign_to_name\": log[\"assign_to_name\"],\r\n \"status\": \"Planned\"\r\n })\r\n \r\n # Calculate next due date\r\n due_date = get_next_due_date(due_date, periodicity)\r\n\r\n # Stop if beyond 5 years\r\n if due_date > max_date:\r\n break\r\n\r\n columns = [\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"custom_asset_names\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Serial Number\", \"fieldname\": \"serial_number\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Due Date\", \"fieldname\": \"due_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"Periodicity\", \"fieldname\": \"periodicity\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Maintenance Type\", \"fieldname\": \"maintenance_type\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Assigned To\", \"fieldname\": \"assign_to_name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Status\", \"fieldname\": \"status\", \"fieldtype\": \"Data\", \"width\": 100},\r\n ]\r\n\r\n return columns, data\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
},
|
|
{
|
|
"parent": "PPM Planner",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "hospital",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "month",
|
|
"fieldtype": "Select",
|
|
"label": "Month",
|
|
"mandatory": 0,
|
|
"options": "\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember",
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Select",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": "\n2020\n2021\n2022\n2023\n2024\n2025\n2026\n2027\n2028\n2029\n2030",
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "supplier",
|
|
"fieldtype": "Link",
|
|
"label": "Supplier",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.063289",
|
|
"module": "Asset Lite",
|
|
"name": "PM Status by Supplier Report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "PM Status by Supplier Report",
|
|
"report_script": "\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n conditions = [\"a.supplier IS NOT NULL AND a.supplier != ''\"]\r\n query_params = {}\r\n \r\n if filters.get(\"hospital\"):\r\n conditions.append(\"aml.custom_hospital_name = %(hospital)s\")\r\n query_params[\"hospital\"] = filters.get(\"hospital\")\r\n\r\n # ✅ Apply Year Filter\r\n if filters.get(\"year\"):\r\n conditions.append(\"YEAR(aml.due_date) = %(year)s\")\r\n query_params[\"year\"] = filters.get(\"year\")\r\n\r\n # ✅ Apply Month Filter\r\n if filters.get(\"month\"):\r\n month_mapping = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12\r\n }\r\n month_num = month_mapping.get(filters.get(\"month\"))\r\n if month_num:\r\n conditions.append(\"MONTH(aml.due_date) = %(month)s\")\r\n query_params[\"month\"] = month_num\r\n\r\n # ✅ Apply Supplier Filter (from Asset Doctype)\r\n if filters.get(\"supplier\"):\r\n conditions.append(\"a.supplier = %(supplier)s\")\r\n query_params[\"supplier\"] = filters.get(\"supplier\")\r\n\r\n # ✅ Construct WHERE Clause\r\n where_clause = \"WHERE \" + \" AND \".join(conditions) if conditions else \"\"\r\n\r\n # ✅ Fetch Summary Counts (Grouped by Supplier)\r\n summary_query = f\"\"\"\r\n SELECT\r\n SUM(CASE WHEN aml.maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS planned,\r\n SUM(CASE WHEN aml.maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS completed,\r\n SUM(CASE WHEN aml.maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS overdue,\r\n COUNT(aml.name) AS total_pm\r\n FROM `tabAsset Maintenance Log` aml\r\n LEFT JOIN `tabAsset` a ON aml.asset_name = a.name\r\n {where_clause}\r\n \"\"\"\r\n summary_data = frappe.db.sql(summary_query, query_params, as_dict=True)\r\n\r\n # ✅ Fetch Supplier-wise Summary for Chart\r\n supplier_query = f\"\"\"\r\n SELECT\r\n a.supplier AS supplier,\r\n SUM(CASE WHEN aml.maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS planned,\r\n SUM(CASE WHEN aml.maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS completed,\r\n SUM(CASE WHEN aml.maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS overdue\r\n FROM `tabAsset Maintenance Log` aml\r\n LEFT JOIN `tabAsset` a ON aml.asset_name = a.name\r\n {where_clause}\r\n GROUP BY a.supplier\r\n \"\"\"\r\n supplier_summary = frappe.db.sql(supplier_query, query_params, as_dict=True)\r\n\r\n # ✅ Fetch Detailed Table Data\r\n details_query = f\"\"\"\r\n SELECT\r\n aml.name AS log_id,\r\n aml.asset_name AS asset_id,\r\n aml.custom_hospital_name AS company,\r\n aml.custom_asset_names AS asset_name,\r\n aml.maintenance_status AS status,\r\n aml.due_date AS due_date,\r\n a.supplier AS supplier,\r\n aml.custom_pm_overdue_reason,\r\n aml.custom_accepted_by_moh,\r\n am.custom_site_contractor,\r\n am.custom_subcontractor,\r\n am.custom_service_coverage,\r\n am.custom_service_agreement,\r\n am.custom_price_per_pm\r\n FROM `tabAsset Maintenance Log` aml\r\n LEFT JOIN `tabAsset` a ON aml.asset_name = a.name\r\n LEFT JOIN `tabAsset Maintenance` am ON aml.asset_maintenance = am.name\r\n {where_clause}\r\n ORDER BY aml.due_date DESC\r\n \"\"\"\r\n table_data = frappe.db.sql(details_query, query_params, as_dict=True)\r\n\r\n # ✅ Define Report Columns\r\n columns = [\r\n {\"label\": \"Log ID\", \"fieldname\": \"log_id\", \"fieldtype\": \"Link\", \"options\": \"Asset Maintenance Log\", \"width\": 150},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Link\", \"options\": \"Supplier\", \"width\": 200},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Data\", \"width\": 120},\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\", \"width\": 250},\r\n {\"label\": \"Maintenance Status\", \"fieldname\": \"status\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Due Date\", \"fieldname\": \"due_date\", \"fieldtype\": \"Date\", \"width\": 150},\r\n {\"label\": \"Price Per PM\", \"fieldname\": \"custom_price_per_pm\", \"fieldtype\": \"Currency\", \"width\": 150},\r\n {\"label\": \"Site Contractor\", \"fieldname\": \"custom_site_contractor\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Subcontractor\", \"fieldname\": \"custom_subcontractor\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Service Coverage\", \"fieldname\": \"custom_service_coverage\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Service Agreement\", \"fieldname\": \"custom_service_agreement\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Overdue Reason\", \"fieldname\": \"custom_pm_overdue_reason\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Accepted By MOH\", \"fieldname\": \"custom_accepted_by_moh\", \"fieldtype\": \"Check\", \"width\": 100},\r\n ]\r\n\r\n # ✅ Prepare Chart Data (Stacked Bar Chart by Supplier)\r\n labels = []\r\n planned_values = []\r\n completed_values = []\r\n overdue_values = []\r\n total_values = [] # New Total Column\r\n \r\n for row in supplier_summary:\r\n labels.append(row[\"supplier\"] or \"Unknown\")\r\n planned = row[\"planned\"] or 0\r\n completed = row[\"completed\"] or 0\r\n overdue = row[\"overdue\"] or 0\r\n \r\n planned_values.append(planned)\r\n completed_values.append(completed)\r\n overdue_values.append(overdue)\r\n total_values.append(planned + completed + overdue) # Sum of all statuses\r\n \r\n # ✅ Define Updated Chart with \"Total\"\r\n chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"Overdue\", \"values\": overdue_values, \"chartType\": \"bar\", \"color\": \"red\"},\r\n {\"name\": \"Planned\", \"values\": planned_values, \"chartType\": \"bar\", \"color\": \"orange\"},\r\n {\"name\": \"Completed\", \"values\": completed_values, \"chartType\": \"bar\", \"color\": \"green\"},\r\n {\"name\": \"Total\", \"values\": total_values, \"chartType\": \"bar\", \"color\": \"blue\"}, # ✅ New Total Bar\r\n ]\r\n },\r\n \"type\": \"bar\",\r\n \"barOptions\": {\r\n \"stacked\": True # ✅ Stack all bars including Total\r\n }\r\n }\r\n\r\n\r\n # ✅ Prepare Report Summary Data\r\n report_summary = [\r\n {\"label\": \"Planned\", \"value\": summary_data[0][\"planned\"], \"indicator\": \"orange\"},\r\n {\"label\": \"Completed\", \"value\": summary_data[0][\"completed\"], \"indicator\": \"green\"},\r\n {\"label\": \"Overdue\", \"value\": summary_data[0][\"overdue\"], \"indicator\": \"red\"},\r\n {\"label\": \"Total PM\", \"value\": summary_data[0][\"total_pm\"], \"indicator\": \"blue\"}\r\n ]\r\n\r\n return columns, table_data, None, chart, report_summary\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "PM Status by Supplier Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "month",
|
|
"fieldtype": "Select",
|
|
"label": "Month",
|
|
"mandatory": 0,
|
|
"options": "\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember",
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Select",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": "\n2020\n2021\n2022\n2023\n2024\n2025\n2026\n2027\n2028\n2029\n2030",
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "supplier",
|
|
"fieldtype": "Link",
|
|
"label": "Supplier",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset ID",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.171324",
|
|
"module": "Asset Lite",
|
|
"name": "Suppliers Repair Cost Report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Suppliers Repair Cost Report",
|
|
"report_script": "def execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # Define Filters\r\n filters_dict = {}\r\n\r\n # Apply Company, Asset, and Supplier Filters\r\n if filters.get(\"company\"):\r\n filters_dict[\"company\"] = filters.get(\"company\")\r\n if filters.get(\"asset\"):\r\n filters_dict[\"asset\"] = filters.get(\"asset\")\r\n if filters.get(\"supplier\"):\r\n filters_dict[\"supplier\"] = filters.get(\"supplier\")\r\n\r\n # Apply Month & Year Filters\r\n if filters.get(\"year\"):\r\n year_num = int(filters[\"year\"]) # Ensure it's an integer\r\n\r\n if filters.get(\"month\"):\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12\r\n }\r\n month_num = month_map.get(filters[\"month\"])\r\n\r\n if month_num:\r\n first_day = f\"{year_num}-{month_num:02d}-01\"\r\n last_day = frappe.utils.get_last_day(first_day)\r\n filters_dict[\"creation\"] = [\"between\", [first_day, last_day]]\r\n else:\r\n first_day = f\"{year_num}-01-01\"\r\n last_day = f\"{year_num}-12-31\"\r\n filters_dict[\"creation\"] = [\"between\", [first_day, last_day]]\r\n\r\n # Fetch Work Orders with Filters\r\n work_orders = frappe.get_all(\r\n \"Work_Order\",\r\n filters=filters_dict,\r\n fields=[\r\n \"name\", \"company\", \"work_order_type\", \"repair_status\", \"total_repair_cost\",\r\n \"completion_date\", \"first_responded_on\", \"custom_deadline_date\", \"failure_date\",\r\n \"supplier\", \"serial_number\", \"asset_name\", \"repair_cost\", \"asset\",\r\n \"assigned_technician\", \"custom_maintenance_manager\", \"custom_priority_\", \"creation\"\r\n ],\r\n order_by=\"creation desc\"\r\n )\r\n\r\n # Define Report Columns\r\n columns = [\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Work Order No\", \"fieldname\": \"name\", \"fieldtype\": \"Link\", \"options\": \"Work_Order\", \"width\": 150},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Data\", \"width\": 120},\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 120},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\", \"width\": 180},\r\n \r\n {\"label\": \"Priority\", \"fieldname\": \"custom_priority_\", \"fieldtype\": \"Data\", \"width\": 100},\r\n {\"label\": \"Work Order Type\", \"fieldname\": \"work_order_type\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Repair Status\", \"fieldname\": \"repair_status\", \"fieldtype\": \"Data\", \"width\": 120},\r\n {\"label\": \"Spare Used - Qty\", \"fieldname\": \"spares_used\", \"fieldtype\": \"Data\", \"width\": 250},\r\n {\"label\": \"Spare Cost (SAR)\", \"fieldname\": \"spare_cost\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n {\"label\": \"Purchase Items - Qty\", \"fieldname\": \"invoice_items\", \"fieldtype\": \"Data\", \"width\": 170},\r\n {\"label\": \"Purchase Cost (SAR)\", \"fieldname\": \"repair_cost\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n {\"label\": \"Total Repair Cost (SAR)\", \"fieldname\": \"total_repair_cost\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n \r\n {\"label\": \"Failure Date\", \"fieldname\": \"failure_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"First Responded\", \"fieldname\": \"first_responded_on\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"Completion Date\", \"fieldname\": \"completion_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"Deadline Date\", \"fieldname\": \"custom_deadline_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"Serial Number\", \"fieldname\": \"serial_number\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Assigned To\", \"fieldname\": \"custom_maintenance_manager\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Created On\", \"fieldname\": \"creation\", \"fieldtype\": \"Datetime\", \"width\": 150}\r\n ]\r\n\r\n # Fetch Spare Parts for Each Work Order\r\n for wo in work_orders:\r\n spare_parts = frappe.get_all(\r\n \"Asset Repair Consumed Item\",\r\n filters={\"parent\": wo[\"name\"]},\r\n fields=[\"item_code\", \"consumed_quantity\"]\r\n )\r\n\r\n if spare_parts:\r\n wo[\"spares_used\"] = \"\\n\".join([f\"{sp['item_code']} - {sp['consumed_quantity']}\" for sp in spare_parts])\r\n else:\r\n wo[\"spares_used\"] = \"\"\r\n\r\n # Fetch Purchase Invoice linked to Work Order\r\n invoice_links = frappe.get_all(\r\n \"PI Table\",\r\n filters={\"parent\": wo[\"name\"]},\r\n fields=[\"purchase_invoice\"]\r\n )\r\n\r\n invoice_items_list = []\r\n for invoice in invoice_links:\r\n if invoice[\"purchase_invoice\"]:\r\n items = frappe.get_all(\r\n \"Purchase Invoice Item\",\r\n filters={\"parent\": invoice[\"purchase_invoice\"]},\r\n fields=[\"item_code\", \"qty\"]\r\n )\r\n invoice_items_list.extend([f\"{item['item_code']} - {item['qty']}\" for item in items])\r\n\r\n wo[\"invoice_items\"] = \"\\n\".join(invoice_items_list) if invoice_items_list else \" \"\r\n\r\n # Calculate Spare Cost = Total Repair Cost - Purchase Cost\r\n wo[\"spare_cost\"] = (wo.get(\"total_repair_cost\") or 0) - (wo.get(\"repair_cost\") or 0)\r\n\r\n # ✅ Fetch Supplier-wise Total Repair Cost\r\n supplier_query = \"\"\"\r\n SELECT supplier, SUM(total_repair_cost) AS total_repair_cost\r\n FROM `tabWork_Order`\r\n WHERE supplier IS NOT NULL AND supplier != ''\r\n \"\"\"\r\n\r\n # ✅ Apply Supplier Filter if Selected\r\n if filters.get(\"supplier\"):\r\n supplier_query =supplier_query + \" AND supplier = %(supplier)s\"\r\n supplier_query =supplier_query + \" GROUP BY supplier ORDER BY total_repair_cost DESC\"\r\n\r\n supplier_data = frappe.db.sql(supplier_query, filters, as_dict=True)\r\n\r\n # ✅ Prepare Chart Data (Filtered by Supplier)\r\n supplier_labels = []\r\n repair_cost_values = []\r\n\r\n for row in supplier_data:\r\n supplier_labels.append(row[\"supplier\"])\r\n repair_cost_values.append(row[\"total_repair_cost\"])\r\n\r\n chart = {\r\n \"data\": {\r\n \"labels\": supplier_labels,\r\n \"datasets\": [\r\n {\r\n \"name\": \"Total Repair Cost\",\r\n \"values\": repair_cost_values,\r\n \"chartType\": \"bar\",\r\n \"color\": \"blue\"\r\n }\r\n ]\r\n },\r\n \"type\": \"bar\",\r\n \"barOptions\": {\r\n \"stacked\": False # Not stacked, just a simple bar chart\r\n }\r\n }\r\n\r\n return columns, work_orders, None, chart\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Suppliers Repair Cost Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Sales Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.219083",
|
|
"module": "Asset Lite",
|
|
"name": "Work_order department wise",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Work_order department wise",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n department = filters.get(\"department\")\r\n\r\n # Query to fetch work orders, their departments, status, and work order type\r\n if department:\r\n query = \"\"\"\r\n SELECT\r\n name,\r\n department,\r\n repair_status,\r\n work_order_type\r\n FROM\r\n `tabWork_Order`\r\n WHERE\r\n department = %s\r\n ORDER BY\r\n name\r\n \"\"\"\r\n result = frappe.db.sql(query, department, as_dict=True)\r\n sql1 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Open' AND department = %s\"\"\"\r\n sql2 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Work In Progress' AND department = %s\"\"\"\r\n sql3 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Pending Review' AND department = %s\"\"\"\r\n sql4 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Completed' AND department = %s\"\"\"\r\n sql5 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Closed' AND department = %s\"\"\"\r\n sql6 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Open', 'Work In Progress', 'Pending Review', 'Completed', 'Closed', 'Cancelled') AND department = %s\"\"\"\r\n report_summary = [\r\n {\"value\": row.count, \"label\": \"Open\"} for row in frappe.db.sql(sql1, (department,), as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Work In Progress\"} for row in frappe.db.sql(sql2, (department,), as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Pending Review\"} for row in frappe.db.sql(sql3, (department,), as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Completed\"} for row in frappe.db.sql(sql4, (department,), as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Closed\"} for row in frappe.db.sql(sql5, (department,), as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Total Work Orders\"} for row in frappe.db.sql(sql6, (department,), as_dict=True)\r\n ]\r\n\r\n else:\r\n # If no department is selected, return all work orders\r\n query_no_department = \"\"\"\r\n SELECT\r\n name,\r\n department,\r\n repair_status,\r\n work_order_type\r\n FROM\r\n `tabWork_Order`\r\n ORDER BY\r\n name\r\n \"\"\"\r\n result = frappe.db.sql(query_no_department, as_dict=True)\r\n sql1 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Open'\"\"\"\r\n sql2 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Work In Progress'\"\"\"\r\n sql3 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Pending Review'\"\"\"\r\n sql4 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Completed'\"\"\"\r\n sql5 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Closed'\"\"\"\r\n sql6 = \"\"\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Open', 'Work In Progress', 'Pending Review', 'Completed', 'Closed', 'Cancelled')\"\"\"\r\n report_summary = [\r\n {\"value\": row.count, \"label\": \"Open\"} for row in frappe.db.sql(sql1, as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Work In Progress\"} for row in frappe.db.sql(sql2, as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Pending Review\"} for row in frappe.db.sql(sql3, as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Completed\"} for row in frappe.db.sql(sql4, as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Closed\"} for row in frappe.db.sql(sql5, as_dict=True)\r\n ] + [\r\n {\"value\": row.count, \"label\": \"Total Work Orders\"} for row in frappe.db.sql(sql6, as_dict=True)\r\n ]\r\n\r\n # Create a dictionary to count work orders per work order type and status\r\n work_order_type_status_count = {}\r\n \r\n for row in result:\r\n work_order_type = row['work_order_type']\r\n status = row['repair_status']\r\n if work_order_type not in work_order_type_status_count:\r\n work_order_type_status_count[work_order_type] = {}\r\n if status in work_order_type_status_count[work_order_type]:\r\n work_order_type_status_count[work_order_type][status] = work_order_type_status_count[work_order_type][status] + 1 # Increment count for the status\r\n else:\r\n work_order_type_status_count[work_order_type][status] = 1 # Initialize count for the status\r\n\r\n # Prepare data for the chart\r\n chart_labels = list(work_order_type_status_count.keys()) # Work order type names\r\n chart_datasets = []\r\n\r\n # Collect unique statuses across all work order types\r\n unique_statuses = set()\r\n for statuses in work_order_type_status_count.values():\r\n unique_statuses.update(statuses.keys())\r\n unique_statuses = sorted(unique_statuses) # Sort statuses alphabetically\r\n\r\n # Prepare datasets for each status\r\n for status in unique_statuses:\r\n values = []\r\n for work_order_type in chart_labels:\r\n values.append(work_order_type_status_count[work_order_type].get(status, 0))\r\n \r\n chart_datasets.append({\r\n \"name\": status, # Status name\r\n \"values\": values # Counts per work order type\r\n })\r\n\r\n # Define the columns to be displayed in the report\r\n columns = [\r\n {\"fieldname\": \"name\", \"label\": \"Work Order ID\", \"fieldtype\": \"Link\", \"options\": \"Work Order\", \"width\": 200},\r\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\", \"options\": \"Department\", \"width\": 150},\r\n {\"fieldname\": \"repair_status\", \"label\": \"Status\", \"fieldtype\": \"Data\", \"width\": 100},\r\n {\"fieldname\": \"work_order_type\", \"label\": \"Work Order Type\", \"fieldtype\": \"Data\", \"width\": 150},\r\n ]\r\n \r\n # Configure the chart to show the count of work orders per work order type and status\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Work order type names\r\n \"datasets\": chart_datasets # Each dataset corresponds to a status\r\n },\r\n \"type\": \"bar\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#CCCCB7\", \"#52B2BF\", \"#9EC1A4\", \"#058D7C\", \"#A3A5CF\"] # Customize the colors as needed\r\n }\r\n\r\n return columns, result, None, chart, report_summary\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Work_order department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset Maintenance Assignees Status Count Department",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.180938",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Assignees Status Count Department",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset Maintenance Assignees Status Count Department",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n department = filters.get(\"department\")\r\n\r\n # Base query with a JOIN\r\n query = \"\"\"\r\n SELECT \r\n a.department,\r\n aml.item_name AS \"Item Name\", \r\n aml.maintenance_status AS \"Maintenance Status\", \r\n aml.assign_to_name AS \"Assigned To\", \r\n \r\n SUM(CASE \r\n WHEN aml.due_date = aml.completion_date AND aml.maintenance_status ='Completed' THEN 1 \r\n ELSE 0 \r\n END) AS \"Completed On Time\",\r\n SUM(CASE \r\n WHEN aml.completion_date < aml.due_date AND aml.maintenance_status = 'Completed' THEN 1 \r\n ELSE 0 \r\n END) AS \"Completed Within Time\",\r\n SUM(CASE \r\n WHEN aml.completion_date > aml.due_date THEN 1 \r\n ELSE 0 \r\n END) AS \"Delay In Completion\",\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Planned' AND aml.completion_date IS NULL AND aml.due_date > CURRENT_DATE() THEN 1 \r\n ELSE 0 \r\n END) AS \"Pending\",\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Planned' AND aml.completion_date IS NULL AND aml.due_date < CURRENT_DATE() THEN 1 \r\n ELSE 0 \r\n END) AS \"Overdue\", \r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Cancelled' THEN 1 \r\n ELSE 0 \r\n END) AS \"Cancelled\" \r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n JOIN \r\n `tabAsset` a ON aml.asset_maintenance = a.name -- Adjust the join condition based on your actual field names\r\n \"\"\"\r\n\r\n # Conditional filter for department\r\n if department:\r\n query =query+ \" WHERE a.department = %s\" # Filter by department from the Asset table\r\n query_params = (department,)\r\n else:\r\n query_params = ()\r\n\r\n # Complete query\r\n query =query+ \" GROUP BY aml.assign_to_name\"\r\n\r\n # Execute the query\r\n result = frappe.db.sql(query, query_params, as_dict=True)\r\n\r\n # Define the columns\r\n columns = [\r\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\", \"options\": \"Department\", \"width\": 200},\r\n {\"fieldname\": \"Item Name\", \"label\": \"Item Name\", \"fieldtype\": \"Link\", \"options\": \"Employee\", \"width\": 200},\r\n {\"fieldname\": \"Maintenance Status\", \"label\": \"Maintenance Status\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"fieldname\": \"Assigned To\", \"label\": \"Assigned To\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Completed On Time\", \"label\": \"Completed On Time\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"fieldname\": \"Completed Within Time\", \"label\": \"Completed Within Time\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"fieldname\": \"Delay In Completion\", \"label\": \"Delay In Completion\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"fieldname\": \"Pending\", \"label\": \"Pending\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"fieldname\": \"Overdue\", \"label\": \"Overdue\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Cancelled\", \"label\": \"Cancelled\", \"fieldtype\": \"Int\", \"width\": 150},\r\n ] \r\n\r\n return columns, result # Return both columns and result\r\ndata = execute (filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Assignees Status Count Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignees Status Count Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignees Status Count Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset wise Count Department",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.142399",
|
|
"module": "Asset Lite",
|
|
"name": "Asset wise Count Department",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset wise Count Department",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n department = filters.get(\"department\")\r\n\r\n # Base query with a JOIN\r\n query = \"\"\"\r\n select \r\n a.department,\r\n aml.item_name AS \"Item Name\", \r\n aml.maintenance_status AS \"Maintenance Status\", \r\n sum(case when due_date = completion_date AND maintenance_status ='Completed' then 1 else 0 end) as \"Completed On Time\" ,\r\n sum(case when completion_date < due_date and maintenance_status = 'Completed' then 1 else 0 end) as \"Completed Within Time\",\r\n sum(case when completion_date >due_date then 1 else 0 end ) as \"Delay In Completion\",\r\n sum(case when maintenance_status = 'Planned' AND completion_date IS null AND due_date > current_date() then 1 else 0 end ) as \"Pending\",\r\n sum(case when maintenance_status = 'Planned' AND completion_date IS null AND due_date < current_date() then 1 else 0 end) as \"Overdue\" , \r\n sum(case when maintenance_status = 'Cancelled' then 1 else 0 end) as \"Cancelled\" \r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n JOIN \r\n `tabAsset` a ON aml.asset_maintenance = a.name -- Adjust the join condition based on your actual field names\r\n \"\"\"\r\n \r\n \r\n # Conditional filter for department\r\n if department:\r\n query =query+ \" WHERE a.department = %s\" # Filter by department from the Asset table\r\n query_params = (department,)\r\n else:\r\n query_params = ()\r\n query =query+ \" GROUP BY aml.item_name\"\r\n \r\n\r\n # Execute the query\r\n result = frappe.db.sql(query, query_params, as_dict=True)\r\n\r\n # Define the columns\r\n columns = [\r\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\", \"options\": \"Department\", \"width\": 200},\r\n {\"fieldname\": \"Item Name\", \"label\": \"Item Name\", \"fieldtype\": \"Link\", \"options\": \"Employee\", \"width\": 200},\r\n {\"fieldname\": \"Maintenance Status\", \"label\": \"Maintenance Status\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"fieldname\": \"Completed On Time\", \"label\": \"Completed On Time\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Completed Within Time\", \"label\": \"Completed Within Time\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"fieldname\": \"Delay In Completion\", \"label\": \"Delay In Completion\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"fieldname\": \"Pending\", \"label\": \"Pending\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"fieldname\": \"Overdue\", \"label\": \"Overdue\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Cancelled\", \"label\": \"Cancelled\", \"fieldtype\": \"Int\", \"width\": 150},\r\n ] \r\n\r\n return columns, result # Return both columns and result\r\ndata = execute (filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset wise Count Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset wise Count Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset wise Count Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "support_plan",
|
|
"fieldtype": "Link",
|
|
"label": "Support Plan",
|
|
"mandatory": 0,
|
|
"options": "Support Plans",
|
|
"parent": "Support Plan",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.979434",
|
|
"module": "Asset Lite",
|
|
"name": "Support Plan",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Support Plans",
|
|
"reference_report": null,
|
|
"report_name": "Support Plan",
|
|
"report_script": "def execute(filters=None):\r\n columns = [\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\"},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Link\", \"options\": \"Supplier\"},\r\n {\"label\": \"Class\", \"fieldname\": \"class\", \"fieldtype\": \"Data\"}\r\n ]\r\n \r\n result = []\r\n\r\n # Define the class filter\r\n asset_class_filter = \"Class A\"\r\n\r\n # Fetch Assets where class is \"Class A\"\r\n assets = frappe.get_all('Asset', filters={'custom_class': asset_class_filter}, \r\n fields=['name as asset_id', 'asset_name', 'supplier', 'custom_class'])\r\n\r\n # Append each asset to the result\r\n for asset in assets:\r\n result.append({\r\n \"asset_id\": asset['asset_id'],\r\n \"asset_name\": asset['asset_name'],\r\n \"supplier\": asset['supplier'],\r\n \"class\": asset['custom_class']\r\n })\r\n\r\n return columns, result\r\ndata = execute(filters=None)\r\n\r\n\r\n\r\n\r\ndef execute(filters):\r\n columns = [\r\n {\"label\": \"Support Plan Name\", \"fieldname\": \"support_plan_name\", \"fieldtype\": \"Link\", \"options\": \"Support Plans\"},\r\n {\"label\": \"Frequency\", \"fieldname\": \"frequency\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Warranty\", \"fieldname\": \"warranty\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Service Contract\", \"fieldname\": \"service_contract\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Comprehensive\", \"fieldname\": \"spare_parts\", \"fieldtype\": \"Check\"},\r\n {\"label\": \"Spare Parts & Labour\", \"fieldname\": \"spare_parts_labour\", \"fieldtype\": \"Check\"},\r\n {\"label\": \"Labour Only\", \"fieldname\": \"labour\", \"fieldtype\": \"Check\"},\r\n {\"label\": \"PPM Only\", \"fieldname\": \"ppm_only\", \"fieldtype\": \"Check\"},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Warranty Start Date\", \"fieldname\": \"custom_warranty_start_date\", \"fieldtype\": \"Date\"},\r\n {\"label\": \"Warranty End Date\", \"fieldname\": \"custom_warranty_end_date\", \"fieldtype\": \"Date\"},\r\n {\"label\": \"Service Start Date\", \"fieldname\": \"custom_service_contract_start\", \"fieldtype\": \"Date\"},\r\n {\"label\": \"Service End Date\", \"fieldname\": \"custom_service_contract_end\", \"fieldtype\": \"Date\"}\r\n ]\r\n \r\n result = []\r\n\r\n # Check if a filter is applied\r\n support_plan_filter = filters.get(\"support_plan\") if filters and \"support_plan\" in filters else None\r\n\r\n # Fetch Support Plans based on the filter if applied, else fetch all\r\n support_plan_filters = {}\r\n if support_plan_filter:\r\n support_plan_filters[\"name\"] = support_plan_filter\r\n \r\n support_plans = frappe.get_all('Support Plans', filters=support_plan_filters, fields=['name', 'frequency', 'warranty', 'service_contract', 'spare_parts', \"spare_parts_labour\", \"labour\", \"ppm_only\"])\r\n \r\n for plan in support_plans:\r\n \r\n # Convert 1/0 to Yes/No for boolean fields\r\n warranty_status = \"Yes\" if plan['warranty'] == 1 else \"No\"\r\n service_contract_status = \"Yes\" if plan['service_contract'] == 1 else \"No\"\r\n \r\n # Get Assets related to the Support Plan\r\n assets = frappe.get_all('Asset', filters={'custom_support_plan': plan['name']}, fields=['asset_name', 'name', 'custom_warranty_start_date', 'custom_warranty_end_date', 'custom_service_contract_start', 'custom_service_contract_end'])\r\n \r\n if assets:\r\n # Use the first asset in the same row as the support plan details\r\n first_asset = assets[0]\r\n result.append({\r\n \"support_plan_name\": plan['name'],\r\n \"frequency\": plan['frequency'],\r\n \"warranty\": plan['warranty'],\r\n \"service_contract\": plan['service_contract'],\r\n \"spare_parts\": plan['spare_parts'],\r\n \"spare_parts_labour\": plan['spare_parts_labour'],\r\n \"labour\": plan['labour'],\r\n \"ppm_only\": plan['ppm_only'],\r\n \"asset_id\": first_asset['asset_name'],\r\n \"asset_name\": first_asset['name'],\r\n \"custom_warranty_start_date\": first_asset['custom_warranty_start_date'],\r\n \"custom_warranty_end_date\": first_asset['custom_warranty_end_date'],\r\n \"custom_service_contract_start\": first_asset['custom_service_contract_start'],\r\n \"custom_service_contract_end\": first_asset['custom_service_contract_end']\r\n })\r\n \r\n # Add any remaining assets as separate rows\r\n for asset in assets[1:]:\r\n result.append({\r\n \"support_plan_name\": \"\", # Leave support plan name empty for subsequent asset rows\r\n \"frequency\": \"\",\r\n \"warranty\": \"\",\r\n \"service_contract\": \"\",\r\n \"spare_parts\": 0,\r\n \"spare_parts_labour\": 0,\r\n \"labour\": 0,\r\n \"ppm_only\": 0,\r\n \"asset_id\": asset['asset_name'],\r\n \"asset_name\": asset['name'],\r\n \"custom_warranty_start_date\": asset['custom_warranty_start_date'],\r\n \"custom_warranty_end_date\": asset['custom_warranty_end_date'],\r\n \"custom_service_contract_start\": asset['custom_service_contract_start'],\r\n \"custom_service_contract_end\": asset['custom_service_contract_end']\r\n })\r\n else:\r\n # If there are no assets, show the support plan details with empty asset fields\r\n result.append({\r\n \"support_plan_name\": plan['name'],\r\n \"frequency\": plan['frequency'],\r\n \"warranty\": plan['warranty'],\r\n \"service_contract\": plan['service_contract'],\r\n \"spare_parts\": plan['spare_parts'],\r\n \"spare_parts_labour\": plan['spare_parts_labour'],\r\n \"labour\": plan['labour'],\r\n \"ppm_only\": plan['ppm_only'],\r\n \"asset_id\": None,\r\n \"asset_name\": None,\r\n \"custom_warranty_start_date\": None,\r\n \"custom_warranty_end_date\": None,\r\n \"custom_service_contract_start\": None,\r\n \"custom_service_contract_end\": None\r\n })\r\n \r\n return columns, result\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Support Plan",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Support Plan",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Support Plan",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Support Plan",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-02-18 09:20:47.386840",
|
|
"module": "Asset Lite",
|
|
"name": "Maintenance Percentage of Replacement Asset Value (MPRAV)",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Maintenance Percentage of Replacement Asset Value (MPRAV)",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Maintenance Percentage of Replacement Asset Value (MPRAV)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Maintenance Percentage of Replacement Asset Value (MPRAV)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Stock User"
|
|
},
|
|
{
|
|
"parent": "Maintenance Percentage of Replacement Asset Value (MPRAV)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:10.855537",
|
|
"module": "Asset Lite",
|
|
"name": "Technicians Avg",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Feedback",
|
|
"reference_report": null,
|
|
"report_name": "Technicians Avg",
|
|
"report_script": "\r\ndef execute(filters=None):\r\n columns= [\r\n {\"label\": \"Technician\", \"fieldname\": \"technician\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Total Feedbacks\", \"fieldname\": \"total_feedbacks\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"label\": \"Raw Avg Rating\", \"fieldname\": \"avg_rating\", \"fieldtype\": \"Float\", \"width\": 150}, # Rating field type\r\n {\"label\": \"Avg Rating (%)\", \"fieldname\": \"rating_percentage\", \"fieldtype\": \"Percent\", \"width\": 150}\r\n ]\r\n\r\n\r\n technician_ratings = {}\r\n\r\n # Fetch feedback data\r\n feedbacks = frappe.get_all(\r\n \"Feedback\",\r\n filters={},\r\n fields=[\"work_order\", \"overall\"]\r\n )\r\n\r\n for feedback in feedbacks:\r\n # Fetch the assigned technician from the Work Order\r\n work_order = frappe.db.get_value(\"Work_Order\", feedback[\"work_order\"], \"assigned_technician\")\r\n\r\n if not work_order:\r\n continue # Skip if no technician assigned\r\n\r\n technician = work_order\r\n\r\n if technician not in technician_ratings:\r\n technician_ratings[technician] = {\"total_rating\": 0, \"count\": 0}\r\n\r\n # Fix for rating field normalization (0-1 scale) → Convert to 5-point scale\r\n rating_value = feedback[\"overall\"] * 5\r\n\r\n technician_ratings[technician][\"total_rating\"] =technician_ratings[technician][\"total_rating\"]+ rating_value\r\n technician_ratings[technician][\"count\"] = technician_ratings[technician][\"count\"]+1\r\n\r\n # Convert into report data format\r\n report_data = []\r\n for technician, rating_data in technician_ratings.items():\r\n total_feedbacks = rating_data[\"count\"]\r\n avg_rating = (rating_data[\"total_rating\"] / total_feedbacks) if total_feedbacks else 0\r\n rating_percentage = (avg_rating / 5) * 100 # Convert to percentage\r\n\r\n report_data.append({\r\n \"technician\": technician,\r\n \"total_feedbacks\": total_feedbacks,\r\n \"avg_rating\": avg_rating, # Raw avg rating\r\n \"rating_percentage\": rating_percentage # Percentage\r\n })\r\n\r\n return columns,report_data\r\n \r\ndata=execute(filters=None)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Technicians Avg",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Technicians Avg",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Technicians Avg",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.360974",
|
|
"module": "Asset Lite",
|
|
"name": "Total Hrs and Downtime Hrs by Asset",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Total Hrs and Downtime Hrs by Asset",
|
|
"report_script": "def execute(filters):\r\n columns = [\r\n {\"label\": \"\", \"fieldname\": \"name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Total Hours of All Assets\", \"fieldname\": \"total_hours_sum\", \"fieldtype\": \"Float\"},\r\n {\"label\": \"Total Downtime Hours of All Assets\", \"fieldname\": \"downtime_hours_sum\", \"fieldtype\": \"Float\"},\r\n {\"label\": \"Total Uptime Hours of All Assets\", \"fieldname\": \"uptime_hours_sum\", \"fieldtype\": \"Float\"}\r\n ]\r\n \r\n result = []\r\n \r\n # Get the department and class filters from the input\r\n department = filters.get(\"department\") if filters else None\r\n asset_class = filters.get(\"class\") if filters else None\r\n asset_name = filters.get(\"asset\") if filters else None\r\n \r\n # Build the filter conditions based on the department and class filters\r\n asset_filters = {}\r\n if department:\r\n asset_filters['department'] = department\r\n if asset_class:\r\n asset_filters['custom_class'] = asset_class\r\n if asset_name:\r\n asset_filters['name'] = asset_name\r\n \r\n # Fetch all assets with their total hours and downtime hours based on filters\r\n assets = frappe.get_all('Asset', filters=asset_filters, fields=['custom_total_hours', 'custom_down_time'])\r\n \r\n # Initialize sums\r\n total_hours_sum = round(sum(asset['custom_total_hours'] or 0 for asset in assets))\r\n downtime_hours_sum = round(sum(asset['custom_down_time'] or 0 for asset in assets))\r\n uptime_hours_sum = round(total_hours_sum - downtime_hours_sum)\r\n \r\n if total_hours_sum == 0:\r\n total_hours_sum = downtime_hours_sum\r\n uptime_hours_sum = round(total_hours_sum - downtime_hours_sum)\r\n \r\n \r\n \r\n # Add the sums to the result\r\n result.append({\r\n \"name\":\"Hours\",\r\n \"total_hours_sum\": total_hours_sum,\r\n \"downtime_hours_sum\": downtime_hours_sum,\r\n \"uptime_hours_sum\": uptime_hours_sum\r\n })\r\n \r\n return columns, result\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset Maintenance Frequency Department",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "name",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Asset Maintenance Frequency Department",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:10.886475",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Frequency Department",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset Maintenance Frequency Department",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n department = filters.get(\"department\")\r\n\r\n # Define the query\r\n if department:\r\n query = \"\"\"\r\n SELECT\r\n a.department,\r\n aml.item_name AS item,\r\n SUM(CASE WHEN maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS Planned,\r\n SUM(CASE WHEN maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS Completed,\r\n SUM(CASE WHEN maintenance_status = 'Cancelled' THEN 1 ELSE 0 END) AS Cancelled,\r\n SUM(CASE WHEN maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS Overdue,\r\n COUNT(aml.item_name) AS `Total Count`\r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n JOIN \r\n `tabAsset` a ON aml.asset_maintenance = a.name \r\n WHERE\r\n department = %s\r\n GROUP BY\r\n aml.item_name\r\n \"\"\"\r\n result = frappe.db.sql(query, (department,), as_dict=True)\r\n\r\n else:\r\n query = \"\"\"\r\n SELECT\r\n a.department,\r\n aml.item_name AS item,\r\n SUM(CASE WHEN maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS Planned,\r\n SUM(CASE WHEN maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS Completed,\r\n SUM(CASE WHEN maintenance_status = 'Cancelled' THEN 1 ELSE 0 END) AS Cancelled,\r\n SUM(CASE WHEN maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS Overdue,\r\n COUNT(aml.item_name) AS `Total Count`\r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n JOIN \r\n `tabAsset` a ON aml.asset_maintenance = a.name \r\n GROUP BY\r\n aml.item_name\r\n \"\"\"\r\n result = frappe.db.sql(query, as_dict=True)\r\n\r\n # Define the columns for the report\r\n columns = [\r\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\",\"options\":\"Department\", \"width\": 150},\r\n {\"fieldname\": \"item\", \"label\": \"Item Name\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"fieldname\": \"Planned\", \"label\": \"Planned\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Completed\", \"label\": \"Completed\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Cancelled\", \"label\": \"Cancelled\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Overdue\", \"label\": \"Overdue\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"fieldname\": \"Total Count\", \"label\": \"Total Count\", \"fieldtype\": \"Int\", \"width\": 100}\r\n ]\r\n\r\n return columns, result\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Frequency Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Frequency Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Frequency Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Frequency Department",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "supplier",
|
|
"fieldtype": "Link",
|
|
"label": "Supplier",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "Supplier Score",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2024-12-19 13:04:47.947899",
|
|
"module": "Asset Lite",
|
|
"name": "Supplier Score",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Supplier Score",
|
|
"report_script": "",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Supplier Score",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2024-12-19 12:25:59.662186",
|
|
"module": "Asset Lite",
|
|
"name": "Supplier Down Time",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Supplier Down Time",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Supplier Down Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": "{}",
|
|
"letter_head": "Test",
|
|
"modified": "2025-01-07 22:30:21.848955",
|
|
"module": "Asset Lite",
|
|
"name": "Preventive maintenance compliance (PMC)",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Preventive maintenance compliance (PMC)",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Preventive maintenance compliance (PMC)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Preventive maintenance compliance (PMC)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Preventive maintenance compliance (PMC)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.387931",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Count (Supplier) by Asset",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Count (Supplier) by Asset",
|
|
"report_script": "\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n result = []\r\n asset = filters.get(\"asset\") # Fetch asset filter\r\n\r\n # SQL Query to fetch asset details\r\n if asset:\r\n query = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n custom_serial_number\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n name = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, (asset,), as_dict=True)\r\n else:\r\n # If no asset filter is applied, return all assets\r\n query_all = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n custom_serial_number\r\n FROM\r\n `tabAsset`\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query_all, as_dict=True)\r\n\r\n # Create a dictionary to count occurrences of each asset\r\n asset_count = {}\r\n\r\n for row in result:\r\n asset_name = row['asset_name']\r\n asset_count[asset_name] = asset_count.get(asset_name, 0) + 1\r\n\r\n # Prepare data for the chart\r\n chart_labels = list(asset_count.keys()) # Asset names\r\n chart_values = list(asset_count.values()) # Count of assets\r\n\r\n # Define the columns for the report\r\n columns = [\r\n {\"fieldname\": \"name\", \"label\": \"Asset ID\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"fieldname\": \"custom_serial_number\", \"label\": \"serial\", \"fieldtype\": \"Data\", \"width\": 150},\r\n ]\r\n\r\n # Configure the chart (Pie chart showing asset distribution)\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Asset Names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Asset Count\",\r\n \"values\": chart_values # Count of each asset type\r\n }\r\n ]\r\n },\r\n \"type\": \"pie\", # Can be 'bar', 'line', or 'pie'\r\n \"colors\": [\"#ECAD4B\", \"#39E4A5\", \"#B4CD29\"] # Custom colors\r\n }\r\n\r\n return columns, result, None, chart\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Count (Supplier) by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset Class A",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.098412",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Class A",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Class A",
|
|
"report_script": "def execute(filters=None):\r\n columns = [\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\"},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Link\", \"options\": \"Supplier\"},\r\n {\"label\": \"Class\", \"fieldname\": \"class\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Department\", \"fieldname\": \"department\", \"fieldtype\": \"Link\", \"options\": \"Department\"}\r\n ]\r\n \r\n result = []\r\n department_count = {} # To store the count of assets by department\r\n\r\n # Define the class filter\r\n asset_class_filter = \"Class A\"\r\n\r\n # Add an optional department filter (from filters if provided)\r\n department_filter = filters.get(\"department\") if filters else None\r\n \r\n # Create the filters dictionary\r\n asset_filters = {'custom_class': asset_class_filter}\r\n \r\n # Add department filter if provided\r\n if department_filter:\r\n asset_filters['department'] = department_filter\r\n\r\n # Fetch Assets where class is \"Class A\" and optionally filter by department\r\n assets = frappe.get_all('Asset', filters=asset_filters, \r\n fields=['name as asset_id', 'asset_name', 'supplier', 'custom_class', 'department'])\r\n\r\n # Append each asset to the result and count by department\r\n for asset in assets:\r\n result.append({\r\n \"asset_id\": asset['asset_id'],\r\n \"asset_name\": asset['asset_name'],\r\n \"supplier\": asset['supplier'],\r\n \"class\": asset['custom_class'],\r\n \"department\": asset['department']\r\n })\r\n\r\n # Count assets by department\r\n department = asset['department']\r\n if department:\r\n department_count[department] = department_count.get(department, 0) + 1\r\n\r\n # Prepare chart data (labels and values for each department)\r\n chart_labels = list(department_count.keys()) # Department names\r\n chart_values = list(department_count.values()) # Count of assets in each department\r\n\r\n # Create the chart configuration\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Department names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Number of Assets\",\r\n \"values\": chart_values # Asset counts for each department\r\n }\r\n ]\r\n },\r\n \"type\": \"bar\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#FF6384\"] # Customize colors for the chart\r\n }\r\n\r\n return columns, result, None, chart\r\n\r\n# Example call with filters\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Class A",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset Class B",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.055822",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Class B",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Class B",
|
|
"report_script": "def execute(filters):\r\n columns = [\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\"},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Link\", \"options\": \"Supplier\"},\r\n {\"label\": \"Class\", \"fieldname\": \"class\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Department\", \"fieldname\": \"department\", \"fieldtype\": \"Link\", \"options\": \"Department\"}\r\n ]\r\n \r\n result = []\r\n department_count = {} # To store the count of assets by department\r\n\r\n # Define the class filter\r\n asset_class_filter = \"Class B\"\r\n\r\n # Add an optional department filter (from filters if provided)\r\n department_filter = filters.get(\"department\") if filters else None\r\n \r\n # Create the filters dictionary\r\n asset_filters = {'custom_class': asset_class_filter}\r\n \r\n # Add department filter if provided\r\n if department_filter:\r\n asset_filters['department'] = department_filter\r\n\r\n # Fetch Assets where class is \"Class A\" and optionally filter by department\r\n assets = frappe.get_all('Asset', filters=asset_filters, \r\n fields=['name as asset_id', 'asset_name', 'supplier', 'custom_class', 'department'])\r\n\r\n # Append each asset to the result and count by department\r\n for asset in assets:\r\n result.append({\r\n \"asset_id\": asset['asset_id'],\r\n \"asset_name\": asset['asset_name'],\r\n \"supplier\": asset['supplier'],\r\n \"class\": asset['custom_class'],\r\n \"department\": asset['department']\r\n })\r\n\r\n # Count assets by department\r\n department = asset['department']\r\n if department:\r\n department_count[department] = department_count.get(department, 0) + 1\r\n\r\n # Prepare chart data (labels and values for each department)\r\n chart_labels = list(department_count.keys()) # Department names\r\n chart_values = list(department_count.values()) # Count of assets in each department\r\n\r\n # Create the chart configuration\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Department names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Number of Assets\",\r\n \"values\": chart_values # Asset counts for each department\r\n }\r\n ]\r\n },\r\n \"type\": \"bar\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#FF6384\"] # Customize colors for the chart\r\n }\r\n\r\n return columns, result, None, chart\r\n\r\n# Example call with filters\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Class B",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset Class C",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.016518",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Class C",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Class C",
|
|
"report_script": "def execute(filters):\r\n columns = [\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\"},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Link\", \"options\": \"Supplier\"},\r\n {\"label\": \"Class\", \"fieldname\": \"class\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Department\", \"fieldname\": \"department\", \"fieldtype\": \"Link\", \"options\": \"Department\"}\r\n ]\r\n \r\n result = []\r\n department_count = {} # To store the count of assets by department\r\n\r\n # Define the class filter\r\n asset_class_filter = \"Class C\"\r\n\r\n # Add an optional department filter (from filters if provided)\r\n department_filter = filters.get(\"department\") if filters else None\r\n \r\n # Create the filters dictionary\r\n asset_filters = {'custom_class': asset_class_filter}\r\n \r\n # Add department filter if provided\r\n if department_filter:\r\n asset_filters['department'] = department_filter\r\n\r\n # Fetch Assets where class is \"Class A\" and optionally filter by department\r\n assets = frappe.get_all('Asset', filters=asset_filters, \r\n fields=['name as asset_id', 'asset_name', 'supplier', 'custom_class', 'department'])\r\n\r\n # Append each asset to the result and count by department\r\n for asset in assets:\r\n result.append({\r\n \"asset_id\": asset['asset_id'],\r\n \"asset_name\": asset['asset_name'],\r\n \"supplier\": asset['supplier'],\r\n \"class\": asset['custom_class'],\r\n \"department\": asset['department']\r\n })\r\n\r\n # Count assets by department\r\n department = asset['department']\r\n if department:\r\n department_count[department] = department_count.get(department, 0) + 1\r\n\r\n # Prepare chart data (labels and values for each department)\r\n chart_labels = list(department_count.keys()) # Department names\r\n chart_values = list(department_count.values()) # Count of assets in each department\r\n\r\n # Create the chart configuration\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Department names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Number of Assets\",\r\n \"values\": chart_values # Asset counts for each department\r\n }\r\n ]\r\n },\r\n \"type\": \"bar\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#FF6384\"] # Customize colors for the chart\r\n }\r\n\r\n return columns, result, None, chart\r\n\r\n# Example call with filters\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Class C",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Work Order Status by Asset",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": "",
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:11.088059",
|
|
"module": "Asset Lite",
|
|
"name": "Work Order Status by Asset",
|
|
"prepared_report": 0,
|
|
"query": "",
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Work Order Status by Asset",
|
|
"report_script": "def get_result(filters=None):\r\n if filters is None:\r\n filters = {}\r\n\r\n columns = [\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 200},\r\n {\"label\": \"Work Order Type\", \"fieldname\": \"work_order_type\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Open\", \"fieldname\": \"open_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": \"Work In Progress\", \"fieldname\": \"work_in_progress_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": \"Pending Review\", \"fieldname\": \"pending_review_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": \"Completed\", \"fieldname\": \"completed_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": \"Closed\", \"fieldname\": \"closed_count\", \"fieldtype\": \"Int\", \"width\": 200}\r\n ]\r\n\r\n # Build Additional Filters\r\n additional_filters = \"\"\r\n filter_fields = [\"work_order_type\", \"repair_status\", \"company\"]\r\n\r\n for field in filter_fields:\r\n if filters.get(field):\r\n additional_filters =additional_filters + f\" AND wt.{field} = '{filters.get(field)}'\"\r\n\r\n # Main Query with Company Filter\r\n query = f\"\"\"\r\n SELECT\r\n company,\r\n work_order_type,\r\n SUM(CASE WHEN repair_status = 'Open' THEN 1 ELSE 0 END) AS open_count,\r\n SUM(CASE WHEN repair_status = 'Work In Progress' THEN 1 ELSE 0 END) AS work_in_progress_count,\r\n SUM(CASE WHEN repair_status = 'Pending Review' THEN 1 ELSE 0 END) AS pending_review_count,\r\n SUM(CASE WHEN repair_status = 'Completed' THEN 1 ELSE 0 END) AS completed_count,\r\n SUM(CASE WHEN repair_status = 'Closed' THEN 1 ELSE 0 END) AS closed_count\r\n FROM\r\n `tabWork_Order` as wt\r\n WHERE\r\n repair_status IN ('Open', 'Work In Progress', 'Pending Review', 'Completed', 'Closed', 'Cancelled') {additional_filters}\r\n GROUP BY\r\n company, work_order_type\r\n \"\"\"\r\n \r\n result = frappe.db.sql(query, as_dict=True)\r\n\r\n # Summary Queries with Company Filter\r\n sql_queries = {\r\n \"Open\": \"SELECT COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Open'\",\r\n \"Work In Progress\": \"SELECT COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Work In Progress'\",\r\n \"Pending Review\": \"SELECT COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Pending Review'\",\r\n \"Completed\": \"SELECT COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Completed'\",\r\n \"Closed\": \"SELECT COUNT(*) as count FROM `tabWork_Order` WHERE repair_status = 'Closed'\",\r\n \"Total Work Orders\": \"SELECT COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Open', 'Work In Progress', 'Pending Review', 'Completed', 'Closed', 'Cancelled')\"\r\n }\r\n\r\n # Apply Company Filter to Summary Queries (Corrected Indentation)\r\n if filters.get(\"company\"): # ✅ Proper indentation\r\n company_filter = f\" AND company = '{filters.get('company')}'\"\r\n for key in sql_queries:\r\n sql_queries[key] = sql_queries[key] + company_filter # ✅ Correct fix\r\n\r\n # Execute Summary Queries\r\n report_summary = [{\"value\": row.count, \"label\": label} for label, query in sql_queries.items() for row in frappe.db.sql(query, as_dict=True)]\r\n\r\n # Chart Data\r\n chart = {\r\n \"data\": {\r\n \"labels\": [row[\"work_order_type\"] for row in result],\r\n \"datasets\": [\r\n {\"name\": \"Open\", \"values\": [row[\"open_count\"] for row in result]},\r\n {\"name\": \"Work In Progress\", \"values\": [row[\"work_in_progress_count\"] for row in result]},\r\n {\"name\": \"Pending Review\", \"values\": [row[\"pending_review_count\"] for row in result]},\r\n {\"name\": \"Completed\", \"values\": [row[\"completed_count\"] for row in result]},\r\n {\"name\": \"Closed\", \"values\": [row[\"closed_count\"] for row in result]},\r\n ]\r\n },\r\n \"type\": \"bar\",\r\n \"barOptions\": {\r\n \"stacked\": 1,\r\n \"spaceRatio\": 0.6\r\n },\r\n \"colors\": [\"#CCCCB7\", \"#52B2BF\", \"#9EC1A4\", \"#058D7C\", \"#A3A5CF\"],\r\n }\r\n\r\n return columns, result, None, chart, report_summary\r\n\r\n# Calling the function\r\ndata = get_result(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Work Order Status by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Status by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Status by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Work Order Status by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": "frappe.query_reports[\"Asset List Department wise\"] = {\r\n onload: function(report) {\r\n // Fetch the logged-in user's department\r\n frappe.call({\r\n method: \"frappe.client.get_value\",\r\n args: {\r\n doctype: \"Employee\",\r\n filters: {\"user_id\": frappe.session.user},\r\n fieldname: \"department\"\r\n },\r\n callback: function(r) {\r\n if (r.message && r.message.department) {\r\n // Set the department filter value\r\n let department = r.message.department;\r\n report.set_filter_value(\"department\", department);\r\n\r\n // Now, set this value in the chart filter as well\r\n const chart = report.page.charts.find(chart => chart.chart_name === \"Asset Department Wisr\");\r\n if (chart) {\r\n chart.update_filter_value(\"department\", department);\r\n chart.refresh(); // Refresh to apply the filter\r\n }\r\n }\r\n }\r\n });\r\n }\r\n};\r\n",
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:12.255598",
|
|
"module": "Asset Lite",
|
|
"name": "Asset List Department wise",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset List Department wise",
|
|
"report_script": "def execute(filters):\r\n result = []\r\n\r\n # Fetch the department filter value\r\n department = filters.get(\"department\")\r\n\r\n # Query to fetch asset names, departments, status, and location\r\n if department:\r\n query = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n department,\r\n status,\r\n location\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n department = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, department, as_dict=True)\r\n else:\r\n # If no department is selected, return all assets\r\n query_no_department = \"\"\"\r\n SELECT\r\n name,\r\n asset_name,\r\n department,\r\n status,\r\n location\r\n FROM\r\n `tabAsset`\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query_no_department, as_dict=True)\r\n\r\n # Create a dictionary to count assets per department\r\n department_count = {}\r\n \r\n for row in result:\r\n dept = row['department']\r\n if dept in department_count:\r\n department_count[dept] = department_count[dept] + 1 # Increment count\r\n else:\r\n department_count[dept] = 1 # Initialize count\r\n\r\n # Prepare data for the chart\r\n chart_labels = list(department_count.keys()) # Departments\r\n chart_values = list(department_count.values()) # Count of assets\r\n\r\n # Define the columns to be displayed in the report\r\n columns = [\r\n {\"fieldname\": \"name\", \"label\": \"Asset ID\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"fieldname\": \"status\", \"label\": \"Status\", \"fieldtype\": \"Data\", \"width\": 100},\r\n {\"fieldname\": \"location\", \"label\": \"Location\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\", \"options\": \"Department\", \"width\": 150}\r\n ]\r\n\r\n # Configure the chart to show the number of assets per department\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels, # Department names\r\n \"datasets\": [\r\n {\r\n \"name\": \"Number of Assets\",\r\n \"values\": chart_values # Count of assets for each department\r\n }\r\n ]\r\n },\r\n \"type\": \"pie\", # You can use 'bar', 'line', 'pie', etc.\r\n \"colors\": [\"#3498db\"] # Customize the color as needed\r\n }\r\n\r\n return columns, result, None, chart\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset List Department wise",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-03-05 21:09:42.461336",
|
|
"module": "Asset Lite",
|
|
"name": "Supplier Total Score",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Supplier Scorecard",
|
|
"reference_report": null,
|
|
"report_name": "Supplier Total Score",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Supplier Total Score",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Asset Maintenance Frequency Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Data",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": "\n2020\n2021\n2022\n2023\n2024\n2025\n2026\n2027\n2028\n2029\n2030",
|
|
"parent": "Asset Maintenance Frequency Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "month",
|
|
"fieldtype": "Select",
|
|
"label": "Month",
|
|
"mandatory": 0,
|
|
"options": "\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember",
|
|
"parent": "Asset Maintenance Frequency Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:11.266824",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Frequency Report",
|
|
"prepared_report": 0,
|
|
"query": "select\r\n custom_asset_names as Item,\r\n SUM(CASE WHEN maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS Planned,\r\n SUM(CASE WHEN maintenance_status = 'Completed' THEN 1 ELSE 0 END) as \"Completed\",\r\n SUM(CASE WHEN maintenance_status = 'Cancelled' THEN 1 ELSE 0 END) as \"Cancelled\",\r\n SUM(CASE WHEN maintenance_status = 'Overdue' THEN 1 ELSE 0 END) as \"Overdue\",\r\n COUNT(custom_asset_names) as \"Total Count\"\r\nfrom \r\n `tabAsset Maintenance Log`\r\ngroup by\r\n custom_asset_names",
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": "",
|
|
"report_name": "Asset Maintenance Frequency Report",
|
|
"report_script": "\r\n\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # Build dynamic SQL filters\r\n conditions = \"1=1\" # Always true (used for dynamic filtering)\r\n query_params = {}\r\n\r\n # Apply Company Filter\r\n if filters.get(\"company\"):\r\n conditions =conditions + \" AND a.company = %(company)s\"\r\n query_params[\"company\"] = filters.get(\"company\")\r\n\r\n # Apply Year & Month Filters\r\n if filters.get(\"year\"):\r\n conditions =conditions + \" AND YEAR(aml.creation) = %(year)s\"\r\n query_params[\"year\"] = int(filters.get(\"year\"))\r\n\r\n if filters.get(\"month\"):\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12\r\n }\r\n month_num = month_map.get(filters.get(\"month\"))\r\n if month_num:\r\n conditions =conditions + \" AND MONTH(aml.creation) = %(month)s\"\r\n query_params[\"month\"] = month_num\r\n\r\n # SQL Query\r\n query = f\"\"\"\r\n SELECT\r\n aml.custom_asset_names AS item,\r\n a.company AS company,\r\n SUM(CASE WHEN aml.maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS planned,\r\n SUM(CASE WHEN aml.maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS completed,\r\n SUM(CASE WHEN aml.maintenance_status = 'Cancelled' THEN 1 ELSE 0 END) AS cancelled,\r\n SUM(CASE WHEN aml.maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS overdue,\r\n COUNT(aml.custom_asset_names) AS total_count\r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n LEFT JOIN\r\n `tabAsset` a ON aml.asset_name = a.name\r\n WHERE\r\n {conditions}\r\n GROUP BY\r\n aml.custom_asset_names, a.company\r\n ORDER BY \r\n total_count DESC\r\n \"\"\"\r\n\r\n # Execute query\r\n result = frappe.db.sql(query, query_params, as_dict=True)\r\n\r\n # Define Columns\r\n columns = [\r\n {\"label\": \"Item\", \"fieldname\": \"item\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 200},\r\n {\"label\": \"Planned\", \"fieldname\": \"planned\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"label\": \"Completed\", \"fieldname\": \"completed\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"label\": \"Cancelled\", \"fieldname\": \"cancelled\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"label\": \"Overdue\", \"fieldname\": \"overdue\", \"fieldtype\": \"Int\", \"width\": 100},\r\n {\"label\": \"Total Count\", \"fieldname\": \"total_count\", \"fieldtype\": \"Int\", \"width\": 100},\r\n ]\r\n\r\n return columns, result\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Frequency Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Frequency Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "hospital",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "PM Status Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "month",
|
|
"fieldtype": "Select",
|
|
"label": "Month",
|
|
"mandatory": 0,
|
|
"options": "\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember",
|
|
"parent": "PM Status Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Select",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": "\n2020\n2021\n2022\n2023\n2024\n2025\n2026\n2027\n2028\n2029\n2030",
|
|
"parent": "PM Status Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-04-22 14:49:11.037963",
|
|
"module": "Asset Lite",
|
|
"name": "PM Status Report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "PM Status Report",
|
|
"report_script": "def execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n conditions = [\"aml.custom_hospital_name IS NOT NULL AND aml.custom_hospital_name != ''\"]\r\n query_params = {}\r\n\r\n # Apply Year Filter\r\n if filters.get(\"year\"):\r\n conditions.append(\"YEAR(aml.due_date) = %(year)s\")\r\n query_params[\"year\"] = filters.get(\"year\")\r\n\r\n # Apply Month Filter\r\n if filters.get(\"month\"):\r\n month_mapping = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12\r\n }\r\n month_num = month_mapping.get(filters.get(\"month\"))\r\n if month_num:\r\n conditions.append(\"MONTH(aml.due_date) = %(month)s\")\r\n query_params[\"month\"] = month_num\r\n\r\n # Apply Hospital Filter\r\n if filters.get(\"hospital\"):\r\n conditions.append(\"aml.custom_hospital_name = %(hospital)s\")\r\n query_params[\"hospital\"] = filters.get(\"hospital\")\r\n\r\n # Construct WHERE Clause\r\n where_clause = \"WHERE \" + \" AND \".join(conditions) if conditions else \"\"\r\n\r\n # Fetch Summary Counts (Grouped by Hospital)\r\n summary_query = f\"\"\"\r\n SELECT\r\n SUM(CASE WHEN aml.maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS planned,\r\n SUM(CASE WHEN aml.maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS completed,\r\n SUM(CASE WHEN aml.maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS overdue,\r\n COUNT(aml.name) AS total_pm\r\n FROM `tabAsset Maintenance Log` aml\r\n {where_clause}\r\n \"\"\"\r\n summary_data = frappe.db.sql(summary_query, query_params, as_dict=True)\r\n\r\n # Fetch Hospital-wise Summary for Chart\r\n hospital_query = f\"\"\"\r\n SELECT\r\n aml.custom_hospital_name AS company,\r\n SUM(CASE WHEN aml.maintenance_status = 'Planned' THEN 1 ELSE 0 END) AS planned,\r\n SUM(CASE WHEN aml.maintenance_status = 'Completed' THEN 1 ELSE 0 END) AS completed,\r\n SUM(CASE WHEN aml.maintenance_status = 'Overdue' THEN 1 ELSE 0 END) AS overdue\r\n FROM `tabAsset Maintenance Log` aml\r\n {where_clause}\r\n GROUP BY aml.custom_hospital_name\r\n \"\"\"\r\n hospital_summary = frappe.db.sql(hospital_query, query_params, as_dict=True)\r\n\r\n # Fetch Detailed Table Data\r\n details_query = f\"\"\"\r\n SELECT\r\n aml.name AS log_id,\r\n aml.asset_name AS asset_id,\r\n aml.custom_asset_names AS asset_name,\r\n aml.maintenance_status AS status,\r\n aml.due_date AS due_date,\r\n aml.custom_hospital_name AS company,\r\n aml.custom_pm_overdue_reason,\r\n aml.custom_early_completion_reason,\r\n aml.custom_accepted_by_moh,\r\n am.custom_site_contractor,\r\n am.custom_subcontractor,\r\n am.custom_service_coverage,\r\n am.custom_service_agreement,\r\n am.custom_price_per_pm\r\n FROM `tabAsset Maintenance Log` aml\r\n LEFT JOIN `tabAsset Maintenance` am ON aml.asset_maintenance = am.name\r\n {where_clause}\r\n ORDER BY aml.due_date DESC\r\n \"\"\"\r\n table_data = frappe.db.sql(details_query, query_params, as_dict=True)\r\n\r\n # Define Report Columns\r\n columns = [\r\n {\"label\": \"Log ID\", \"fieldname\": \"log_id\", \"fieldtype\": \"Link\", \"options\": \"Asset Maintenance Log\", \"width\": 150},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 200},\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\", \"width\": 250},\r\n {\"label\": \"Maintenance Status\", \"fieldname\": \"status\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Due Date\", \"fieldname\": \"due_date\", \"fieldtype\": \"Date\", \"width\": 150},\r\n {\"label\": \"Price Per PM\", \"fieldname\": \"custom_price_per_pm\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Site Contractor\", \"fieldname\": \"custom_site_contractor\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Subcontractor\", \"fieldname\": \"custom_subcontractor\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Service Coverage\", \"fieldname\": \"custom_service_coverage\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Service Agreement\", \"fieldname\": \"custom_service_agreement\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Overdue Reason\", \"fieldname\": \"custom_pm_overdue_reason\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Early Completion Reason\", \"fieldname\": \"custom_early_completion_reason\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Accepted By MOH\", \"fieldname\": \"custom_accepted_by_moh\", \"fieldtype\": \"Check\", \"width\": 100},\r\n ]\r\n\r\n # ✅ Prepare Chart Data (Stacked Bar Chart)\r\n labels = []\r\n planned_values = []\r\n completed_values = []\r\n overdue_values = []\r\n total_values = [] # New Total Column\r\n \r\n for row in hospital_summary:\r\n labels.append(row[\"company\"] or \"Unknown\")\r\n planned = row[\"planned\"] or 0\r\n completed = row[\"completed\"] or 0\r\n overdue = row[\"overdue\"] or 0\r\n \r\n planned_values.append(planned)\r\n completed_values.append(completed)\r\n overdue_values.append(overdue)\r\n total_values.append(planned + completed + overdue) # Sum of all statuses\r\n \r\n # ✅ Define Updated Chart with \"Total\"\r\n chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": [\r\n {\"name\": \"Overdue\", \"values\": overdue_values, \"chartType\": \"bar\", \"color\": \"red\"},\r\n {\"name\": \"Planned\", \"values\": planned_values, \"chartType\": \"bar\", \"color\": \"orange\"},\r\n {\"name\": \"Completed\", \"values\": completed_values, \"chartType\": \"bar\", \"color\": \"green\"},\r\n {\"name\": \"Total\", \"values\": total_values, \"chartType\": \"bar\", \"color\": \"blue\"}, # ✅ New Total Bar\r\n ]\r\n },\r\n \"type\": \"bar\",\r\n \"barOptions\": {\r\n \"stacked\": True # ✅ Stack all bars including Total\r\n }\r\n }\r\n\r\n # Prepare Report Summary Data\r\n report_summary = [\r\n {\"label\": \"Planned\", \"value\": summary_data[0][\"planned\"], \"indicator\": \"orange\"},\r\n {\"label\": \"Completed\", \"value\": summary_data[0][\"completed\"], \"indicator\": \"green\"},\r\n {\"label\": \"Overdue\", \"value\": summary_data[0][\"overdue\"], \"indicator\": \"red\"},\r\n {\"label\": \"Total PM\", \"value\": summary_data[0][\"total_pm\"], \"indicator\": \"blue\"}\r\n ]\r\n\r\n return columns, table_data, None, chart, report_summary\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "PM Status Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "PM Status Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "PM Status Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "PM Status Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "supplier",
|
|
"fieldtype": "Link",
|
|
"label": "Supplier",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-07-30 21:47:53.262796",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Cost History",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Cost History",
|
|
"report_script": "def execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # ✅ Define Allowed Companies (Hospitals)\r\n #allowed_companies = [\r\n # \"King AbdulAziz Specialist Hospital\",\r\n # \"Domat Al Jandal Hospital\",\r\n # \"Al Jouf Hospital\",\r\n # \"Tabarjal Hospital\"\r\n #]\r\n \r\n # ✅ Get all company names from the Company DocType\r\n allowed_companies = [row.name for row in frappe.get_all(\"Company\", fields=[\"name\"])]\r\n\r\n # ✅ Apply Filters & Conditions\r\n conditions = [\"a.company IN %(allowed_companies)s\"] # Restrict to specific hospitals\r\n query_params = {\"allowed_companies\": allowed_companies}\r\n\r\n # ✅ Apply Additional Company Filter (if selected)\r\n if filters.get(\"company\") and filters[\"company\"] in allowed_companies:\r\n conditions.append(\"a.company = %(company)s\")\r\n query_params[\"company\"] = filters[\"company\"]\r\n\r\n # ✅ Apply Supplier Filter (if selected)\r\n if filters.get(\"supplier\"):\r\n conditions.append(\"a.supplier = %(supplier)s\")\r\n query_params[\"supplier\"] = filters[\"supplier\"]\r\n\r\n # ✅ Construct WHERE Clause\r\n where_clause = \"WHERE \" + \" AND \".join(conditions) if conditions else \"\"\r\n\r\n # ✅ Fetch Asset Data\r\n query = f\"\"\"\r\n SELECT\r\n a.name AS asset_id,\r\n a.asset_name AS asset_name,\r\n a.company AS company,\r\n a.gross_purchase_amount AS gross_amount,\r\n a.custom_total_spare_parts_amount AS spare_parts_amount,\r\n a.supplier AS supplier,\r\n a.custom_serial_number AS serial_number,\r\n COALESCE((\r\n SELECT SUM(sp.qty) FROM `tabSpare Parts` sp \r\n WHERE sp.parent = a.name\r\n ), 0) AS spare_parts_qty\r\n \r\n FROM `tabAsset` a\r\n {where_clause}\r\n ORDER BY a.asset_name\r\n \"\"\"\r\n data = frappe.db.sql(query, query_params, as_dict=True)\r\n\r\n # ✅ Define Report Columns\r\n columns = [\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_id\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 150},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 150},\r\n {\"label\": \"Gross Purchase Amount\", \"fieldname\": \"gross_amount\", \"fieldtype\": \"Currency\", \"width\": 200},\r\n {\"label\": \"Repair Cost\", \"fieldname\": \"spare_parts_amount\", \"fieldtype\": \"Currency\", \"width\": 200},\r\n {\"label\": \"Spare Parts Quantity\", \"fieldname\": \"spare_parts_qty\", \"fieldtype\": \"Int\", \"width\": 180},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Link\", \"options\": \"Supplier\", \"width\": 200},\r\n {\"label\": \"Serial Number\", \"fieldname\": \"serial_number\", \"fieldtype\": \"Data\", \"width\": 150},\r\n ]\r\n\r\n # 🔧 FIXED: Apply same filters to chart query as main table query\r\n chart_conditions = [\"company IN %(allowed_companies)s\"]\r\n chart_params = {\"allowed_companies\": allowed_companies}\r\n\r\n # ✅ Apply Company Filter to Chart (CRITICAL FIX)\r\n if filters.get(\"company\") and filters[\"company\"] in allowed_companies:\r\n chart_conditions.append(\"company = %(company)s\")\r\n chart_params[\"company\"] = filters[\"company\"]\r\n\r\n # ✅ Apply Supplier Filter to Chart\r\n if filters.get(\"supplier\"):\r\n chart_conditions.append(\"supplier = %(supplier)s\")\r\n chart_params[\"supplier\"] = filters[\"supplier\"]\r\n\r\n # ✅ Construct Chart WHERE Clause\r\n chart_where_clause = \"WHERE \" + \" AND \".join(chart_conditions) if chart_conditions else \"\"\r\n\r\n # 🔧 FIXED: Updated chart query with proper filtering\r\n supplier_query = f\"\"\"\r\n SELECT supplier, COUNT(name) AS asset_count\r\n FROM `tabAsset`\r\n {chart_where_clause}\r\n AND supplier IS NOT NULL AND supplier != ''\r\n GROUP BY supplier \r\n ORDER BY asset_count DESC\r\n \"\"\"\r\n\r\n supplier_data = frappe.db.sql(supplier_query, chart_params, as_dict=True)\r\n\r\n # ✅ Prepare Supplier vs Asset Count Chart\r\n supplier_labels = []\r\n asset_count_values = []\r\n\r\n for row in supplier_data:\r\n supplier_labels.append(row[\"supplier\"])\r\n asset_count_values.append(row[\"asset_count\"])\r\n\r\n # 🎯 Enhanced chart with better title based on filters\r\n chart_title = \"Asset Count by Supplier\"\r\n if filters.get(\"company\"):\r\n chart_title = f\"Asset Count by Supplier - {filters['company']}\"\r\n \r\n chart = {\r\n \"data\": {\r\n \"labels\": supplier_labels,\r\n \"datasets\": [\r\n {\r\n \"name\": \"Asset Count\",\r\n \"values\": asset_count_values,\r\n \"chartType\": \"bar\",\r\n \"color\": \"blue\"\r\n }\r\n ]\r\n },\r\n \"type\": \"bar\",\r\n \"title\": chart_title,\r\n \"barOptions\": {\r\n \"stacked\": False # Not stacked, just a simple bar chart\r\n }\r\n }\r\n\r\n return columns, data, None, chart\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Asset Cost History",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-01-08 11:51:04.404667",
|
|
"module": "Asset Lite",
|
|
"name": "Maintenance Response Time",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Maintenance Response Time",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Maintenance Response Time",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Sales Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "from_date",
|
|
"fieldtype": "Date",
|
|
"label": "From Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "to_date",
|
|
"fieldtype": "Date",
|
|
"label": "To Date",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.313582",
|
|
"module": "Asset Lite",
|
|
"name": "Engineers working Hours",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Engineers working Hours",
|
|
"report_script": "\r\ndef execute(filters):\r\n # Define the columns for the report\r\n columns = [\r\n {\"label\": \"Engineer\", \"fieldname\": \"engineer\", \"fieldtype\": \"Link\", \"options\": \"User\", \"width\": 200},\r\n {\"label\": \"Engineer Name\", \"fieldname\": \"engineer_name\", \"fieldtype\": \"Data\", \"width\": 200}, # New Column\r\n {\"label\": \"Total Hours Spent\", \"fieldname\": \"total_hours\", \"fieldtype\": \"Float\", \"width\": 150},\r\n {\"label\": \"Company\", \"fieldname\": \"company\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 200}, # Added Company Column\r\n ]\r\n\r\n # Prepare conditions and parameters\r\n conditions = []\r\n params = {}\r\n\r\n # Add date range filter if provided\r\n if filters.get(\"from_date\") and filters.get(\"to_date\"):\r\n conditions.append(\"wo.creation BETWEEN %(start_date)s AND %(end_date)s\")\r\n params[\"start_date\"] = f\"{filters['from_date']} 00:00:00\"\r\n params[\"end_date\"] = f\"{filters['to_date']} 23:59:59\"\r\n\r\n # Add company filter if provided\r\n if filters.get(\"company\"):\r\n conditions.append(\"wo.company = %(company)s\")\r\n params[\"company\"] = filters[\"company\"]\r\n\r\n # Build the WHERE clause\r\n where_clause = \" AND \" + \" AND \".join(conditions) if conditions else \"\"\r\n\r\n # SQL Query with Company Filter\r\n query = f\"\"\"\r\n SELECT\r\n t.allocated_to AS engineer,\r\n u.full_name AS engineer_name, \r\n wo.company AS company,\r\n SUM(wo.total_hours_spent) AS total_hours\r\n FROM\r\n `tabToDo` t\r\n INNER JOIN\r\n `tabWork_Order` wo ON wo.name = t.reference_name\r\n LEFT JOIN\r\n `tabUser` u ON u.name = t.allocated_to -- Joining tabUser to get full_name\r\n WHERE\r\n t.reference_type = 'Work_Order' AND wo.docstatus = 1\r\n {where_clause}\r\n GROUP BY\r\n t.allocated_to, u.full_name, wo.company\r\n \"\"\"\r\n\r\n # Execute the query with parameters\r\n result = frappe.db.sql(query, params, as_dict=True)\r\n \r\n # Ensure total_hours is rounded to 2 decimal places\r\n for row in result:\r\n row[\"total_hours\"] = round(row[\"total_hours\"], 2) if row[\"total_hours\"] is not None else 0.00\r\n\r\n return columns, result\r\n\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Engineers working Hours",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [],
|
|
"is_standard": "Yes",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "Test",
|
|
"modified": "2025-01-07 20:06:07.388338",
|
|
"module": "Asset Lite",
|
|
"name": "Planned maintenance percentage (PMP)",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Planned maintenance percentage (PMP)",
|
|
"report_script": null,
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Planned maintenance percentage (PMP)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Planned maintenance percentage (PMP)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Planned maintenance percentage (PMP)",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Asset Maintenance Assignments",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-04-22 14:49:11.010300",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Maintenance Assignments",
|
|
"prepared_report": 0,
|
|
"query": "\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # Define Company Filter (Optional)\r\n company_filter = \"\"\r\n if filters.get(\"company\"):\r\n company_filter = \"AND a.company = %(company)s\"\r\n\r\n # SQL Query with Company Filter\r\n query = f\"\"\"\r\n SELECT \r\n aml.item_name AS item_name,\r\n aml.maintenance_status AS maintenance_status,\r\n aml.assign_to_name AS assigned_to,\r\n SUM(CASE \r\n WHEN aml.due_date = aml.completion_date \r\n AND aml.maintenance_status = 'Completed' THEN 1 \r\n ELSE 0 \r\n END) AS completed_on_time,\r\n SUM(CASE \r\n WHEN aml.completion_date < aml.due_date \r\n AND aml.maintenance_status = 'Completed' THEN 1 \r\n ELSE 0 \r\n END) AS completed_within_time,\r\n SUM(CASE \r\n WHEN aml.completion_date > aml.due_date THEN 1 \r\n ELSE 0 \r\n END) AS delay_in_completion,\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Planned' \r\n AND aml.completion_date IS NULL \r\n AND aml.due_date > CURDATE() THEN 1 \r\n ELSE 0 \r\n END) AS pending,\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Planned' \r\n AND aml.completion_date IS NULL \r\n AND aml.due_date < CURDATE() THEN 1 \r\n ELSE 0 \r\n END) AS overdue,\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Cancelled' THEN 1 \r\n ELSE 0 \r\n END) AS cancelled\r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n LEFT JOIN \r\n `tabAsset` a ON aml.asset_name = a.name\r\n WHERE \r\n 1=1 {company_filter} -- Apply Company Filter\r\n GROUP BY \r\n aml.assign_to_name\r\n ORDER BY \r\n completed_within_time DESC;\r\n \"\"\"\r\n\r\n # Fetch Data from Database\r\n result = frappe.db.sql(query, filters, as_dict=True)\r\n\r\n # Define Report Columns\r\n columns = [\r\n {\"label\": \"Item Name\", \"fieldname\": \"item_name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Maintenance Status\", \"fieldname\": \"maintenance_status\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Assigned To\", \"fieldname\": \"assigned_to\", \"fieldtype\": \"Data\", \"width\": 180},\r\n {\"label\": \"Completed On Time\", \"fieldname\": \"completed_on_time\", \"fieldtype\": \"Int\", \"width\": 130},\r\n {\"label\": \"Completed Within Time\", \"fieldname\": \"completed_within_time\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"label\": \"Delay In Completion\", \"fieldname\": \"delay_in_completion\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"label\": \"Pending\", \"fieldname\": \"pending\", \"fieldtype\": \"Int\", \"width\": 120},\r\n {\"label\": \"Overdue\", \"fieldname\": \"overdue\", \"fieldtype\": \"Int\", \"width\": 120},\r\n {\"label\": \"Cancelled\", \"fieldname\": \"cancelled\", \"fieldtype\": \"Int\", \"width\": 120},\r\n ]\r\n\r\n return columns, result\r\n",
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Asset Maintenance Assignments",
|
|
"report_script": "def execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n \r\n # Define Company Filter (Optional)\r\n company_filter = \"\"\r\n if filters.get(\"company\"):\r\n company_filter = \"AND a.company = %(company)s\"\r\n\r\n # SQL Query with Company Filter\r\n query = f\"\"\"\r\n SELECT \r\n aml.item_name AS item_name,\r\n a.company AS company,\r\n aml.maintenance_status AS maintenance_status,\r\n aml.assign_to_name AS assigned_to,\r\n SUM(CASE \r\n WHEN aml.due_date = aml.completion_date \r\n AND aml.maintenance_status = 'Completed' THEN 1 \r\n ELSE 0 \r\n END) AS completed_on_time,\r\n SUM(CASE \r\n WHEN aml.completion_date < aml.due_date \r\n AND aml.maintenance_status = 'Completed' THEN 1 \r\n ELSE 0 \r\n END) AS completed_within_time,\r\n SUM(CASE \r\n WHEN aml.completion_date > aml.due_date THEN 1 \r\n ELSE 0 \r\n END) AS delay_in_completion,\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Planned' \r\n AND aml.completion_date IS NULL \r\n AND aml.due_date > CURDATE() THEN 1 \r\n ELSE 0 \r\n END) AS pending,\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Planned' \r\n AND aml.completion_date IS NULL \r\n AND aml.due_date < CURDATE() THEN 1 \r\n ELSE 0 \r\n END) AS overdue,\r\n SUM(CASE \r\n WHEN aml.maintenance_status = 'Cancelled' THEN 1 \r\n ELSE 0 \r\n END) AS cancelled\r\n FROM \r\n `tabAsset Maintenance Log` aml\r\n LEFT JOIN \r\n `tabAsset` a ON aml.asset_name = a.name\r\n WHERE \r\n 1=1 {company_filter}\r\n GROUP BY \r\n aml.assign_to_name\r\n ORDER BY \r\n completed_within_time DESC;\r\n \"\"\"\r\n\r\n # Fetch Data from Database\r\n result = frappe.db.sql(query, filters, as_dict=True)\r\n\r\n # Define Report Columns\r\n columns = [\r\n {\"label\": \"Item Name\", \"fieldname\": \"item_name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Link\",\"options\":\"Company\",\"width\": 200},\r\n {\"label\": \"Maintenance Status\", \"fieldname\": \"maintenance_status\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Assigned To\", \"fieldname\": \"assigned_to\", \"fieldtype\": \"Data\", \"width\": 180},\r\n {\"label\": \"Completed On Time\", \"fieldname\": \"completed_on_time\", \"fieldtype\": \"Int\", \"width\": 130},\r\n {\"label\": \"Completed Within Time\", \"fieldname\": \"completed_within_time\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"label\": \"Delay In Completion\", \"fieldname\": \"delay_in_completion\", \"fieldtype\": \"Int\", \"width\": 150},\r\n {\"label\": \"Pending\", \"fieldname\": \"pending\", \"fieldtype\": \"Int\", \"width\": 120},\r\n {\"label\": \"Overdue\", \"fieldname\": \"overdue\", \"fieldtype\": \"Int\", \"width\": 120},\r\n {\"label\": \"Cancelled\", \"fieldname\": \"cancelled\", \"fieldtype\": \"Int\", \"width\": 120},\r\n ]\r\n\r\n return columns, result\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Maintenance Assignments",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignments",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignments",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Maintenance Assignments",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "class",
|
|
"fieldtype": "Select",
|
|
"label": "Class",
|
|
"mandatory": 0,
|
|
"options": "\nClass A\nClass B\nClass C",
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.498639",
|
|
"module": "Asset Lite",
|
|
"name": "Total Hrs and Downtime Hrs",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Total Hrs and Downtime Hrs",
|
|
"report_script": "def execute(filters):\r\n columns = [\r\n {\"label\": \"\", \"fieldname\": \"name\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Total Hours of All Assets\", \"fieldname\": \"total_hours_sum\", \"fieldtype\": \"Float\"},\r\n {\"label\": \"Total Downtime Hours of All Assets\", \"fieldname\": \"downtime_hours_sum\", \"fieldtype\": \"Float\"},\r\n {\"label\": \"Total Uptime Hours of All Assets\", \"fieldname\": \"uptime_hours_sum\", \"fieldtype\": \"Float\"}\r\n ]\r\n \r\n result = []\r\n \r\n # Get the department and class filters from the input\r\n department = filters.get(\"department\") if filters else None\r\n asset_class = filters.get(\"class\") if filters else None\r\n asset_name = filters.get(\"asset\") if filters else None\r\n \r\n # Build the filter conditions based on the department and class filters\r\n asset_filters = {}\r\n if department:\r\n asset_filters['department'] = department\r\n if asset_class:\r\n asset_filters['custom_class'] = asset_class\r\n if asset_name:\r\n asset_filters['name'] = asset_name\r\n \r\n # Fetch all assets with their total hours and downtime hours based on filters\r\n assets = frappe.get_all('Asset', filters=asset_filters, fields=['custom_total_hours', 'custom_down_time'])\r\n \r\n # Initialize sums\r\n total_hours_sum = round(sum(asset['custom_total_hours'] or 0 for asset in assets))\r\n downtime_hours_sum = round(sum(asset['custom_down_time'] or 0 for asset in assets))\r\n uptime_hours_sum = round(total_hours_sum - downtime_hours_sum)\r\n \r\n if total_hours_sum == 0:\r\n total_hours_sum = downtime_hours_sum\r\n uptime_hours_sum = round(total_hours_sum - downtime_hours_sum)\r\n \r\n \r\n \r\n # Add the sums to the result\r\n result.append({\r\n \"name\":\"Hours\",\r\n \"total_hours_sum\": total_hours_sum,\r\n \"downtime_hours_sum\": downtime_hours_sum,\r\n \"uptime_hours_sum\": uptime_hours_sum\r\n })\r\n \r\n return columns, result\r\n\r\ndata = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
},
|
|
{
|
|
"parent": "Total Hrs and Downtime Hrs",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Employee"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "hospital",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Planned PM",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-09-03 15:39:36.024998",
|
|
"module": "Asset Lite",
|
|
"name": "Planned PM",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset Maintenance Log",
|
|
"reference_report": null,
|
|
"report_name": "Planned PM",
|
|
"report_script": "#import frappe\r\n#from frappe.utils import nowdate, get_last_day\r\n\r\ndef execute(filters=None):\r\n today = frappe.utils.nowdate()\r\n end_of_month = frappe.utils.get_last_day(today)\r\n\r\n # Initialize filters dictionary\r\n planned_filters = {\r\n \"maintenance_status\": \"Planned\",\r\n \"due_date\": [\"between\", [today, end_of_month]]\r\n }\r\n\r\n overdue_filters = {\r\n \"maintenance_status\": [\"in\", [\"Overdue\"]],\r\n \"due_date\": [\"<\", today]\r\n }\r\n\r\n # Apply hospital filter if provided\r\n if filters and filters.get(\"hospital\"):\r\n planned_filters[\"custom_hospital_name\"] = filters.get(\"hospital\")\r\n overdue_filters[\"custom_hospital_name\"] = filters.get(\"hospital\")\r\n\r\n # Fetch Planned PMs due from today till end of month\r\n planned_data = frappe.db.get_all(\r\n \"Asset Maintenance Log\",\r\n filters=planned_filters,\r\n fields=[\r\n \"name\", \"asset_name\", \"custom_asset_names\", \"due_date\", \"maintenance_status\", \"assign_to_name\", \"custom_hospital_name\"\r\n ],\r\n order_by=\"due_date\"\r\n )\r\n\r\n # Fetch Overdue PMs\r\n overdue_data = frappe.db.get_all(\r\n \"Asset Maintenance Log\",\r\n filters=overdue_filters,\r\n fields=[\r\n \"name\", \"asset_name\", \"custom_asset_names\", \"due_date\", \"maintenance_status\", \"assign_to_name\", \"custom_hospital_name\"\r\n ],\r\n order_by=\"due_date\"\r\n )\r\n\r\n # Combine both datasets\r\n data = planned_data + overdue_data\r\n\r\n # Define report columns\r\n columns = [\r\n {\"label\": \"Log ID\", \"fieldname\": \"name\", \"fieldtype\": \"Link\", \"options\": \"Asset Maintenance Log\"},\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Link\", \"options\": \"Asset\"},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"custom_asset_names\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Hospital\", \"fieldname\": \"custom_hospital_name\", \"fieldtype\": \"Link\", \"options\": \"Company\"},\r\n {\"label\": \"Due Date\", \"fieldname\": \"due_date\", \"fieldtype\": \"Date\"},\r\n {\"label\": \"Status\", \"fieldname\": \"maintenance_status\", \"fieldtype\": \"Data\"},\r\n {\"label\": \"Assigned To\", \"fieldname\": \"assign_to_name\", \"fieldtype\": \"Data\"},\r\n ]\r\n\r\n return columns, data\r\n\r\n# Example call\r\ndata = execute(filters)\r\n\r\n\r\n\r\n# def execute(filters=None):\r\n# today = frappe.utils.nowdate()\r\n# next_month_start = frappe.utils.get_first_day(frappe.utils.add_months(today, 1))\r\n# next_month_end = frappe.utils.get_last_day(frappe.utils.add_months(today, 1))\r\n\r\n# data = frappe.db.get_all(\r\n# \"Asset Maintenance Log\",\r\n# filters={\r\n# \"maintenance_status\": \"Planned\",\r\n# \"due_date\": [\"between\", [next_month_start, next_month_end]],\r\n# },\r\n# fields=[\r\n# \"name\", \"asset_name\", \"maintenance_status\",\"custom_asset_names\", \"due_date\", \"assign_to_name\"\r\n# ],\r\n# order_by=\"due_date\"\r\n# )\r\n\r\n# columns = [\r\n# {\"label\": \"Log ID\", \"fieldname\": \"name\", \"fieldtype\": \"Link\", \"options\": \"Asset Maintenance Log\"},\r\n# {\"label\": \"Asset ID\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Link\", \"options\": \"Asset\"},\r\n# {\"label\": \"Asset Name\", \"fieldname\": \"custom_asset_names\", \"fieldtype\": \"Data\"},\r\n# {\"label\": \"Due Date\", \"fieldname\": \"due_date\", \"fieldtype\": \"Date\"},\r\n# {\"label\": \"Status\", \"fieldname\": \"maintenance_status\", \"fieldtype\": \"Data\"},\r\n# {\"label\": \"Assigned To\", \"fieldname\": \"assign_to_name\", \"fieldtype\": \"Data\"},\r\n# ]\r\n\r\n# return columns, data\r\n\r\n# data = execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Planned PM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing User"
|
|
},
|
|
{
|
|
"parent": "Planned PM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Planned PM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Planned PM",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "department",
|
|
"fieldtype": "Link",
|
|
"label": "Department",
|
|
"mandatory": 0,
|
|
"options": "Department",
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "custom_class",
|
|
"fieldtype": "Select",
|
|
"label": "Class",
|
|
"mandatory": 0,
|
|
"options": "\nClass A\nClass B\nClass C",
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "name",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": "frappe.query_reports[\"Asset Up and Down\"] = {\n filters: [\n {\n fieldname: \"asset_name\",\n label: __(\"Asset\"),\n fieldtype: \"Link\",\n options: \"Asset\"\n },\n {\n fieldname: \"department\",\n label: __(\"Department\"),\n fieldtype: \"Link\",\n options: \"Department\"\n },\n {\n fieldname: \"custom_class\",\n label: __(\"Class\"),\n fieldtype: \"Data\"\n }\n ]\n};\n",
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-04-22 14:49:11.436123",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Up and Down",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Up and Down",
|
|
"report_script": "def execute(filters=None):\n if filters is None:\n filters = {}\n\n result = []\n status_count = {}\n\n # Fetch the department, name, and custom_class filter values (if any)\n department = filters.get(\"department\")\n name = filters.get(\"name\")\n custom_class = filters.get(\"custom_class\")\n\n # SQL query to fetch asset ID, asset name, status, department, and class\n if department and custom_class and name:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n department = %s AND custom_class = %s AND name = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (department, custom_class, name), as_dict=True)\n \n elif department and custom_class:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n department = %s AND custom_class = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (department, custom_class), as_dict=True)\n \n elif department and name:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n department = %s AND name = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (department, name), as_dict=True)\n \n elif custom_class and name:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n custom_class = %s AND name = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (custom_class, name), as_dict=True)\n elif department:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n department = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (department,), as_dict=True)\n elif custom_class:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n custom_class = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (custom_class,), as_dict=True)\n elif name:\n query = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n WHERE\n name = %s\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query, (name,), as_dict=True)\n else:\n query_no_filters = \"\"\"\n SELECT\n name AS name,\n asset_name,\n custom_device_status AS status,\n department,\n name,\n custom_class\n FROM\n `tabAsset`\n ORDER BY\n asset_name\n \"\"\"\n result = frappe.db.sql(query_no_filters, as_dict=True)\n\n # Prepare data for the chart\n for row in result:\n status = row['status']\n if status:\n normalized_status = status.strip().lower()\n status_count[normalized_status] = status_count.get(normalized_status, 0) + 1\n\n chart_labels = list(status_count.keys())\n chart_values = list(status_count.values())\n\n columns = [\n {\"fieldname\": \"name\", \"label\": \"Asset ID\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 200},\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Data\", \"width\": 200},\n {\"fieldname\": \"status\", \"label\": \"Status\", \"fieldtype\": \"Data\", \"width\": 100},\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\", \"options\": \"Department\", \"width\": 150},\n {\"fieldname\": \"custom_class\", \"label\": \"Class\", \"fieldtype\": \"Data\", \"width\": 200},\n ]\n\n status_colors = [\"#2ba63d\" if status == 'up' else \"#FF0000\" if status == 'down' else \"#0000FF\" for status in chart_labels]\n\n chart = {\n \"data\": {\n \"labels\": chart_labels,\n \"datasets\": [{\"name\": \"Number of Assets\", \"values\": chart_values}]\n },\n \"type\": \"pie\",\n \"colors\": status_colors\n }\n\n return columns, result, None, chart\n\ndata = execute(filters)\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "repair_status",
|
|
"fieldtype": "Select",
|
|
"label": "Status",
|
|
"mandatory": 0,
|
|
"options": "\nOpen\nWork In Progress\nPending Review\nCompleted\nClosed",
|
|
"parent": "Work Order Status",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "work_order_type",
|
|
"fieldtype": "Link",
|
|
"label": "Work Order Type",
|
|
"mandatory": 0,
|
|
"options": "Issue Type",
|
|
"parent": "Work Order Status",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "wo_name",
|
|
"fieldtype": "Link",
|
|
"label": "Work Order",
|
|
"mandatory": 0,
|
|
"options": "Work_Order",
|
|
"parent": "Work Order Status",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset_type",
|
|
"fieldtype": "Link",
|
|
"label": "Asset Type",
|
|
"mandatory": 0,
|
|
"options": "Asset Type",
|
|
"parent": "Work Order Status",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": "",
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-06-20 13:40:07.036876",
|
|
"module": "Asset Lite",
|
|
"name": "Work Order Status",
|
|
"prepared_report": 0,
|
|
"query": "",
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Work Order Status",
|
|
"report_script": "def get_result(filters):\r\n\r\n columns = [\r\n {\"label\": _(\"Work Order Type\"), \"fieldname\": \"work_order_type\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": _(\"Open\"), \"fieldname\": \"open_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": _(\"Work In Progress\"), \"fieldname\": \"work_in_progress_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": _(\"Pending Review\"), \"fieldname\": \"pending_review_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": _(\"Completed\"), \"fieldname\": \"completed_count\", \"fieldtype\": \"Int\", \"width\": 200},\r\n {\"label\": _(\"Closed\"), \"fieldname\": \"closed_count\", \"fieldtype\": \"Int\", \"width\": 200}\r\n ]\r\n\r\n additional_filters = \"\"\r\n filter_fields = ['work_order_type','repair_status','asset_type']\r\n\r\n for field in filter_fields:\r\n if filters.get(field):\r\n additional_filters = additional_filters + f\" AND wt.{field} = '{filters.get(field)}'\"\r\n\r\n \r\n query = f\"\"\"\r\n SELECT\r\n name as wo_name,\r\n asset_type,\r\n work_order_type,\r\n SUM(CASE WHEN repair_status = 'Open' THEN 1 ELSE 0 END) AS open_count,\r\n SUM(CASE WHEN repair_status = 'Work In Progress' THEN 1 ELSE 0 END) AS work_in_progress_count,\r\n SUM(CASE WHEN repair_status = 'Pending Review' THEN 1 ELSE 0 END) AS pending_review_count,\r\n SUM(CASE WHEN repair_status = 'Completed' THEN 1 ELSE 0 END) AS completed_count,\r\n SUM(CASE WHEN repair_status = 'Closed' THEN 1 ELSE 0 END) AS closed_count\r\n FROM\r\n `tabWork_Order` as wt\r\n WHERE\r\n repair_status IN ('Open', 'Work In Progress', 'Pending Review', 'Completed', 'Closed','Cancelled') {additional_filters}\r\n GROUP BY\r\n work_order_type\r\n \"\"\"\r\n result = frappe.db.sql(query, as_dict=1)\r\n\r\n \r\n #data1 = []\r\n\r\n # Append the columns as the first element\r\n #data1.append(columns)\r\n\r\n # Append the result rows to the data list\r\n #data1.extend(result)\r\n\r\n sql1=\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Open')\"\r\n sql2=\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Work In Progress')\"\r\n sql3=\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Pending Review')\"\r\n sql4=\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Completed')\"\r\n sql5=\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Closed')\"\r\n sql6=\"SELECT repair_status, COUNT(*) as count FROM `tabWork_Order` WHERE repair_status IN ('Open', 'Work In Progress', 'Pending Review', 'Completed', 'Closed', 'Cancelled')\"\r\n report_summary = [\r\n {\"value\": row.count, \"label\": \"Open\"} for row in frappe.db.sql(sql1, as_dict=True)]+[\r\n {\"value\": row.count, \"label\": \"Work In Progress\"} for row in frappe.db.sql(sql2, as_dict=True)]+[\r\n {\"value\": row.count, \"label\": \"Pending Review\"} for row in frappe.db.sql(sql3, as_dict=True)]+[\r\n {\"value\": row.count, \"label\": \"Completed\"} for row in frappe.db.sql(sql4, as_dict=True)]+[\r\n {\"value\": row.count, \"label\": \"Closed\"} for row in frappe.db.sql(sql5, as_dict=True)]+[\r\n {\"value\": row.count, \"label\": \"Total Work Orders\"} for row in frappe.db.sql(sql6, as_dict=True)\r\n ]\r\n\r\n #chart = {\r\n # \"data\": {\r\n # \"labels\": [row['label'] for row in report_summary],\r\n # \"datasets\": [\r\n # {\r\n # \"name\": \"Count\",\r\n # \"values\": [row['value'] for row in report_summary],\r\n # }\r\n # ]\r\n # },\r\n # \"type\": \"bar\"\r\n #}\r\n chart = {\r\n \"data\": {\r\n \"labels\": [row['work_order_type'] for row in result],\r\n \"datasets\": [\r\n {\r\n \"name\": \"Open\",\r\n \"values\": [row['open_count'] for row in result],\r\n },\r\n {\r\n \"name\": \"Work In Progress\",\r\n \"values\": [row['work_in_progress_count'] for row in result],\r\n },\r\n {\r\n \"name\": \"Pending Review\",\r\n \"values\": [row['pending_review_count'] for row in result],\r\n },\r\n {\r\n \"name\": \"Completed\",\r\n \"values\": [row['completed_count'] for row in result],\r\n },\r\n {\r\n \"name\": \"Closed\",\r\n \"values\": [row['closed_count'] for row in result],\r\n },\r\n ]\r\n },\r\n \"type\": \"bar\",\r\n \"barOptions\": {\r\n \"stacked\": 1,\r\n \"spaceRatio\": 0.6\r\n },\r\n \"colors\": [\"#CCCCB7\", \"#52B2BF\", \"#9EC1A4\", \"#058D7C\", \"#A3A5CF\"],\r\n }\r\n return columns,result,None,chart,report_summary\r\n\r\n\r\ndata = get_result(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Work Order Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Status",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "month",
|
|
"fieldtype": "Select",
|
|
"label": "Month",
|
|
"mandatory": 0,
|
|
"options": "\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember",
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "year",
|
|
"fieldtype": "Select",
|
|
"label": "Year",
|
|
"mandatory": 0,
|
|
"options": "\n2020\n2021\n2022\n2023\n2024\n2025\n2026\n2027\n2028\n2029\n2030",
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "supplier",
|
|
"fieldtype": "Link",
|
|
"label": "Supplier",
|
|
"mandatory": 0,
|
|
"options": "Supplier",
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset ID",
|
|
"mandatory": 0,
|
|
"options": "Asset",
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset_type",
|
|
"fieldtype": "Link",
|
|
"label": "Asset Type",
|
|
"mandatory": 0,
|
|
"options": "Asset Type",
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-06-20 11:43:00.066139",
|
|
"module": "Asset Lite",
|
|
"name": "Overall Work Order Report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Overall Work Order Report",
|
|
"report_script": "\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # Define Filters\r\n filters_dict = {}\r\n\r\n # Apply Company Filter\r\n if filters.get(\"company\"):\r\n filters_dict[\"company\"] = filters.get(\"company\")\r\n \r\n if filters.get(\"asset\"):\r\n filters_dict[\"asset\"] = filters.get(\"asset\")\r\n \r\n if filters.get(\"asset_type\"):\r\n filters_dict[\"asset_type\"] = filters.get(\"asset_type\")\r\n \r\n if filters.get(\"supplier\"):\r\n filters_dict[\"supplier\"] = filters.get(\"supplier\")\r\n\r\n # Apply Month & Year Filters\r\n if filters.get(\"year\"):\r\n year_num = int(filters[\"year\"]) # Ensure it's an integer\r\n\r\n if filters.get(\"month\"):\r\n # Map month names to numbers\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12\r\n }\r\n month_num = month_map.get(filters[\"month\"])\r\n\r\n if month_num:\r\n first_day = f\"{year_num}-{month_num:02d}-01\"\r\n last_day = frappe.utils.get_last_day(first_day) # Get last day of the month dynamically\r\n filters_dict[\"creation\"] = [\"between\", [first_day, last_day]]\r\n else:\r\n # If only year is provided, filter for the entire year\r\n first_day = f\"{year_num}-01-01\"\r\n last_day = f\"{year_num}-12-31\"\r\n filters_dict[\"creation\"] = [\"between\", [first_day, last_day]]\r\n\r\n # Fetch Work Orders with Filters\r\n work_orders = frappe.get_all(\r\n \"Work_Order\",\r\n filters=filters_dict,\r\n fields=[\r\n \"name\", \"company\", \"work_order_type\", \"repair_status\", \"total_repair_cost\",\r\n \"completion_date\", \"first_responded_on\", \"custom_deadline_date\", \"failure_date\",\r\n \"supplier\", \"serial_number\", \"asset_name\", \"repair_cost\", \"asset\", \"asset_type\",\r\n \"assigned_technician\", \"custom_maintenance_manager\", \"custom_priority_\", \"creation\"\r\n ],\r\n order_by=\"creation desc\"\r\n )\r\n\r\n # Define Report Columns\r\n columns = [\r\n {\"label\": \"Work Order No\", \"fieldname\": \"name\", \"fieldtype\": \"Link\", \"options\": \"Work_Order\", \"width\": 150},\r\n {\"label\": \"Hospital Name\", \"fieldname\": \"company\", \"fieldtype\": \"Data\", \"width\": 120},\r\n {\"label\": \"Asset ID\", \"fieldname\": \"asset\", \"fieldtype\": \"Link\", \"options\": \"Asset\", \"width\": 120},\r\n {\"label\": \"Asset Type\", \"fieldname\": \"asset_type\", \"fieldtype\": \"Link\", \"options\": \"Asset Type\", \"width\": 120},\r\n {\"label\": \"Asset Name\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Data\", \"width\": 180},\r\n {\"label\": \"Supplier\", \"fieldname\": \"supplier\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Priority\", \"fieldname\": \"custom_priority_\", \"fieldtype\": \"Data\", \"width\": 100},\r\n {\"label\": \"Work Order Type\", \"fieldname\": \"work_order_type\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Repair Status\", \"fieldname\": \"repair_status\", \"fieldtype\": \"Data\", \"width\": 120},\r\n {\"label\": \"Spare Used - Qty\", \"fieldname\": \"spares_used\", \"fieldtype\": \"Data\", \"width\": 250},\r\n {\"label\": \"Spare Cost (SAR)\", \"fieldname\": \"spare_cost\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n {\"label\": \"Purchase Items - Qty\", \"fieldname\": \"invoice_items\", \"fieldtype\": \"Data\", \"width\": 170},\r\n {\"label\": \"Purchase Cost (SAR)\", \"fieldname\": \"repair_cost\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n {\"label\": \"Total Repair Cost (SAR)\", \"fieldname\": \"total_repair_cost\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n {\"label\": \"Failure Date\", \"fieldname\": \"failure_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"First Responded\", \"fieldname\": \"first_responded_on\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"Completion Date\", \"fieldname\": \"completion_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n {\"label\": \"Deadline Date\", \"fieldname\": \"custom_deadline_date\", \"fieldtype\": \"Date\", \"width\": 120},\r\n \r\n {\"label\": \"Serial Number\", \"fieldname\": \"serial_number\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Assigned To\", \"fieldname\": \"custom_maintenance_manager\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Created On\", \"fieldname\": \"creation\", \"fieldtype\": \"Datetime\", \"width\": 150}\r\n ]\r\n\r\n # Fetch Spare Parts for Each Work Order\r\n for wo in work_orders:\r\n spare_parts = frappe.get_all(\r\n \"Asset Repair Consumed Item\",\r\n filters={\"parent\": wo[\"name\"]},\r\n fields=[\"item_code\", \"consumed_quantity\"]\r\n )\r\n\r\n if spare_parts:\r\n wo[\"spares_used\"] = \"\\n\".join([f\"{sp['item_code']} - {sp['consumed_quantity']}\" for sp in spare_parts])\r\n else:\r\n wo[\"spares_used\"] = \"\"\r\n\r\n # Fetch Purchase Invoice linked to Work Order from invoice_table\r\n invoice_links = frappe.get_all(\r\n \"PI Table\",\r\n filters={\"parent\": wo[\"name\"]},\r\n fields=[\"purchase_invoice\"]\r\n )\r\n\r\n invoice_items_list = []\r\n for invoice in invoice_links:\r\n if invoice[\"purchase_invoice\"]:\r\n items = frappe.get_all(\r\n \"Purchase Invoice Item\",\r\n filters={\"parent\": invoice[\"purchase_invoice\"]},\r\n fields=[\"item_code\", \"qty\"]\r\n )\r\n invoice_items_list.extend([f\"{item['item_code']} - {item['qty']}\" for item in items])\r\n\r\n wo[\"invoice_items\"] = \"\\n\".join(invoice_items_list) if invoice_items_list else \" \"\r\n\r\n # **Calculate Spare Cost** = Total Repair Cost - Purchase Cost\r\n wo[\"spare_cost\"] = (wo.get(\"total_repair_cost\") or 0) - (wo.get(\"repair_cost\") or 0)\r\n\r\n return columns, work_orders\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Overall Work Order Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Sales Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 0,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "custom_asset_type",
|
|
"fieldtype": "Link",
|
|
"label": "Asset Type",
|
|
"mandatory": 0,
|
|
"options": "Asset Type",
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": "",
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-07-30 21:08:29.851080",
|
|
"module": "Asset Lite",
|
|
"name": "Asset Up and Down by Asset",
|
|
"prepared_report": 1,
|
|
"query": null,
|
|
"ref_doctype": "Asset",
|
|
"reference_report": null,
|
|
"report_name": "Asset Up and Down by Asset",
|
|
"report_script": "def execute(filters=None):\r\n if filters is None:\r\n filters = {}\r\n\r\n result = []\r\n status_count = {}\r\n\r\n # Fetch the department, company, and custom_class filter values (if any)\r\n department = filters.get(\"department\")\r\n company = filters.get(\"company\")\r\n custom_asset_type = filters.get(\"custom_asset_type\")\r\n custom_class = filters.get(\"custom_class\")\r\n\r\n \r\n if company and custom_asset_type:\r\n query = \"\"\"\r\n SELECT\r\n company AS company,\r\n asset_name,\r\n custom_asset_type AS custom_asset_type,\r\n custom_device_status AS status,\r\n department,\r\n company,\r\n custom_class\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n company = %s AND custom_asset_type = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, (company, custom_asset_type), as_dict=True)\r\n\r\n elif company:\r\n query = \"\"\"\r\n SELECT\r\n company AS company,\r\n asset_name,\r\n custom_asset_type AS custom_asset_type,\r\n custom_device_status AS status,\r\n department,\r\n company,\r\n custom_class\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n company = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, (company,), as_dict=True)\r\n\r\n elif custom_asset_type:\r\n query = \"\"\"\r\n SELECT\r\n company AS company,\r\n asset_name,\r\n custom_asset_type AS custom_asset_type,\r\n custom_device_status AS status,\r\n department,\r\n company,\r\n custom_class\r\n FROM\r\n `tabAsset`\r\n WHERE\r\n custom_asset_type = %s\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query, (custom_asset_type,), as_dict=True)\r\n\r\n else:\r\n query_no_filters = \"\"\"\r\n SELECT\r\n company AS company,\r\n asset_name,\r\n custom_asset_type AS custom_asset_type,\r\n custom_device_status AS status,\r\n department,\r\n company,\r\n custom_class\r\n FROM\r\n `tabAsset`\r\n ORDER BY\r\n asset_name\r\n \"\"\"\r\n result = frappe.db.sql(query_no_filters, as_dict=True)\r\n\r\n # Prepare data for the chart\r\n for row in result:\r\n status = row['status']\r\n if status:\r\n normalized_status = status.strip().lower()\r\n status_count[normalized_status] = status_count.get(normalized_status, 0) + 1\r\n\r\n chart_labels = list(status_count.keys())\r\n chart_values = list(status_count.values())\r\n\r\n columns = [\r\n {\"fieldname\": \"company\", \"label\": \"Hospital Name\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 200},\r\n {\"fieldname\": \"asset_name\", \"label\": \"Asset Name\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"fieldname\": \"custom_asset_type\", \"label\": \"Asset Type\", \"fieldtype\": \"Link\", \"options\": \"Asset Type\",\"width\": 200},\r\n {\"fieldname\": \"status\", \"label\": \"Status\", \"fieldtype\": \"Data\", \"width\": 100},\r\n {\"fieldname\": \"department\", \"label\": \"Department\", \"fieldtype\": \"Link\", \"options\": \"Department\", \"width\": 150},\r\n {\"fieldname\": \"custom_class\", \"label\": \"Class\", \"fieldtype\": \"Data\", \"width\": 200},\r\n ]\r\n\r\n status_colors = [\"#2ba63d\" if status == 'up' else \"#FF0000\" if status == 'down' else \"#0000FF\" for status in chart_labels]\r\n\r\n chart = {\r\n \"data\": {\r\n \"labels\": chart_labels,\r\n \"datasets\": [{\"company\": \"Number of Assets\", \"values\": chart_values}]\r\n },\r\n \"type\": \"donut\",\r\n \"colors\": status_colors\r\n }\r\n\r\n return columns, result, None, chart\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Accounts User"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Asset Up and Down by Asset",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance User"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "company",
|
|
"fieldtype": "Link",
|
|
"label": "Hospital Name",
|
|
"mandatory": 0,
|
|
"options": "Company",
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
},
|
|
{
|
|
"default": null,
|
|
"fieldname": "asset_type",
|
|
"fieldtype": "Link",
|
|
"label": "Asset Type",
|
|
"mandatory": 0,
|
|
"options": "Asset Type",
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": null,
|
|
"json": null,
|
|
"letter_head": "",
|
|
"modified": "2025-06-20 10:46:08.247007",
|
|
"module": "Asset Lite",
|
|
"name": "Work Order Priority Report",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Work Order Priority Report",
|
|
"report_script": "\r\ndef execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n conditions = [\"wo.custom_priority_ IS NOT NULL\"] # Exclude NULL priorities\r\n query_params = {}\r\n\r\n # Apply Company Filter\r\n if filters.get(\"company\"):\r\n conditions.append(\"wo.company = %(company)s\")\r\n query_params[\"company\"] = filters.get(\"company\")\r\n \r\n if filters.get(\"asset_type\"):\r\n conditions.append(\"wo.asset_type = %(asset_type)s\")\r\n query_params[\"asset_type\"] = filters.get(\"asset_type\")\r\n\r\n # Construct WHERE clause safely\r\n where_clause = \"WHERE \" + \" AND \".join(conditions) if conditions else \"\"\r\n\r\n # SQL Query\r\n query = f\"\"\"\r\n SELECT\r\n wo.company AS company,\r\n wo.asset_type AS asset_type,\r\n wo.custom_priority_ AS priority,\r\n COUNT(wo.name) AS work_order_count\r\n FROM \r\n `tabWork_Order` wo\r\n {where_clause}\r\n GROUP BY\r\n wo.company, wo.custom_priority_\r\n ORDER BY \r\n wo.company, work_order_count DESC\r\n \"\"\"\r\n\r\n # Execute query with safe parameters\r\n result = frappe.db.sql(query, query_params, as_dict=True)\r\n\r\n # Define Report Columns\r\n columns = [\r\n {\"label\": \"Company\", \"fieldname\": \"company\", \"fieldtype\": \"Link\", \"options\": \"Company\", \"width\": 200},\r\n {\"label\": \"Priority\", \"fieldname\": \"priority\", \"fieldtype\": \"Data\", \"width\": 150},\r\n {\"label\": \"Work Order Count\", \"fieldname\": \"work_order_count\", \"fieldtype\": \"Int\", \"width\": 150}\r\n ]\r\n\r\n # Prepare data for Stacked Chart\r\n company_wise_data = {} # Dictionary to store company-wise work order counts by priority\r\n priority_list = set() # To keep track of all unique priorities\r\n\r\n for row in result:\r\n company = row[\"company\"]\r\n priority = row[\"priority\"]\r\n count = row[\"work_order_count\"]\r\n\r\n priority_list.add(priority) # Store unique priorities\r\n\r\n if company not in company_wise_data:\r\n company_wise_data[company] = {}\r\n\r\n company_wise_data[company][priority] = count\r\n\r\n # Convert dictionary to chart format\r\n labels = list(company_wise_data.keys()) # X-Axis: Companies\r\n datasets = []\r\n\r\n priority_list = sorted(priority_list) # Ensure consistent order for priority labels\r\n\r\n # Priority Color Mapping\r\n color_map = {\r\n \"Urgent\": \"red\",\r\n \"Normal\": \"blue\"\r\n }\r\n\r\n # Prepare datasets for each priority\r\n for priority in priority_list:\r\n dataset = {\r\n \"name\": priority,\r\n \"values\": [company_wise_data[company].get(priority, 0) for company in labels],\r\n \"chartType\": \"bar\"\r\n }\r\n datasets.append(dataset)\r\n\r\n # Define Stacked Chart\r\n chart = {\r\n \"data\": {\r\n \"labels\": labels,\r\n \"datasets\": datasets\r\n },\r\n \"type\": \"bar\", # Bar Chart\r\n \"colors\": [color_map.get(priority, \"gray\") for priority in priority_list], # Apply colors\r\n \"barOptions\": {\"stacked\": True} # Enable stacking\r\n }\r\n\r\n return columns, result, None, chart # Returning stacked chart\r\n\r\ndata = execute(filters)\r\n",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "End user"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Work Order Priority Report",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Sales Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
},
|
|
{
|
|
"add_total_row": 1,
|
|
"columns": [],
|
|
"disabled": 0,
|
|
"docstatus": 0,
|
|
"doctype": "Report",
|
|
"filters": [
|
|
{
|
|
"default": null,
|
|
"fieldname": "Asset",
|
|
"fieldtype": "Link",
|
|
"label": "Asset",
|
|
"mandatory": 0,
|
|
"options": null,
|
|
"parent": "Repair Cost",
|
|
"parentfield": "filters",
|
|
"parenttype": "Report",
|
|
"wildcard_filter": 0
|
|
}
|
|
],
|
|
"is_standard": "No",
|
|
"javascript": "frappe.query_reports[\"Repair Cost\"] = {\n filters: [\n {\n fieldname: \"year\",\n label: __(\"Year\"),\n fieldtype: \"Int\",\n default: new Date().getFullYear(), // Current Year\n reqd: 1 // Make it mandatory\n },\n {\n fieldname: \"month\",\n label: __(\"Month\"),\n fieldtype: \"Select\",\n options: [\n \n \" \", \"January\", \"February\", \"March\", \"April\", \"May\", \"June\",\n \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"\n ],\n \n },\n \n {\n fieldname: \"class\",\n label: __(\"Class\"),\n fieldtype: \"Select\",\n options: [\n \"\",\"Class A\",\"Class B\",\"Class C\"\n ],\n \n },\n {\n fieldname: \"vendor\",\n label: __(\"Vendor\"),\n fieldtype: \"Link\",\n options: \"Supplier\"\n },\n {\n fieldname: \"asset_name\",\n label: __(\"Asset\"),\n fieldtype: \"Link\",\n options: \"Asset\"\n \n },\n {\n fieldname: \"work_order\",\n label: __(\"Work Order\"),\n fieldtype: \"Link\",\n options: \"Work_Order\"\n \n },\n {\n fieldname: \"department\",\n label: __(\"Department\"),\n fieldtype: \"Link\",\n options: \"Department\"\n \n }\n \n \n ]\n};",
|
|
"json": null,
|
|
"letter_head": null,
|
|
"modified": "2025-05-22 15:11:38.867845",
|
|
"module": "Asset Lite",
|
|
"name": "Repair Cost",
|
|
"prepared_report": 0,
|
|
"query": null,
|
|
"ref_doctype": "Work_Order",
|
|
"reference_report": null,
|
|
"report_name": "Repair Cost",
|
|
"report_script": "def execute(filters=None):\r\n if not filters:\r\n filters = {}\r\n\r\n # Ensure Year is provided\r\n if not filters.get('year'):\r\n frappe.throw(_(\"Please select a Year to proceed.\"))\r\n\r\n def get_days_in_month(year: int, month_name: str) -> int:\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12,\r\n }\r\n month = month_map.get(month_name)\r\n month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\n # Handle leap year for February\r\n if month == 2:\r\n if (int(year) % 4 == 0 and int(year) % 100 != 0) or (int(year) % 400 == 0):\r\n return 29\r\n else:\r\n return 28\r\n else:\r\n return month_days[month - 1]\r\n\r\n def get_dates_of_month(year: int, month_name: str) -> list:\r\n total_days = get_days_in_month(year, month_name)\r\n month_map = {\r\n \"January\": 1, \"February\": 2, \"March\": 3, \"April\": 4,\r\n \"May\": 5, \"June\": 6, \"July\": 7, \"August\": 8,\r\n \"September\": 9, \"October\": 10, \"November\": 11, \"December\": 12,\r\n }\r\n month = month_map.get(month_name)\r\n return [f\"{year}-{month:02d}-{day:02d}\" for day in range(1, total_days + 1)]\r\n\r\n columns = [\r\n {\"label\": \"Asset\", \"fieldname\": \"asset_name\", \"fieldtype\": \"Link\",\"options\": \"Asset\", \"width\": 200},\r\n {\"label\": \"Work Order\", \"fieldname\": \"work_order\", \"fieldtype\": \"Link\",\"options\": \"Work_Order\", \"width\": 200},\r\n {\"label\": \"Item\", \"fieldname\": \"item_code\", \"fieldtype\": \"Data\", \"width\": 200},\r\n {\"label\": \"Quantity\", \"fieldname\": \"quantity\", \"fieldtype\": \"Float\", \"width\": 120},\r\n {\"label\": \"Amount\", \"fieldname\": \"amount\", \"fieldtype\": \"Currency\", \"width\": 120},\r\n ]\r\n\r\n result1 = []\r\n year = filters.get('year')\r\n month = filters.get('month')\r\n department = filters.get('department') # Optional department filter\r\n asset_class = filters.get('class') # Optional class filter\r\n vendor = filters.get('vendor') # Optional vendor filter\r\n asset_name = filters.get('asset_name')\r\n work_order = filters.get('work_order')\r\n\r\n # If month is not provided, show data for the whole year\r\n if month:\r\n dates_in_month = get_dates_of_month(year, month)\r\n date_filter = \"wo.failure_date BETWEEN %(start_date)s AND %(end_date)s\"\r\n else:\r\n date_filter = \"YEAR(wo.failure_date) = %(year)s\" # Filter by year only\r\n\r\n # Dynamically construct where clause for optional filters\r\n where_conditions = [date_filter]\r\n if department:\r\n where_conditions.append(\"wo.department = %(department)s\")\r\n if asset_class:\r\n where_conditions.append(\"asset.custom_class = %(class)s\")\r\n if vendor:\r\n where_conditions.append(\"wo.vendor = %(vendor)s\") # Vendor filter directly from Work Order\r\n if asset_name:\r\n where_conditions.append(\"asset.name = %(asset_name)s\") \r\n if work_order:\r\n where_conditions.append(\"wo.name = %(work_order)s\")\r\n\r\n # Construct final WHERE clause\r\n where_clause = \" AND \".join(where_conditions)\r\n\r\n # Fetch data for Work Orders, Material Requests, and Purchase Orders\r\n results = frappe.db.sql(\r\n f\"\"\"\r\n SELECT \r\n wo.name AS work_order,\r\n asset.name as asset_name,\r\n mri.item_code AS item_code,\r\n SUM(mri.qty) AS quantity,\r\n SUM(po_item.rate * mri.qty) AS amount\r\n FROM `tabWork_Order` wo\r\n LEFT JOIN `tabMaterial Request` mr ON mr.custom_work_order = wo.name\r\n LEFT JOIN `tabMaterial Request Item` mri ON mri.parent = mr.name\r\n LEFT JOIN `tabPurchase Order Item` po_item ON po_item.material_request = mr.name AND po_item.item_code = mri.item_code\r\n LEFT JOIN `tabAsset` asset ON wo.asset = asset.name\r\n WHERE {where_clause}\r\n GROUP BY wo.name, asset.name, mri.item_code\r\n ORDER BY amount ASC\r\n \"\"\",\r\n {\r\n \"start_date\": dates_in_month[0] if month else None,\r\n \"end_date\": dates_in_month[-1] if month else None,\r\n \"year\": year,\r\n \"department\": department,\r\n \"class\": asset_class,\r\n \"vendor\": vendor, # Pass the vendor filter value\r\n \"work_order\": work_order,\r\n \"asset_name\": asset_name,\r\n },\r\n as_dict=True\r\n )\r\n\r\n ## Prepare final report data\r\n # for row in results:\r\n # result1.append({\r\n # \"asset_name\": row.get(\"asset_name\"),\r\n # \"work_order\": row.get(\"work_order\"),\r\n # \"item_code\": row.get(\"item_code\"),\r\n # \"quantity\": float(row.get(\"quantity\") or 0),\r\n # \"amount\": float(row.get(\"amount\") or 0),\r\n # })\r\n \r\n for row in results:\r\n if row.get(\"item_code\"): # **Ensures only rows with an item_code are included**\r\n result1.append({\r\n \"asset_name\": row.get(\"asset_name\"),\r\n \"work_order\": row.get(\"work_order\"),\r\n \"item_code\": row.get(\"item_code\"),\r\n \"quantity\": float(row.get(\"quantity\") or 0),\r\n \"amount\": float(row.get(\"amount\") or 0),\r\n })\r\n\r\n return columns, result1\r\n\r\ndata=execute(filters)",
|
|
"report_type": "Script Report",
|
|
"roles": [
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Quality Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Manufacturing Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Technician"
|
|
},
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Maintenance User"
|
|
},
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "System Manager"
|
|
},
|
|
{
|
|
"parent": "Repair Cost",
|
|
"parentfield": "roles",
|
|
"parenttype": "Report",
|
|
"role": "Finance Manager"
|
|
}
|
|
],
|
|
"timeout": 0
|
|
}
|
|
] |