why is this code not working?
Hi @LeTienIT:
As far I know, get_events_method
expects a path to python method … This can be done with .py file or with a server script (API type)
Okay. So I need to know the structure to configure the calendar? How should I write a .py function to meet the need to display the total number of projects instead of each one?
Hi @LeTienIT:
It could be done without writing .py file.
Server script lets you create API method from UI.
Example:
So, from your client script
get_events_method: "get_events"
Make sure that field_map
fits with API method response.
Anyway … I don’t understand your use case for total number of projects on calendar view … Can you ellaborate further?
Hope this helps.
Okay. Take a photo below. This is the default display when I create a project calendar. You can see that if there are many projects on consecutive days, it looks very difficult. So what I mean is I want to change the way this is displayed. Instead of displaying each project name, just one number is the total number of projects that day. Or is there another easier way to display it? or maybe show me how I can adjust the css of this display?
Can you please try this code:
frappe.views.calendar[“Project”] = {
field_map: {
“start”: “expected_start_date”,
“end”: “expected_end_date”,
“id”: “name”,
“title”: “custom_khách_hà ng”,
“allDay”: “allDay”,
“progress”: “progress”
},
get_events_method: function(start, end, callback) {
console.log(“Fetching events from”, start.format(), “to”, end.format());
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Project",
fields: ["name", "expected_start_date", "expected_end_date", "custom_khách_hà ng", "progress"],
filters: [
["expected_start_date", ">=", start.format()],
["expected_start_date", "<=", end.format()]
]
},
callback: function(response) {
console.log("API call completed");
if (response.message) {
let events = response.message.map(function(project) {
return {
id: project.name,
title: project.custom_khách_hà ng,
start: project.expected_start_date,
end: project.expected_end_date,
allDay: true,
progress: project.progress
};
});
console.log("Events to render:", events);
callback(events);
} else {
console.error("No response message from server");
}
}
});
}
};
Hi @LeTienIT:
Server script:
data = frappe.db.sql("""SELECT CONCAT(cast(COUNT(name)as CHAR), " projects") as subject, date(expected_start_date) as expected_start_date from `tabProject` group by date(expected_start_date)""", as_dict=True)
frappe.response["message"] = data
Client script for Project doctype:
frappe.views.calendar['Project'] = {
field_map: {
start: "expected_start_date",
end: "expected_start_date",
id: "subject",
title: "subject",
allDay: 1,
},
get_events_method: "get_events"
}
Hope this helps.