Skip to content

Commit

Permalink
balance log
Browse files Browse the repository at this point in the history
  • Loading branch information
parthagrawal9 committed Dec 5, 2019
1 parent 724f22e commit bb47cb0
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 4 deletions.
31 changes: 31 additions & 0 deletions membershipmanagement/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import frappe
from frappe import _
from frappe.model.document import Document

def send_welcome_email(doc,method):
msg = " ".join([
'Welcome to Membership Management System <b>',doc.full_name,
'<br>Plan:</b> ', doc.plan,
'<br><b>Start Date:</b> ',doc.joining_date,
'<br><b>End Date:</b> ',doc.end_date,
'<br><b>Balance:</b> ',str(doc.balance)
])
frappe.sendmail(
recipients=[doc.member],
sender=frappe.session.user,
subject="New Membership",
message=msg,
now=True
)
frappe.msgprint(_("Welcome Email Sent!"))

def add_balance_log(doc,method):
# doc = frappe.get_doc('Member', doc.member)
doc.append('balance_log', {
'date': doc.joining_date,
'description': ' ' . join(['Membership - ',doc.plan, ' - ', doc.duration, ' month/s']),
'amount': doc.total,
'balance': (doc.balance - doc.total)
})
doc.save()

8 changes: 8 additions & 0 deletions membershipmanagement/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
# ---------------
# Hook on document methods and events


doc_events={
"Member":{
"after_insert": "membershipmanagement.api.send_welcome_email",
"after_insert": "membershipmanagement.api.add_balance_log"
}
}

# doc_events = {
# "*": {
# "on_update": "method",
Expand Down
Empty file.
52 changes: 52 additions & 0 deletions membershipmanagement/members/doctype/balance_log/balance_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"creation": "2019-12-05 14:46:36.632538",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"date",
"description",
"amount",
"balance"
],
"fields": [
{
"fieldname": "date",
"fieldtype": "Read Only",
"in_list_view": 1,
"label": "Date",
"reqd": 1
},
{
"fieldname": "description",
"fieldtype": "Read Only",
"in_list_view": 1,
"label": "Description",
"reqd": 1
},
{
"fieldname": "amount",
"fieldtype": "Read Only",
"in_list_view": 1,
"label": "Amount",
"reqd": 1
},
{
"fieldname": "balance",
"fieldtype": "Read Only",
"in_list_view": 1,
"label": "Balance",
"reqd": 1
}
],
"istable": 1,
"modified": "2019-12-05 15:02:08.757375",
"modified_by": "Administrator",
"module": "Members",
"name": "Balance Log",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
10 changes: 10 additions & 0 deletions membershipmanagement/members/doctype/balance_log/balance_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Parth - M20Zero and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class BalanceLog(Document):
pass
14 changes: 13 additions & 1 deletion membershipmanagement/members/doctype/member/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ frappe.ui.form.on("Member", {
var member = frappe.model.get_doc(cdt, cdn);
frappe.model.set_value(cdt, cdn, "end_date", frappe.datetime.add_months(member.joining_date, member.duration));
}
});
});

frappe.ui.form.on("Member", {
duration: function(frm, cdt, cdn){
var member = frappe.model.get_doc(cdt, cdn);
frappe.model.set_value(cdt, cdn, "balance_log.date", member.joining_date);
frappe.model.set_value(cdt, cdn, "balance_log.bal", (member.balance-member.total));
frappe.model.set_value(cdt, cdn, "balance_log.description", "welcome");
frappe.model.set_value(cdt, cdn, "balance_log.amount", meber.total);
}


});
21 changes: 18 additions & 3 deletions membershipmanagement/members/doctype/member/member.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"duration",
"plan_col_break_column",
"plan_price",
"total"
"total",
"balance_section",
"balance_log"
],
"fields": [
{
Expand Down Expand Up @@ -55,7 +57,7 @@
"fieldname": "balance",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Balance",
"label": "Initial Balance",
"reqd": 1
},
{
Expand Down Expand Up @@ -100,9 +102,22 @@
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"collapsible": 1,
"fieldname": "balance_section",
"fieldtype": "Section Break",
"label": "Balance "
},
{
"fieldname": "balance_log",
"fieldtype": "Table",
"label": "Balance Log",
"options": "Balance Log",
"read_only": 1
}
],
"modified": "2019-12-04 12:23:06.934641",
"modified": "2019-12-05 15:01:10.814675",
"modified_by": "Administrator",
"module": "Members",
"name": "Member",
Expand Down

0 comments on commit bb47cb0

Please sign in to comment.