Seera/DEPLOY_BACKEND.md
2025-11-03 13:38:27 +05:30

4.0 KiB

Backend Deployment Guide

Quick Deploy

Copy the updated frappe_dashboard_api.py to your Frappe server:

# Step 1: Copy file to Frappe app
scp frappe_dashboard_api.py user@your-server:/tmp/

# Step 2: SSH to server
ssh user@your-server

# Step 3: Move to correct location
cd /path/to/frappe-bench/apps/asset_lite
mkdir -p asset_lite/api
cp /tmp/frappe_dashboard_api.py asset_lite/api/dashboard_api.py

# Step 4: Restart Frappe
bench restart

# Step 5: Test the API
curl "https://seeraasm-med.seeraarabia.com/api/method/asset_lite.api.dashboard_api.get_number_cards"

What This API Does

1. get_number_cards()

Returns counts for KPI cards:

  • Total Assets
  • Open Work Orders
  • Work Orders In Progress
  • Completed Work Orders

2. list_dashboard_charts()

Lists all public Dashboard Charts with their configuration

3. get_dashboard_chart_data(chart_name, filters)

Supports BOTH:

  • Report Charts - Uses the Report's query and x/y field configuration
  • Custom Charts - Queries the source doctype directly based on based_on and value_based_on fields

4. get_repair_cost_by_item(year)

Specialized endpoint for repair cost analysis

What Was Fixed

Issue 1: "Unknown column 'label'"

  • Removed label field from queries
  • Now only queries y_field and color

Issue 2: "DashboardChart object has no attribute 'get_chart_data'"

  • Replaced with custom SQL queries
  • Reads document_type, based_on, value_based_on fields
  • Builds appropriate GROUP BY queries

Issue 3: Empty datasets

  • Added proper error handling
  • Logs errors to Frappe error log
  • Returns meaningful error messages

Chart Types Supported

Report Charts (with "Use Report Chart" checked)

Examples from your Frappe:

  • Up & Down Time Chart
  • Work Order Status Chart
  • PPM Status
  • PPM Template Counts
  • Repair Cost

Configuration Required:

  • Chart Type: Report
  • Report Name: Valid report name
  • Use Report Chart: ✓ checked
  • X Field: Field name for X-axis
  • Y Axis: At least one row with y_field and color

Custom Charts (DocType-based)

Examples from your Frappe:

  • Maintenance - Asset wise Count
  • Asset Maintenance Assignees Status Count
  • Asset Maintenance Frequency Chart

Configuration Required:

  • Chart Type: Custom
  • Document Type: Source doctype (e.g., "Asset Maintenance")
  • Based On: Field to group by (e.g., "assigned_to")
  • Value Based On: Field to count (optional, defaults to "name")

Troubleshooting

Charts still showing "No data"

  1. Check chart exists:
SELECT name, chart_name, chart_type, document_type, based_on 
FROM `tabDashboard Chart` 
WHERE name = 'Up & Down Time Chart';
  1. Check if Public:
SELECT name, is_public FROM `tabDashboard Chart`;
  1. Test API directly:
# In browser (while logged in):
https://seeraasm-med.seeraarabia.com/api/method/asset_lite.api.dashboard_api.get_dashboard_chart_data?chart_name=Up%20%26%20Down%20Time%20Chart
  1. Check Frappe logs:
bench logs
# or
tail -f logs/web.error.log

API returns 404

  • Backend file not copied to correct location
  • App name is not asset_lite (update paths in API calls)

API returns 500

  • Check Frappe error logs
  • Verify chart configuration matches what API expects

Next Steps After Deploy

  1. Deploy this file to your Frappe server
  2. Restart: bench restart
  3. Hard refresh your React dashboard (Ctrl+Shift+R)
  4. Check browser console for data logs
  5. Charts should now display with real data!

Expected Console Output (Success)

After successful deployment, you should see:

Up & Down Time Chart data: {labels: ["up", "down"], datasets: [{values: [7092, 16]}], type: "Pie"}
Work Order Status Chart data: {labels: ["Open", "Completed"], datasets: [{values: [3, 2]}], type: "Bar"}
Maintenance - Asset wise Count data: {labels: ["Asset1", "Asset2"], datasets: [{values: [10, 5]}], type: "Bar"}

File to deploy: frappe_dashboard_api.py
Location: asset_lite/api/dashboard_api.py
Restart: bench restart