Skip to content

Commit

Permalink
fix: changes during review
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarvora committed Jul 26, 2024
1 parent 558d007 commit 3c5ef05
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 10 additions & 2 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ frappe.ui.form.on("Payment Entry", {
}
}

let set_matched_payment_requests = false;

$.each(frm.doc.references || [], function (i, row) {
if (frappe.flags.allocate_payment_amount == 0) {
//If allocate payment amount checkbox is unchecked, set zero to allocate amount
Expand All @@ -1095,6 +1097,8 @@ frappe.ui.form.on("Payment Entry", {
frappe.flags.allocate_payment_amount != 0 &&
(!row.allocated_amount || paid_amount_change)
) {
let previous_allocated_amount = row.allocated_amount;

if (row.outstanding_amount > 0 && allocated_positive_outstanding >= 0) {
row.allocated_amount =
row.outstanding_amount >= allocated_positive_outstanding
Expand All @@ -1108,12 +1112,16 @@ frappe.ui.form.on("Payment Entry", {
: row.outstanding_amount;
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
}

if (!row.payment_request && row.allocated_amount > previous_allocated_amount) {
set_matched_payment_requests = true;
}
}
});

frm.refresh_fields();
if (frappe.flags.allocate_payment_amount) frm.call("set_matched_payment_requests");
frm.events.set_total_allocated_amount(frm);
if (set_matched_payment_requests) frm.call("set_matched_payment_requests");
},

set_total_allocated_amount: function (frm) {
Expand Down Expand Up @@ -1707,7 +1715,7 @@ frappe.ui.form.on("Payment Entry Reference", {

const row = frappe.get_doc(cdt, cdn);

if (row.payment_request || !row.reference_name || !row.reference_doctype || !row.allocated_amount)
if (row.payment_request || !(row.reference_doctype && row.reference_name && row.allocated_amount))
return;

frm.call("set_matched_payment_request", { row_idx: row.idx });
Expand Down
19 changes: 12 additions & 7 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,17 @@ def update_outstanding_amounts(self):
self.set_missing_ref_details(force=True)

def validate_duplicate_entry(self):
reference_names = []
reference_names = {}
for d in self.get("references"):
if (d.reference_doctype, d.reference_name, d.payment_term) in reference_names:
key = (d.reference_doctype, d.reference_name, d.payment_term, d.payment_request)
if key in reference_names:
frappe.throw(
_("Row #{0}: Duplicate entry in References {1} {2}").format(
d.idx, d.reference_doctype, d.reference_name
)
)
reference_names.append((d.reference_doctype, d.reference_name, d.payment_term))

reference_names.add(key)

def set_bank_account_data(self):
if self.bank_account:
Expand Down Expand Up @@ -1742,10 +1744,13 @@ def check_references_for_unset_payment_request(self):
if not self.references:
return

matched_payment_requests = get_matched_payment_requests_of_references(
matched_payment_requests = get_matched_payment_requests(
[row for row in self.references if not row.payment_request]
)

if not matched_payment_requests:
return

unset_pr_rows = {}

for row in self.references:
Expand Down Expand Up @@ -1776,7 +1781,7 @@ def set_matched_payment_requests(self):
if not self.references:
return

matched_payment_requests = get_matched_payment_requests_of_references(self.references)
matched_payment_requests = get_matched_payment_requests(self.references)

matched_count = 0

Expand Down Expand Up @@ -1820,7 +1825,7 @@ def set_matched_payment_request(self, row_idx):
):
return

matched_pr = get_matched_payment_requests_of_references([row])
matched_pr = get_matched_payment_requests([row])

if not matched_pr:
return
Expand All @@ -1833,7 +1838,7 @@ def set_matched_payment_request(self, row_idx):
)


def get_matched_payment_requests_of_references(references=None):
def get_matched_payment_requests(references=None):
if not references:
return

Expand Down

0 comments on commit 3c5ef05

Please sign in to comment.