set the reference document in the payment entry while creating from fees (#11861)
* set the reference document in the payment entry while creating from fees
* allocate the paid amount in the reference document
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index d8995a9..8ecedb5 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -512,7 +512,7 @@
c.outstanding_amount = d.outstanding_amount;
c.bill_no = d.bill_no;
- if(!in_list(["Sales Order", "Purchase Order", "Expense Claim"], d.voucher_type)) {
+ if(!in_list(["Sales Order", "Purchase Order", "Expense Claim", "Fees"], d.voucher_type)) {
if(flt(d.outstanding_amount) > 0)
total_positive_outstanding += flt(d.outstanding_amount);
else
@@ -527,7 +527,7 @@
} else {
c.exchange_rate = 1;
}
- if (in_list(['Sales Invoice', 'Purchase Invoice', "Expense Claim"], d.reference_doctype)){
+ if (in_list(['Sales Invoice', 'Purchase Invoice', "Expense Claim", "Fees"], d.reference_doctype)){
c.due_date = d.due_date;
}
});
@@ -535,7 +535,8 @@
if(
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") ||
- (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee")
+ (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") ||
+ (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student")
) {
if(total_positive_outstanding > total_negative_outstanding)
frm.set_value("paid_amount",
@@ -579,13 +580,16 @@
})
var allocated_negative_outstanding = 0;
- if ((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
+ if (
+ (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") ||
- (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee")) {
- if(total_positive_outstanding_including_order > paid_amount) {
- var remaining_outstanding = total_positive_outstanding_including_order - paid_amount;
- allocated_negative_outstanding = total_negative_outstanding < remaining_outstanding ?
- total_negative_outstanding : remaining_outstanding;
+ (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") ||
+ (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student")
+ ) {
+ if(total_positive_outstanding_including_order > paid_amount) {
+ var remaining_outstanding = total_positive_outstanding_including_order - paid_amount;
+ allocated_negative_outstanding = total_negative_outstanding < remaining_outstanding ?
+ total_negative_outstanding : remaining_outstanding;
}
var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding;
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 36ff0ac..99ff295 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -310,9 +310,10 @@
self.difference_amount = flt(self.difference_amount - total_deductions,
self.precision("difference_amount"))
+ # Paid amount is auto allocated in the reference document by default.
+ # Clear the reference document which doesn't have allocated amount on validate so that form can be loaded fast
def clear_unallocated_reference_document_rows(self):
self.set("references", self.get("references", {"allocated_amount": ["not in", [0, None, ""]]}))
-
frappe.db.sql("""delete from `tabPayment Entry Reference`
where parent = %s and allocated_amount = 0""", self.name)
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index ba5d8b3..abdadb3 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -576,14 +576,13 @@
outstanding_invoices = []
precision = frappe.get_precision("Sales Invoice", "outstanding_amount")
- if party_type == "Customer":
+ if party_type == "Customer" or party_type == "Student":
dr_or_cr = "debit_in_account_currency - credit_in_account_currency"
payment_dr_or_cr = "payment_gl_entry.credit_in_account_currency - payment_gl_entry.debit_in_account_currency"
else:
dr_or_cr = "credit_in_account_currency - debit_in_account_currency"
payment_dr_or_cr = "payment_gl_entry.debit_in_account_currency - payment_gl_entry.credit_in_account_currency"
- invoice = 'Sales Invoice' if party_type == 'Customer' else 'Purchase Invoice'
invoice_list = frappe.db.sql("""
select
voucher_no, voucher_type, posting_date, ifnull(sum({dr_or_cr}), 0) as invoice_amount, due_date,
@@ -613,7 +612,6 @@
having (invoice_amount - payment_amount) > 0.005
order by posting_date, name, due_date""".format(
dr_or_cr=dr_or_cr,
- invoice=invoice,
payment_dr_or_cr=payment_dr_or_cr,
condition=condition or ""
), {