Add button to Alms Request to create asociated Expense

Fixes #83
This commit is contained in:
meichthys 2025-11-13 04:25:10 +00:00
parent c143f7b5b4
commit 59f17d2cff
4 changed files with 50 additions and 8 deletions

View File

@ -1,8 +1,23 @@
// Copyright (c) 2025, meichthys and contributors
// For license information, please see license.txt
// frappe.ui.form.on("Church Alms Request", {
// refresh(frm) {
frappe.ui.form.on('Church Alms Request', {
refresh(frm) {
// Add a custom button that creates an Expense from the Alms Request
frm.add_custom_button(__('Create Expense'), function () {
frappe.call({
method: 'church.church_finances.doctype.church_alms_request.church_alms_request.create_expense',
args: {
alms_request_name: frm.doc.name
},
callback: function () {
frm.reload_doc();
}
});
});
},
});
// },
// });

View File

@ -12,6 +12,7 @@
"column_break_ixvv",
"status",
"amount",
"expense_type",
"section_break_olzm",
"description"
],
@ -67,12 +68,19 @@
"fieldtype": "Select",
"label": "Status",
"options": "Pending\nDeclined\nApproved\nDistributed"
},
{
"description": "Required to 'Create Expense'. The fund associated with the selected expense will be reduced by the alms 'Amount'.",
"fieldname": "expense_type",
"fieldtype": "Link",
"label": "Expense Type",
"options": "Church Expense Type"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2025-11-11 00:01:41.374332",
"modified": "2025-11-12 22:57:54.155053",
"modified_by": "Administrator",
"module": "Church Finances",
"name": "Church Alms Request",

View File

@ -1,9 +1,28 @@
# Copyright (c) 2025, meichthys and contributors
# For license information, please see license.txt
# import frappe
import frappe
from frappe.model.document import Document
class ChurchAlmsRequest(Document):
pass
@frappe.whitelist()
def create_expense(alms_request_name):
"""Create a Church Expense from the given Alms Request."""
alms = frappe.get_doc("Church Alms Request", alms_request_name)
# Make sure an expense type and amount are provided
if not alms.amount:
frappe.throw("⚠️ An amount is required for an expense to be created.")
if not alms.expense_type:
frappe.throw("⚠️ An expense type is required for an expense to be created.")
expense = frappe.new_doc("Church Expense")
expense.amount = alms.amount
expense.notes = f"Church Alms Request: {alms.name}"
expense.type = frappe.db.get_value("Church Expense Type", {"name": "Alms"}, "name")
expense.date = frappe.utils.now()
expense.insert(ignore_permissions=True)
frappe.msgprint(f"{expense.type} expense created.")
expense.submit()

File diff suppressed because one or more lines are too long