Resolves Event templating

Fixes #12
This commit is contained in:
meichthys 2025-10-08 04:52:26 +00:00
parent a3499e3ddf
commit b25601eeec
4 changed files with 88 additions and 7 deletions

View File

@ -13,5 +13,41 @@ frappe.ui.form.on('Church Event', {
}
});
frm.set_value('attendance_total', total_attendance);
},
refresh: function(frm) {
// Add template-fill functionality if we have a template specified and this is a new form
if (!frm.is_new() || !frm.doc.type) return;
// Check if the selected type has a template
frappe.db.get_value('Church Event Type', frm.doc.type, 'template_event').then(r => {
if (!r.message?.template_event) return;
// Add Fill from Template` button if template exists
frm.add_custom_button(__('Fill from Template'), function() {
frappe.call({
method: 'church.church_ministries.doctype.church_event.church_event.apply_template',
args: {
source_name: r.message.template_event,
target_doc: frm.doc
},
callback: function(r) {
if (!r.message) return;
Object.keys(r.message).forEach(fieldname => {
frm.set_value(fieldname, r.message[fieldname]);
});
frappe.msgprint({
message: __('Template applied successfully'),
indicator: 'green',
alert: true
});
}
});
});
});
},
type: function(frm) {
// Refresh form to re-evaluate button visibility
frm.trigger('refresh');
}
});
});

View File

@ -7,8 +7,8 @@
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"event_name",
"type",
"event_name",
"all_day",
"start_date",
"start_time",
@ -116,7 +116,7 @@
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2025-09-29 23:46:26.798142",
"modified": "2025-10-07 23:45:56.379848",
"modified_by": "Administrator",
"module": "Church Ministries",
"name": "Church Event",
@ -136,7 +136,6 @@
"write": 1
}
],
"quick_entry": 1,
"row_format": "Dynamic",
"sort_field": "modified",
"sort_order": "DESC",

View File

@ -1,9 +1,37 @@
# Copyright (c) 2025, meichthys and contributors
# For license information, please see license.txt
# import frappe
import frappe
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
class ChurchEvent(Document):
pass
@frappe.whitelist()
def apply_template(source_name):
# Get template document
template = frappe.get_doc("Church Event", source_name)
template_dict = template.as_dict()
# Specify which fields to include (whitelist approach)
include_fields = ["address", "all_day", "description"]
copied_doc = {"attendance": {}}
for field in include_fields:
if field in template_dict:
copied_doc[field] = template_dict[field]
# Copy attendance child table
if template_dict.get("attendance"):
copied_doc["attendance"] = []
for child_row in template_dict["attendance"]:
new_row = {} # Create NEW dict for each row
for child_field in child_row:
new_row[child_field] = child_row[child_field]
copied_doc["attendance"].append(new_row) # Append after building complete row
return copied_doc

View File

@ -8,6 +8,9 @@
"engine": "InnoDB",
"field_order": [
"type",
"column_break_pgdp",
"template_event",
"section_break_pepr",
"description"
],
"fields": [
@ -26,6 +29,21 @@
"label": "Type of Event",
"reqd": 1,
"unique": 1
},
{
"fieldname": "column_break_pgdp",
"fieldtype": "Column Break"
},
{
"description": "Select an existing event here to use it as a template for creating future events of the same type.",
"fieldname": "template_event",
"fieldtype": "Link",
"label": "Template Event",
"options": "Church Event"
},
{
"fieldname": "section_break_pepr",
"fieldtype": "Section Break"
}
],
"grid_page_length": 50,
@ -36,7 +54,7 @@
"link_fieldname": "type"
}
],
"modified": "2025-09-08 23:01:03.227258",
"modified": "2025-10-07 22:26:25.870247",
"modified_by": "Administrator",
"module": "Church Ministries",
"name": "Church Event Type",
@ -61,4 +79,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
}