mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-09 23:39:28 +00:00
Co-authored-by: Pandiyan P <pandiyanpalani37@gmail.com>
This commit is contained in:
@@ -46,23 +46,27 @@ frappe.ui.form.on("Payment Entry", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup: function (frm) {
|
setup: function (frm) {
|
||||||
frm.set_query("paid_from", function () {
|
frm.set_query("paid_from", function (doc) {
|
||||||
frm.events.validate_company(frm);
|
frm.events.validate_company(frm);
|
||||||
|
|
||||||
var account_types = ["Pay", "Internal Transfer"].includes(frm.doc.payment_type)
|
var account_types = ["Pay", "Internal Transfer"].includes(frm.doc.payment_type)
|
||||||
? ["Bank", "Cash"]
|
? ["Bank", "Cash"]
|
||||||
: [frappe.boot.party_account_types[frm.doc.party_type]];
|
: [frappe.boot.party_account_types[frm.doc.party_type]];
|
||||||
|
let filters = {
|
||||||
|
account_type: ["in", account_types],
|
||||||
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
};
|
||||||
|
|
||||||
if (frm.doc.party_type == "Shareholder") {
|
if (frm.doc.party_type == "Shareholder") {
|
||||||
account_types.push("Equity");
|
account_types.push("Equity");
|
||||||
}
|
}
|
||||||
|
if (doc.payment_type == "Internal Transfer" && doc.paid_to) {
|
||||||
|
filters.name = ["!=", doc.paid_to];
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters,
|
||||||
account_type: ["in", account_types],
|
|
||||||
is_group: 0,
|
|
||||||
company: frm.doc.company,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,21 +110,25 @@ frappe.ui.form.on("Payment Entry", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("paid_to", function () {
|
frm.set_query("paid_to", function (doc) {
|
||||||
frm.events.validate_company(frm);
|
frm.events.validate_company(frm);
|
||||||
|
|
||||||
var account_types = ["Receive", "Internal Transfer"].includes(frm.doc.payment_type)
|
var account_types = ["Receive", "Internal Transfer"].includes(frm.doc.payment_type)
|
||||||
? ["Bank", "Cash"]
|
? ["Bank", "Cash"]
|
||||||
: [frappe.boot.party_account_types[frm.doc.party_type]];
|
: [frappe.boot.party_account_types[frm.doc.party_type]];
|
||||||
|
let filters = {
|
||||||
|
account_type: ["in", account_types],
|
||||||
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
};
|
||||||
if (frm.doc.party_type == "Shareholder") {
|
if (frm.doc.party_type == "Shareholder") {
|
||||||
account_types.push("Equity");
|
account_types.push("Equity");
|
||||||
}
|
}
|
||||||
|
if (doc.payment_type == "Internal Transfer" && doc.paid_from) {
|
||||||
|
filters.name = ["!=", doc.paid_from];
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters,
|
||||||
account_type: ["in", account_types],
|
|
||||||
is_group: 0,
|
|
||||||
company: frm.doc.company,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ class PaymentEntry(AccountsController):
|
|||||||
self.set_liability_account()
|
self.set_liability_account()
|
||||||
self.set_missing_ref_details(force=True)
|
self.set_missing_ref_details(force=True)
|
||||||
self.validate_payment_type()
|
self.validate_payment_type()
|
||||||
|
self.validate_internal_transfer_accounts()
|
||||||
self.validate_party_details()
|
self.validate_party_details()
|
||||||
self.set_exchange_rate()
|
self.set_exchange_rate()
|
||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
@@ -623,6 +624,10 @@ class PaymentEntry(AccountsController):
|
|||||||
if self.payment_type not in ("Receive", "Pay", "Internal Transfer"):
|
if self.payment_type not in ("Receive", "Pay", "Internal Transfer"):
|
||||||
frappe.throw(_("Payment Type must be one of Receive, Pay and Internal Transfer"))
|
frappe.throw(_("Payment Type must be one of Receive, Pay and Internal Transfer"))
|
||||||
|
|
||||||
|
def validate_internal_transfer_accounts(self):
|
||||||
|
if self.payment_type == "Internal Transfer" and self.paid_from and self.paid_from == self.paid_to:
|
||||||
|
frappe.throw(_("Paid From and Paid To accounts must be different for an Internal Transfer."))
|
||||||
|
|
||||||
def validate_party_details(self):
|
def validate_party_details(self):
|
||||||
if self.party and not frappe.db.exists(self.party_type, self.party):
|
if self.party and not frappe.db.exists(self.party_type, self.party):
|
||||||
frappe.throw(_("{0} {1} does not exist").format(_(self.party_type), self.party))
|
frappe.throw(_("{0} {1} does not exist").format(_(self.party_type), self.party))
|
||||||
|
|||||||
@@ -726,6 +726,23 @@ class TestPaymentEntry(ERPNextTestSuite):
|
|||||||
|
|
||||||
self.validate_gl_entries(pe.name, expected_gle)
|
self.validate_gl_entries(pe.name, expected_gle)
|
||||||
|
|
||||||
|
def test_internal_transfer_rejects_same_account(self):
|
||||||
|
pe = frappe.new_doc("Payment Entry")
|
||||||
|
pe.payment_type = "Internal Transfer"
|
||||||
|
pe.company = "_Test Company"
|
||||||
|
pe.paid_from = "_Test Bank - _TC"
|
||||||
|
pe.paid_to = "_Test Bank - _TC"
|
||||||
|
pe.paid_amount = 100
|
||||||
|
pe.received_amount = 100
|
||||||
|
pe.reference_no = "same-account-transfer"
|
||||||
|
pe.reference_date = nowdate()
|
||||||
|
|
||||||
|
self.assertRaisesRegex(
|
||||||
|
frappe.ValidationError,
|
||||||
|
"Paid From and Paid To accounts must be different",
|
||||||
|
pe.insert,
|
||||||
|
)
|
||||||
|
|
||||||
def test_payment_against_negative_sales_invoice(self):
|
def test_payment_against_negative_sales_invoice(self):
|
||||||
si1 = create_sales_invoice()
|
si1 = create_sales_invoice()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user