fixes as per the review

This commit is contained in:
Manas Solanki 2017-08-02 15:11:32 +05:30 committed by Nabin Hait
parent 49c52f7639
commit 152ba1eccb
13 changed files with 117 additions and 140 deletions

View File

@ -490,7 +490,6 @@ frappe.ui.form.on('Payment Entry', {
}
},
callback: function(r, rt) {
console.log(r, rt);
if(r.message) {
var total_positive_outstanding = 0;
var total_negative_outstanding = 0;

View File

@ -100,12 +100,9 @@ class PaymentEntry(AccountsController):
if not self.party:
frappe.throw(_("Party is mandatory"))
self.party_name = frappe.db.get_value(self.party_type, self.party,
self.party_type.lower() + "_name")
_party_name = "title" if self.party_type == "Student" else self.party_type.lower() + "_name"
self.party_name = frappe.db.get_value(self.party_type, self.party, _party_name)
if self.party:
if not self.party_balance:
self.party_balance = get_balance_on(party_type=self.party_type,
@ -509,11 +506,11 @@ def get_outstanding_reference_documents(args):
negative_outstanding_invoices = []
if (args.get("party_type") != "Student"):
negative_outstanding_invoices = get_negative_outstanding_invoices(args.get("party_type"),
negative_outstanding_invoices = get_negative_outstanding_invoices(args.get("party_type"),
args.get("party"), args.get("party_account"), total_field)
# Get positive outstanding sales /purchase invoices/ Fees
outstanding_invoices = get_outstanding_invoices(args.get("party_type"), args.get("party"),
outstanding_invoices = get_outstanding_invoices(args.get("party_type"), args.get("party"),
args.get("party_account"))
for d in outstanding_invoices:
@ -694,9 +691,11 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
party_type = "Supplier"
elif dt in ("Expense Claim"):
party_type = "Employee"
elif dt in ("Fees"):
party_type = "Student"
# party account
if dt == "Sales Invoice":
if dt in ("Sales Invoice", "Fees"):
party_account = doc.debit_to
elif dt == "Purchase Invoice":
party_account = doc.credit_to
@ -706,7 +705,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
party_account_currency = doc.get("party_account_currency") or get_account_currency(party_account)
# payment type
if (dt == "Sales Order" or (dt=="Sales Invoice" and doc.outstanding_amount > 0)) \
if (dt == "Sales Order" or (dt in ("Sales Invoice", "Fees") and doc.outstanding_amount > 0)) \
or (dt=="Purchase Invoice" and doc.outstanding_amount < 0):
payment_type = "Receive"
else:
@ -722,6 +721,9 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
elif dt in ("Expense Claim"):
grand_total = doc.total_sanctioned_amount
outstanding_amount = doc.total_sanctioned_amount - doc.total_amount_reimbursed
elif dt == "Fees":
grand_total = doc.grand_total
outstanding_amount = doc.outstanding_amount
else:
total_field = "base_grand_total" if party_account_currency == doc.company_currency else "grand_total"
grand_total = flt(doc.get(total_field))

View File

@ -153,9 +153,6 @@ def get_data():
{
"type": "doctype",
"name": "Fees"
},{
"type": "doctype",
"name": "Fee Schedule"
},
{
"type": "doctype",

View File

@ -358,6 +358,22 @@ def update_email_group(doctype, name):
@frappe.whitelist()
def get_current_enrollment(student, academic_year=None):
current_academic_year = academic_year or frappe.defaults.get_defaults().academic_year
return frappe.get_all("Program Enrollment", fields=["name", "student", "student_name", "student_category",
program_enrollment_list = frappe.db.sql('''
select
name as program_enrollment, student_name, program, student_batch_name as student_batch,
student_category, academic_term, academic_year
from
`tabProgram Enrollment`
where
student = %s and academic_year = %s
order by creation''', (student, current_academic_year), as_dict=1)
'''
program_enrollment_list = frappe.get_all("Program Enrollment", fields=["name", "student", "student_name", "student_category",
"program", "student_batch_name", "academic_year", "academic_term"], filters={"student":student,
"academic_year": current_academic_year})[0]
"academic_year": current_academic_year})
'''
if program_enrollment_list:
return program_enrollment_list[0]
else:
return None

View File

@ -515,7 +515,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Total Amount/Student",
"label": "Total Amount per Student",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -601,7 +601,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2017-07-28 11:14:28.695618",
"modified": "2017-08-02 19:12:15.908822",
"modified_by": "Administrator",
"module": "Schools",
"name": "Fee Schedule",

View File

@ -3,7 +3,6 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class FeeScheduleProgram(Document):

View File

@ -3,7 +3,6 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class FeeScheduleStudentGroup(Document):

View File

@ -427,7 +427,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Debit To",
"label": "Academic Receivable Account",
"length": 0,
"no_copy": 0,
"options": "Account",
@ -458,7 +458,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Credit To",
"label": "Income Account",
"length": 0,
"no_copy": 0,
"options": "Account",
@ -578,8 +578,8 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-07-27 12:52:12.439685",
"modified_by": "manas@erpnext.com",
"modified": "2017-08-02 16:31:35.861158",
"modified_by": "Administrator",
"module": "Schools",
"name": "Fee Structure",
"name_case": "",

View File

@ -1,13 +1,17 @@
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
cur_frm.add_fetch("student", "title", "student_name");
cur_frm.add_fetch("student", "student_email_id", "student_email");
cur_frm.add_fetch("company", "default_receivable_account", "debit_to");
cur_frm.add_fetch("company", "default_income_account", "against_income_account");
cur_frm.add_fetch("company", "cost_center", "cost_center");
frappe.ui.form.on("Fees", {
setup: function(frm) {
frm.add_fetch("student", "title", "student_name");
frm.add_fetch("student", "student_email_id", "student_email");
frm.add_fetch("company", "default_receivable_account", "debit_to");
frm.add_fetch("company", "default_income_account", "against_income_account");
frm.add_fetch("company", "cost_center", "cost_center");
},
onload: function(frm){
frm.set_query("academic_term",function(){
return{
@ -20,7 +24,7 @@ frappe.ui.form.on("Fees", {
frm.set_query("fee_structure",function(){
return{
"filters":{
"academic_term": (frm.doc.academic_term)
"academic_year": (frm.doc.academic_year)
}
};
});
@ -85,14 +89,9 @@ frappe.ui.form.on("Fees", {
},
callback: function(r) {
if(r){
console.log(r);
frm.set_value("student_name", r.message.student_name);
frm.set_value("program_enrollment", r.message.name);
frm.set_value("program", r.message.program);
frm.set_value("student_batch", r.message.student_batch_name);
frm.set_value("student_category", r.message.student_category);
frm.set_value("academic_term", r.message.academic_term);
frm.set_value("academic_year", r.message.academic_year);
$.each(r.message, function(i, d) {
frm.set_value(i,d)
});
}
}
});
@ -100,25 +99,29 @@ frappe.ui.form.on("Fees", {
},
make_payment_request: function(frm) {
frappe.call({
method:"erpnext.accounts.doctype.payment_request.payment_request.make_payment_request",
args: {
"dt": frm.doc.doctype,
"dn": frm.doc.name,
"recipient_id": frm.doc.contact_email
},
callback: function(r) {
if(!r.exc){
var doc = frappe.model.sync(r.message);
frappe.set_route("Form", doc[0].doctype, doc[0].name);
if (!frm.doc.contact_email) {
frappe.msgprint(__("Please set the Email ID for the Student to send the Payment Request"))
} else {
frappe.call({
method:"erpnext.accounts.doctype.payment_request.payment_request.make_payment_request",
args: {
"dt": frm.doc.doctype,
"dn": frm.doc.name,
"recipient_id": frm.doc.contact_email
},
callback: function(r) {
if(!r.exc){
var doc = frappe.model.sync(r.message);
frappe.set_route("Form", doc[0].doctype, doc[0].name);
}
}
}
});
});
}
},
make_payment_entry: function(frm) {
return frappe.call({
method: "erpnext.schools.doctype.fees.fees.get_payment_entry",
method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry",
args: {
"dt": frm.doc.doctype,
"dn": frm.doc.name

View File

@ -142,9 +142,10 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "0",
"fieldname": "include_payment",
"fieldtype": "Check",
"hidden": 0,
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
@ -479,7 +480,7 @@
"columns": 0,
"fieldname": "student_email",
"fieldtype": "Data",
"hidden": 0,
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
@ -661,7 +662,7 @@
"columns": 0,
"fieldname": "currency",
"fieldtype": "Link",
"hidden": 0,
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
@ -1123,7 +1124,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Debit To",
"label": "Academic Receivable Account",
"length": 0,
"no_copy": 0,
"options": "Account",
@ -1154,7 +1155,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Credit To",
"label": "Income Account",
"length": 0,
"no_copy": 0,
"options": "Account",
@ -1242,8 +1243,8 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-07-27 12:58:44.197451",
"modified_by": "manas@erpnext.com",
"modified": "2017-08-03 16:02:06.001422",
"modified_by": "Administrator",
"module": "Schools",
"name": "Fees",
"name_case": "",

View File

@ -25,9 +25,7 @@ class Fees(AccountsController):
def validate(self):
self.calculate_total()
'''
set missing field here and validate the accounts
'''
# set missing field here and validate the accounts
def calculate_total(self):
"""Calculates total amount."""
@ -41,7 +39,7 @@ class Fees(AccountsController):
self.make_gl_entries()
if self.send_payment_request:
if self.send_payment_request and self.student_email:
pr = make_payment_request(dt="Fees", dn=self.name, recipient_id=self.contact_email,
submit_doc=True, use_dummy_message=True)
frappe.msgprint(_("Payment request {0} created").format(getlink("Payment Request", pr.name)))
@ -51,22 +49,22 @@ class Fees(AccountsController):
if not self.grand_total:
return
student_gl_entries = self.get_gl_dict({
"account": self.debit_to,
"party_type": "Student",
"party": self.student,
"against": self.against_income_account,
"debit": self.grand_total,
"debit_in_account_currency": self.grand_total,
"against_voucher": self.name,
"against_voucher_type": self.doctype
})
"account": self.debit_to,
"party_type": "Student",
"party": self.student,
"against": self.against_income_account,
"debit": self.grand_total,
"debit_in_account_currency": self.grand_total,
"against_voucher": self.name,
"against_voucher_type": self.doctype
})
fee_gl_entry = self.get_gl_dict({
"account": self.against_income_account,
"against": self.student,
"credit": self.grand_total,
"credit_in_account_currency": self.grand_total,
"cost_center": self.cost_center
})
"account": self.against_income_account,
"against": self.student,
"credit": self.grand_total,
"credit_in_account_currency": self.grand_total,
"cost_center": self.cost_center
})
from erpnext.accounts.general_ledger import make_gl_entries
make_gl_entries([student_gl_entries, fee_gl_entry], cancel=(self.docstatus == 2),
update_outstanding="Yes", merge_entries=False)
@ -80,66 +78,6 @@ def get_fee_list(doctype, txt, filters, limit_start, limit_page_length=20, order
order by due_date asc limit {0} , {1}'''
.format(limit_start, limit_page_length), student, as_dict = True)
@frappe.whitelist()
def get_payment_entry(dt, dn, bank_account=None):
doc = frappe.get_doc(dt, dn)
party_type = "Student"
party_account = doc.debit_to
party_account_currency = doc.get("currency") or get_account_currency(party_account)
# payment type
if (doc.outstanding_amount > 0):
payment_type = "Receive"
# amounts
grand_total = outstanding_amount = 0
grand_total = doc.grand_total
outstanding_amount = doc.outstanding_amount
# bank or cash
bank = get_default_bank_cash_account(doc.company, "Bank")
paid_amount = received_amount = 0
if party_account_currency == bank.account_currency:
paid_amount = received_amount = abs(outstanding_amount)
elif payment_type == "Receive":
paid_amount = abs(outstanding_amount)
else:
received_amount = abs(outstanding_amount)
pe = frappe.new_doc("Payment Entry")
pe.payment_type = payment_type
pe.company = doc.company
pe.posting_date = nowdate()
pe.mode_of_payment = doc.get("mode_of_payment")
pe.party_type = party_type
pe.party = doc.student
pe.party_name = doc.student_name
pe.paid_from = party_account if payment_type=="Receive" else bank.account
pe.paid_to = party_account if payment_type=="Pay" else bank.account
pe.paid_from_account_currency = party_account_currency if payment_type=="Receive" else bank.account_currency
pe.paid_to_account_currency = party_account_currency if payment_type=="Pay" else bank.account_currency
pe.paid_amount = paid_amount
pe.received_amount = received_amount
pe.allocate_payment_amount = 1
pe.letter_head = doc.get("letter_head")
pe.append("references", {
"reference_doctype": dt,
"reference_name": dn,
"due_date": doc.get("due_date"),
"total_amount": grand_total,
"outstanding_amount": outstanding_amount,
"allocated_amount": outstanding_amount
})
pe.setup_party_account_field()
pe.set_missing_values()
return pe
def get_list_context(context=None):
return {
"show_sidebar": True,
@ -148,4 +86,4 @@ def get_list_context(context=None):
"title": _("Fees"),
"get_list": get_fee_list,
"row_template": "templates/includes/fee/fee_row.html"
}
}

View File

@ -2,11 +2,11 @@ frappe.listview_settings['Fees'] = {
add_fields: ["grand_total", "outstanding_amount", "due_date"],
get_indicator: function(doc) {
if(flt(doc.outstanding_amount)==0) {
return [__("Paid"), "green", "outstanding_amount,=,0"]
return [__("Paid"), "green", "outstanding_amount,=,0"];
} else if (flt(doc.outstanding_amount) > 0 && doc.due_date >= frappe.datetime.get_today()) {
return [__("Unpaid"), "orange", "outstanding_amount,>,0|due_date,>,Today"]
return [__("Unpaid"), "orange", "outstanding_amount,>,0|due_date,>,Today"];
} else if (flt(doc.outstanding_amount) > 0 && doc.due_date < frappe.datetime.get_today()) {
return [__("Overdue"), "red", "outstanding_amount,>,0|due_date,<=,Today"]
return [__("Overdue"), "red", "outstanding_amount,>,0|due_date,<=,Today"];
}
}
};

View File

@ -0,0 +1,23 @@
/* eslint-disable */
// rename this file from _test_[name] to test_[name] to activate
// and remove above this line
QUnit.test("test: Fees", function (assert) {
let done = assert.async();
// number of asserts
assert.expect(1);
frappe.run_serially('Fees', [
// insert a new Fees
() => frappe.tests.make([
// values to be set
{key: 'value'}
]),
() => {
assert.equal(cur_frm.doc.key, 'value');
},
() => done()
]);
});