From 59f17d2cff8600aa53aacc257849ab001bd3f73f Mon Sep 17 00:00:00 2001 From: meichthys Date: Thu, 13 Nov 2025 04:25:10 +0000 Subject: [PATCH] Add button to Alms Request to create asociated Expense Fixes #83 --- .../church_alms_request.js | 23 +++++++++++++++---- .../church_alms_request.json | 10 +++++++- .../church_alms_request.py | 21 ++++++++++++++++- .../manual:_finances/manual:_finances.json | 4 ++-- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/church/church_finances/doctype/church_alms_request/church_alms_request.js b/church/church_finances/doctype/church_alms_request/church_alms_request.js index e6f29ff..b3f31f1 100644 --- a/church/church_finances/doctype/church_alms_request/church_alms_request.js +++ b/church/church_finances/doctype/church_alms_request/church_alms_request.js @@ -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(); + } + }); + }); + }, +}); + + + -// }, -// }); diff --git a/church/church_finances/doctype/church_alms_request/church_alms_request.json b/church/church_finances/doctype/church_alms_request/church_alms_request.json index 00358cf..e21e0a0 100644 --- a/church/church_finances/doctype/church_alms_request/church_alms_request.json +++ b/church/church_finances/doctype/church_alms_request/church_alms_request.json @@ -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", diff --git a/church/church_finances/doctype/church_alms_request/church_alms_request.py b/church/church_finances/doctype/church_alms_request/church_alms_request.py index f19c76c..5c03ca1 100644 --- a/church/church_finances/doctype/church_alms_request/church_alms_request.py +++ b/church/church_finances/doctype/church_alms_request/church_alms_request.py @@ -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() diff --git a/church/church_finances/workspace/manual:_finances/manual:_finances.json b/church/church_finances/workspace/manual:_finances/manual:_finances.json index 59a8c00..4a54d94 100644 --- a/church/church_finances/workspace/manual:_finances/manual:_finances.json +++ b/church/church_finances/workspace/manual:_finances/manual:_finances.json @@ -1,6 +1,6 @@ { "charts": [], - "content": "[{\"id\":\"nnvMTG5Sl5\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83e\ude99Finances Manual\",\"col\":12}},{\"id\":\"B-CtTCmVDX\",\"type\":\"paragraph\",\"data\":{\"text\":\"The finances module contains features related to the finances of the church.\",\"col\":12}},{\"id\":\"w8oEjl0tNc\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83d\udcb5Collections\",\"col\":12}},{\"id\":\"z52PVRpfzT\",\"type\":\"paragraph\",\"data\":{\"text\":\"A collection tracks donations from people for specific events.\",\"col\":12}},{\"id\":\"hh6-W_FmMh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Each time a collection is taken, a New Collection should be created. When creating a new collection note the following:
- Although not required, It is recommended to link the collection to the Church Event in which the collection is being taken.
    - By regularly linking events to collections, it will be possible later to run reports to see collection amounts for specific event types, etc.
- Remember: After saving a collection, it will be in a draft state. In order to finalize the collection, you will need to 'Submit' the collection. Once submitted, it cannot be modified unless you cancel and amend it.
    - See the 'Terminology' section in the Getting Started guide for more information about document states (draft / submitted / cancelled / amended / etc).
- After submitting the collection, you can click the Bank Reconciliation Report button on the top right of the form. This report can be used to compare with bank deposit reports.\",\"col\":12}},{\"id\":\"kVjzsXy2-5\",\"type\":\"paragraph\",\"data\":{\"text\":\"The Finances workspace, contains links to view the collection list and various collection reports.\",\"col\":12}},{\"id\":\"8K2QjgOLSb\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83e\udd32Donations\",\"col\":12}},{\"id\":\"bZ3I5EEmVO\",\"type\":\"paragraph\",\"data\":{\"text\":\"A donation tracks the amount given from a person toward a church fund. For tracking monies given to people in need, see Alms below.\",\"col\":12}},{\"id\":\"HSRUNh_Fan\",\"type\":\"paragraph\",\"data\":{\"text\":\"When adding donations to a collection, note the following:
- After entering each donation, the collection total and fund totals will be updated in real-time.
- If a single donation check specifies multiple funds, enter it as two separate donations (one for each fund).
- Additional payment types can be added if needed.
- When entering a donation from a specific person (i.e. Check donation or Cash Envelope), it is highly recommended to link the donation to the person.
   - By regularly linking donations to persons, end-of-year statements and individual person donation reports can be created.
\",\"col\":12}},{\"id\":\"Z1nAaK7FS7\",\"type\":\"paragraph\",\"data\":{\"text\":\"The Finances workspace, contains links to view donation reports. \",\"col\":12}},{\"id\":\"vVJ7g0tHHy\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83d\udccaFunds\",\"col\":12}},{\"id\":\"4znr2XFUMc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Funds are used by churches to tag monies for a specific purpose. Some default funds are included (i.e. General, Building, Missions, etc), but additional funds can be created for your own purposes.\",\"col\":12}},{\"id\":\"37szS6a0yE\",\"type\":\"paragraph\",\"data\":{\"text\":\"When adding/managing a fund, note the following:
- Any collections that contained donations the the fund will be listed in the 'Transactions' section at the bottom of the fund form.
- Manual transactions can created for the fund if needed
    - If the transaction is a transfer between funds, then
create a fund transfer instead. Fund transfers automatically add a transaction to the fund.
    - If the transaction is documenting an church expense,
add an expense instead. By choosing the expense type, an associated fund transaction will automatically be created. \",\"col\":12}},{\"id\":\"Tdfr6-sFUJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"The Finances workspace, contains links to view fund reports along with a graph showing the current totals in each fund.\",\"col\":12}},{\"id\":\"1IhzkEsC60\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83d\udcb8Expenses\",\"col\":12}},{\"id\":\"jgQMiK07Uh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expenses are any transaction that requires an outflow of funds. \",\"col\":12}},{\"id\":\"wjAR7Nu3_S\",\"type\":\"paragraph\",\"data\":{\"text\":\"When creating an expense, note the following:
- An expense type must be chosen. If needed, you can create a new expense type.
\",\"col\":12}},{\"id\":\"67mC7yvAUx\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expense Types\",\"col\":12}},{\"id\":\"fL3gBJn8g-\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expense types are used to categorize different expenses. This allows for more fine-grained financial reporting.\",\"col\":12}},{\"id\":\"WmN1sFvcpL\",\"type\":\"paragraph\",\"data\":{\"text\":\"When creating an expense type, note the following:
- Each expense type is linked to a specific fund, so that when expenses of this type are created, a transaction for the related fund will also automatically be created.
- Expense types can be grouped in hierarchies. For example, you could have an expense type group of 'Waste' and then have sub-types of 'Trash' and 'Recycling'.
    - In the example above, the 'Waste' expense type would have the 'group' option checked and the 'Trash' and 'Recycling' expense types would have 'Waste' selected as the 'Parent Expense Type'.
\",\"col\":12}},{\"id\":\"hh7kswiBbD\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83e\udef4Alms\",\"col\":12}},{\"id\":\"tlzyc7xao2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Alms are monies given by the church to someone in need. For giving to the church, see Donations above.\",\"col\":12}},{\"id\":\"wHgIFlrdYA\",\"type\":\"paragraph\",\"data\":{\"text\":\"When creating an alms request, note the following:
- The Recipient is the person (or family) who would receive the alms
- Once the alms request is Approved or Declined, the Status field should be updated.
- Once the alms have been distributed to the Recipient, then the Status can be set to Distributed.
\",\"col\":12}}]", + "content": "[{\"id\":\"nnvMTG5Sl5\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83e\ude99Finances Manual\",\"col\":12}},{\"id\":\"B-CtTCmVDX\",\"type\":\"paragraph\",\"data\":{\"text\":\"The finances module contains features related to the finances of the church.\",\"col\":12}},{\"id\":\"w8oEjl0tNc\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83d\udcb5Collections\",\"col\":12}},{\"id\":\"z52PVRpfzT\",\"type\":\"paragraph\",\"data\":{\"text\":\"A collection tracks donations from people for specific events.\",\"col\":12}},{\"id\":\"hh6-W_FmMh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Each time a collection is taken, a New Collection should be created. When creating a new collection note the following:
- Although not required, It is recommended to link the collection to the Church Event in which the collection is being taken.
    - By regularly linking events to collections, it will be possible later to run reports to see collection amounts for specific event types, etc.
- Remember: After saving a collection, it will be in a draft state. In order to finalize the collection, you will need to 'Submit' the collection. Once submitted, it cannot be modified unless you cancel and amend it.
    - See the 'Terminology' section in the Getting Started guide for more information about document states (draft / submitted / cancelled / amended / etc).
- After submitting the collection, you can click the Bank Reconciliation Report button on the top right of the form. This report can be used to compare with bank deposit reports.\",\"col\":12}},{\"id\":\"kVjzsXy2-5\",\"type\":\"paragraph\",\"data\":{\"text\":\"The Finances workspace, contains links to view the collection list and various collection reports.\",\"col\":12}},{\"id\":\"8K2QjgOLSb\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83e\udd32Donations\",\"col\":12}},{\"id\":\"bZ3I5EEmVO\",\"type\":\"paragraph\",\"data\":{\"text\":\"A donation tracks the amount given from a person toward a church fund. For tracking monies given to people in need, see Alms below.\",\"col\":12}},{\"id\":\"HSRUNh_Fan\",\"type\":\"paragraph\",\"data\":{\"text\":\"When adding donations to a collection, note the following:
- After entering each donation, the collection total and fund totals will be updated in real-time.
- If a single donation check specifies multiple funds, enter it as two separate donations (one for each fund).
- Additional payment types can be added if needed.
- When entering a donation from a specific person (i.e. Check donation or Cash Envelope), it is highly recommended to link the donation to the person.
   - By regularly linking donations to persons, end-of-year statements and individual person donation reports can be created.
\",\"col\":12}},{\"id\":\"Z1nAaK7FS7\",\"type\":\"paragraph\",\"data\":{\"text\":\"The Finances workspace, contains links to view donation reports. \",\"col\":12}},{\"id\":\"vVJ7g0tHHy\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83d\udccaFunds\",\"col\":12}},{\"id\":\"4znr2XFUMc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Funds are used by churches to tag monies for a specific purpose. Some default funds are included (i.e. General, Building, Missions, etc), but additional funds can be created for your own purposes.\",\"col\":12}},{\"id\":\"37szS6a0yE\",\"type\":\"paragraph\",\"data\":{\"text\":\"When adding/managing a fund, note the following:
- Any collections that contained donations the the fund will be listed in the 'Transactions' section at the bottom of the fund form.
- Manual transactions can created for the fund if needed
    - If the transaction is a transfer between funds, then
create a fund transfer instead. Fund transfers automatically add a transaction to the fund.
    - If the transaction is documenting an church expense,
add an expense instead. By choosing the expense type, an associated fund transaction will automatically be created. \",\"col\":12}},{\"id\":\"Tdfr6-sFUJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"The Finances workspace, contains links to view fund reports along with a graph showing the current totals in each fund.\",\"col\":12}},{\"id\":\"1IhzkEsC60\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83d\udcb8Expenses\",\"col\":12}},{\"id\":\"jgQMiK07Uh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expenses are any transaction that requires an outflow of funds. \",\"col\":12}},{\"id\":\"wjAR7Nu3_S\",\"type\":\"paragraph\",\"data\":{\"text\":\"When creating an expense, note the following:
- An expense type must be chosen. If needed, you can create a new expense type.
\",\"col\":12}},{\"id\":\"67mC7yvAUx\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expense Types\",\"col\":12}},{\"id\":\"fL3gBJn8g-\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expense types are used to categorize different expenses. This allows for more fine-grained financial reporting.\",\"col\":12}},{\"id\":\"WmN1sFvcpL\",\"type\":\"paragraph\",\"data\":{\"text\":\"When creating an expense type, note the following:
- Each expense type is linked to a specific fund, so that when expenses of this type are created, a transaction for the related fund will also automatically be created.
- Expense types can be grouped in hierarchies. For example, you could have an expense type group of 'Waste' and then have sub-types of 'Trash' and 'Recycling'.
    - In the example above, the 'Waste' expense type would have the 'group' option checked and the 'Trash' and 'Recycling' expense types would have 'Waste' selected as the 'Parent Expense Type'.
\",\"col\":12}},{\"id\":\"hh7kswiBbD\",\"type\":\"paragraph\",\"data\":{\"text\":\"\ud83e\udef4Alms\",\"col\":12}},{\"id\":\"tlzyc7xao2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Alms are monies given by the church to someone in need. For giving to the church, see Donations above.\",\"col\":12}},{\"id\":\"wHgIFlrdYA\",\"type\":\"paragraph\",\"data\":{\"text\":\"When creating an alms request, note the following:
- The Recipient is the person (or family) who would receive the alms
- Once the alms request is Approved or Declined, the Status field should be updated.
- Once the alms have been distributed to the Recipient:
    - The Status can be set to Distributed.
    - An associated Expense can be created by clicking the Create Expense button at the top-right of the form. This will create and submit an
Expense and automatically reduce the Fund associated with that Expense.\",\"col\":12}}]", "creation": "2025-10-26 22:28:38.959939", "custom_blocks": [], "docstatus": 0, @@ -13,7 +13,7 @@ "is_hidden": 0, "label": "Manual: Finances", "links": [], - "modified": "2025-11-10 23:50:22.840399", + "modified": "2025-11-12 23:24:05.428984", "modified_by": "Administrator", "module": "Church Finances", "name": "Manual: Finances",