-
Notifications
You must be signed in to change notification settings - Fork 3
feat:Implement PDC Maturity email notification #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZakkiyathLulu
wants to merge
3
commits into
develop
Choose a base branch
from
pdc_001
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
8 changes: 8 additions & 0 deletions
8
pdc_management/pdc_management/doctype/pdc_management_settings/pdc_management_settings.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2025, efeone and contributors | ||
// For license information, please see license.txt | ||
|
||
// frappe.ui.form.on("PDC Management Settings", { | ||
// refresh(frm) { | ||
|
||
// }, | ||
// }); |
56 changes: 56 additions & 0 deletions
56
pdc_management/pdc_management/doctype/pdc_management_settings/pdc_management_settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"creation": "2025-05-30 14:32:22.979470", | ||
"doctype": "DocType", | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"maturity_notification_before", | ||
"maturity_notification_template", | ||
"notification_role" | ||
], | ||
"fields": [ | ||
{ | ||
"description": "(In Days)", | ||
"fieldname": "maturity_notification_before", | ||
"fieldtype": "Int", | ||
"label": "Maturity Notification Before" | ||
}, | ||
{ | ||
"fieldname": "maturity_notification_template", | ||
"fieldtype": "Link", | ||
"label": "Maturity Notification Template", | ||
"options": "Email Template" | ||
}, | ||
{ | ||
"fieldname": "notification_role", | ||
"fieldtype": "Link", | ||
"label": "Notification Role", | ||
"options": "Role" | ||
} | ||
], | ||
"grid_page_length": 50, | ||
"index_web_pages_for_search": 1, | ||
"issingle": 1, | ||
"links": [], | ||
"modified": "2025-06-11 11:57:51.388741", | ||
"modified_by": "Administrator", | ||
"module": "PDC Management", | ||
"name": "PDC Management Settings", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"print": 1, | ||
"read": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
90 changes: 90 additions & 0 deletions
90
pdc_management/pdc_management/doctype/pdc_management_settings/pdc_management_settings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
import frappe | ||
from frappe.model.document import Document | ||
from frappe.utils import add_days, nowdate | ||
from frappe.utils.user import get_users_with_role | ||
|
||
|
||
class PDCManagementSettings(Document): | ||
pass | ||
|
||
|
||
@frappe.whitelist() | ||
def send_maturity_notifications(): | ||
settings = frappe.get_single("PDC Management Settings") | ||
email_template_name = settings.maturity_notification_template | ||
role_to_notify = settings.notification_role | ||
days_before = settings.maturity_notification_before or 0 | ||
|
||
if not email_template_name: | ||
return | ||
|
||
template_doc = frappe.get_doc("Email Template", email_template_name) | ||
subject = template_doc.subject or "PDC Maturity Reminder" | ||
template = template_doc.response or "" | ||
|
||
target_date = add_days(nowdate(), days_before) | ||
|
||
# Fetch PDCs due on the target date | ||
pdc_list = frappe.get_all( | ||
"Post Dated Cheque", | ||
filters={ | ||
"maturity_date": target_date, | ||
"docstatus": 1 | ||
}, | ||
fields=["name", "maturity_date", "party_type", "party"] | ||
) | ||
|
||
# Get internal user emails with the specified role | ||
internal_emails = [] | ||
if role_to_notify: | ||
for user in get_users_with_role(role_to_notify): | ||
email = frappe.db.get_value("User", user, "email") | ||
enabled = frappe.db.get_value("User", user, "enabled") | ||
if enabled and email: | ||
internal_emails.append(email) | ||
|
||
for pdc in pdc_list: | ||
party_email = get_party_email(pdc.party_type, pdc.party) | ||
|
||
recipients = list(set(internal_emails)) | ||
if party_email: | ||
recipients.append(party_email) | ||
|
||
if not recipients: | ||
continue | ||
|
||
message = frappe.render_template(template, { | ||
"doc": pdc, | ||
"party_name": pdc.party, | ||
"pdc_name": pdc.name, | ||
"maturity_date": pdc.maturity_date | ||
}) | ||
|
||
# Send email to all recipients | ||
frappe.sendmail( | ||
recipients=recipients, | ||
subject=subject, | ||
message=message, | ||
reference_doctype="Post Dated Cheque", | ||
reference_name=pdc.name | ||
) | ||
|
||
|
||
def get_party_email(party_type, party): | ||
if not party_type or not party: | ||
return None | ||
ZakkiyathLulu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = frappe.db.sql(""" | ||
SELECT ce.email_id | ||
FROM `tabDynamic Link` dl | ||
JOIN `tabContact Email` ce ON ce.parent = dl.parent | ||
WHERE dl.link_doctype = %s AND dl.link_name = %s | ||
ORDER BY ce.is_primary DESC | ||
LIMIT 1 | ||
Comment on lines
+79
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format this |
||
""", (party_type, party), as_dict=True) | ||
|
||
if result: | ||
return result[0]["email_id"] | ||
|
||
return frappe.db.get_value(party_type, party, "email_id") |
9 changes: 9 additions & 0 deletions
9
...management/pdc_management/doctype/pdc_management_settings/test_pdc_management_settings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2025, efeone and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
|
||
|
||
class TestPDCManagementSettings(FrappeTestCase): | ||
pass |
Empty file.
73 changes: 73 additions & 0 deletions
73
pdc_management/pdc_management/doctype/pdc_payment_reference/pdc_payment_reference.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"creation": "2025-05-30 10:47:28.110415", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"reference_type", | ||
"reference_name", | ||
"amount", | ||
"outstanding_amount", | ||
"allocated_amount", | ||
"pdc_clearance_date" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "amount", | ||
"fieldtype": "Currency", | ||
"in_list_view": 1, | ||
"label": "Amount", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "outstanding_amount", | ||
"fieldtype": "Currency", | ||
"in_list_view": 1, | ||
"label": "Outstanding Amount" | ||
}, | ||
{ | ||
"fieldname": "allocated_amount", | ||
"fieldtype": "Currency", | ||
"in_list_view": 1, | ||
"label": "Allocated Amount" | ||
}, | ||
{ | ||
"fieldname": "pdc_clearance_date", | ||
"fieldtype": "Date", | ||
"in_list_view": 1, | ||
"label": "PDC Clearance Date", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "reference_type", | ||
"fieldtype": "Link", | ||
"in_list_view": 1, | ||
"label": "Type", | ||
"options": "DocType", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "reference_name", | ||
"fieldtype": "Dynamic Link", | ||
"in_list_view": 1, | ||
"label": "Name", | ||
"options": "reference_type", | ||
"reqd": 1 | ||
} | ||
], | ||
"grid_page_length": 50, | ||
"index_web_pages_for_search": 1, | ||
"istable": 1, | ||
"links": [], | ||
"modified": "2025-06-11 13:24:39.141405", | ||
"modified_by": "Administrator", | ||
"module": "PDC Management", | ||
"name": "PDC Payment Reference", | ||
"owner": "Administrator", | ||
"permissions": [], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
9 changes: 9 additions & 0 deletions
9
pdc_management/pdc_management/doctype/pdc_payment_reference/pdc_payment_reference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2025, efeone and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
|
||
class PDCPaymentReference(Document): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.