Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple issues in Payment Request #42427

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
5fa408a
fix: multiple issues in Payment Request
Abdeali099 Jul 22, 2024
469b805
chore: minor changes
Abdeali099 Jul 22, 2024
3718762
fix: remove bug
Abdeali099 Jul 22, 2024
9ed1d81
fix: replace `round` with `flt`
Abdeali099 Jul 22, 2024
aeddb81
fix: update `set_advance_payment_status()` logic
Abdeali099 Jul 22, 2024
3c4b84d
fix: removed bug of `set_advance_payment_status`
Abdeali099 Jul 22, 2024
a26a75f
fix: changes as per review
Abdeali099 Jul 24, 2024
e5a981b
refactor: replace sql query of `matched_payment_requests` to query bu…
Abdeali099 Jul 25, 2024
558d007
fix: replace `locals` with `get_doc` in set_query
Abdeali099 Jul 25, 2024
3c5ef05
fix: changes during review
sagarvora Jul 26, 2024
bc6acd3
Merge branch 'develop' into handle-multiple-issues-of-payment-request
sagarvora Aug 12, 2024
83b10d4
fix: minor review changes
Abdeali099 Aug 12, 2024
05a78cd
Merge branch 'develop' into handle-multiple-issues-of-payment-request
Abdeali099 Aug 14, 2024
dc757e1
fix: remove unnecessary code for setting payment entry received amount
Abdeali099 Aug 14, 2024
3bfda79
fix: logic for ser payment_request if PE made from transaction
Abdeali099 Aug 14, 2024
208a7e3
fix: Use rounded total to make Payment Request from `Sales Invoice` o…
Abdeali099 Aug 20, 2024
c2973d2
refactor: enhance logic of `set_open_payment_requests_to_references`
Abdeali099 Aug 20, 2024
da36e31
fix: added one optional arg `created_from_payment_request`
Abdeali099 Aug 20, 2024
baa11d1
fix: handle multiple allocation of PR at PE's reference
Abdeali099 Aug 20, 2024
53f30ec
fix: logic for PR if outstanding docs fetch
Abdeali099 Aug 20, 2024
77ba62a
fix: formatted Link field for `Payment Request` for PE's references
Abdeali099 Aug 21, 2024
bb02ffb
fix: replace `get_all()` with `get_list()` for getting Payment Reques…
Abdeali099 Aug 21, 2024
f024d66
fix: replace `get_all()` with `get_list()` for getting Payment Reques…
Abdeali099 Aug 21, 2024
70ec3f6
chore: format `payment_entry.js` file
Abdeali099 Aug 21, 2024
cc5db67
style: Show preview popup of `Payment Request`
Abdeali099 Aug 21, 2024
3270991
fix: remove minor bug
Abdeali099 Aug 22, 2024
dfefdff
fix: add virtual field for Payment Term and Request `outstanding_amou…
Abdeali099 Aug 22, 2024
d4b3601
fix: get outstanding amount in PE's reference on realtime
Abdeali099 Aug 23, 2024
9e092bb
fix: move allocation of allocated_amount to server side (no change)
Abdeali099 Aug 24, 2024
c40419d
fix: some minor changes to allocation
Abdeali099 Aug 24, 2024
a7aaff1
fix: Split `Payment Request` if PE is created from PR and there are `…
Abdeali099 Aug 26, 2024
568adef
fix: minor logic changes
Abdeali099 Aug 26, 2024
fc340c4
fix: Allocation of allocated_amount if `paid_amount` is changes
Abdeali099 Aug 26, 2024
ac51bdf
fix: improve logic of allocation
Abdeali099 Aug 26, 2024
b860eea
fix: set matched payment request if unset
Abdeali099 Aug 27, 2024
39fa208
Merge branch 'develop' into handle-multiple-issues-of-payment-request
Abdeali099 Sep 11, 2024
451bdd5
fix: minor changes
Abdeali099 Sep 11, 2024
9e89da4
fix: Allocate single Payment Request if PE created from PR
Abdeali099 Sep 11, 2024
871806e
fix: improve code logic
Abdeali099 Sep 12, 2024
3ee0a0e
fix: Removed duplication code
Abdeali099 Sep 12, 2024
2182e0c
fix: proper message title
Abdeali099 Sep 12, 2024
c5b5057
refactor: Rename method of Allocation Amount to References
Abdeali099 Sep 13, 2024
22e41e4
refactor: Changing `grand_total` description based on `party_type`
Abdeali099 Sep 13, 2024
3a95e18
refactor: update Payment Request
Abdeali099 Sep 13, 2024
b4aee31
fix: Remove virtual property of payment_term_oustanding from references
Abdeali099 Sep 16, 2024
f0e5902
Merge branch 'develop' into handle-multiple-issues-of-payment-request
Abdeali099 Sep 16, 2024
7ceeb2c
fix: fetch party account currency for creating payment request
vorasmit Sep 16, 2024
ca0c153
fix: use transaction currency as base in payment request
vorasmit Sep 16, 2024
79840a1
fix: party amount for creating payment entry
vorasmit Sep 16, 2024
3cec6f0
fix: allow for proportional amount paid by bank
vorasmit Sep 16, 2024
4416fb7
fix: Changed field order in Payment Request
Abdeali099 Sep 16, 2024
aa93c8b
fix: Minor refactor in Payment Entry Reference table data
Abdeali099 Sep 16, 2024
e92f44c
test: Added test cases for allow Payment at `Partially Paid` status f…
Abdeali099 Sep 16, 2024
3cb9cbc
test: Update partial paid status test case
Abdeali099 Sep 16, 2024
f13cc62
test: Update test case for same currency PR
Abdeali099 Sep 18, 2024
f809548
refactor: Wider the `msgprint` dialog for after save PE
Abdeali099 Sep 20, 2024
133791d
test: Update PR test cases
Abdeali099 Sep 20, 2024
d048123
chore: Remove dirty lines
Abdeali099 Sep 20, 2024
c370e72
test: Checking `Advance Payment Status`
Abdeali099 Sep 20, 2024
9fa760f
fix: formatting update
Abdeali099 Sep 20, 2024
b839319
fix: Use `flt` where doing subtraction
Abdeali099 Sep 20, 2024
b7cb361
test: PR test case with Payment Term for same currency
Abdeali099 Sep 20, 2024
943e1b7
fix: remove redundant `flt`
Abdeali099 Sep 20, 2024
f1d8946
test: Add test cases for PR
Abdeali099 Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 86 additions & 120 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ frappe.ui.form.on("Payment Entry", {
};
});

frm.set_query("payment_request", "references", function (doc, cdt, cdn) {
const row = frappe.get_doc(cdt, cdn);
return {
query: "erpnext.accounts.doctype.payment_request.payment_request.get_open_payment_requests_query",
filters: {
reference_doctype: row.reference_doctype,
reference_name: row.reference_name,
},
};
});

frm.set_query("sales_taxes_and_charges_template", function () {
return {
filters: {
Expand All @@ -191,7 +202,15 @@ frappe.ui.form.on("Payment Entry", {
},
};
});

frm.add_fetch(
"payment_request",
"outstanding_amount",
"payment_request_outstanding",
"Payment Entry Reference"
);
},

refresh: function (frm) {
erpnext.hide_company(frm);
frm.events.hide_unhide_fields(frm);
Expand All @@ -216,6 +235,7 @@ frappe.ui.form.on("Payment Entry", {
);
}
erpnext.accounts.unreconcile_payment.add_unreconcile_btn(frm);
frappe.flags.allocate_payment_amount = true;
},

validate_company: (frm) => {
Expand Down Expand Up @@ -797,7 +817,7 @@ frappe.ui.form.on("Payment Entry", {
);

if (frm.doc.payment_type == "Pay")
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount, 1);
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount, true);
else frm.events.set_unallocated_amount(frm);

frm.set_paid_amount_based_on_received_amount = false;
Expand All @@ -818,7 +838,7 @@ frappe.ui.form.on("Payment Entry", {
}

if (frm.doc.payment_type == "Receive")
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount, 1);
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount, true);
else frm.events.set_unallocated_amount(frm);
},

Expand Down Expand Up @@ -989,6 +1009,7 @@ frappe.ui.form.on("Payment Entry", {
c.outstanding_amount = d.outstanding_amount;
c.bill_no = d.bill_no;
c.payment_term = d.payment_term;
c.payment_term_outstanding = d.payment_term_outstanding;
c.allocated_amount = d.allocated_amount;
c.account = d.account;

Expand Down Expand Up @@ -1038,7 +1059,8 @@ frappe.ui.form.on("Payment Entry", {

frm.events.allocate_party_amount_against_ref_docs(
frm,
frm.doc.payment_type == "Receive" ? frm.doc.paid_amount : frm.doc.received_amount
frm.doc.payment_type == "Receive" ? frm.doc.paid_amount : frm.doc.received_amount,
false
);
},
});
Expand All @@ -1052,93 +1074,13 @@ frappe.ui.form.on("Payment Entry", {
return ["Sales Invoice", "Purchase Invoice"];
},

allocate_party_amount_against_ref_docs: function (frm, paid_amount, paid_amount_change) {
var total_positive_outstanding_including_order = 0;
var total_negative_outstanding = 0;
var total_deductions = frappe.utils.sum(
$.map(frm.doc.deductions || [], function (d) {
return flt(d.amount);
})
);

paid_amount -= total_deductions;

$.each(frm.doc.references || [], function (i, row) {
if (flt(row.outstanding_amount) > 0)
total_positive_outstanding_including_order += flt(row.outstanding_amount);
else total_negative_outstanding += Math.abs(flt(row.outstanding_amount));
allocate_party_amount_against_ref_docs: async function (frm, paid_amount, paid_amount_change) {
await frm.call("allocate_amount_to_references", {
paid_amount: paid_amount,
paid_amount_change: paid_amount_change,
allocate_payment_amount: frappe.flags.allocate_payment_amount ?? false,
});

var allocated_negative_outstanding = 0;
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;
}

var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding;
} else if (["Customer", "Supplier"].includes(frm.doc.party_type)) {
total_negative_outstanding = flt(total_negative_outstanding, precision("outstanding_amount"));
if (paid_amount > total_negative_outstanding) {
if (total_negative_outstanding == 0) {
frappe.msgprint(
__("Cannot {0} {1} {2} without any negative outstanding invoice", [
frm.doc.payment_type,
frm.doc.party_type == "Customer" ? "to" : "from",
frm.doc.party_type,
])
);
return false;
} else {
frappe.msgprint(
__("Paid Amount cannot be greater than total negative outstanding amount {0}", [
total_negative_outstanding,
])
);
return false;
}
} else {
allocated_positive_outstanding = total_negative_outstanding - paid_amount;
allocated_negative_outstanding =
paid_amount +
(total_positive_outstanding_including_order < allocated_positive_outstanding
? total_positive_outstanding_including_order
: allocated_positive_outstanding);
}
}

$.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
row.allocated_amount = 0;
} else if (
frappe.flags.allocate_payment_amount != 0 &&
(!row.allocated_amount || paid_amount_change)
) {
if (row.outstanding_amount > 0 && allocated_positive_outstanding >= 0) {
row.allocated_amount =
row.outstanding_amount >= allocated_positive_outstanding
? allocated_positive_outstanding
: row.outstanding_amount;
allocated_positive_outstanding -= flt(row.allocated_amount);
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
row.allocated_amount =
Math.abs(row.outstanding_amount) >= allocated_negative_outstanding
? -1 * allocated_negative_outstanding
: row.outstanding_amount;
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
}
}
});

frm.refresh_fields();
frm.events.set_total_allocated_amount(frm);
},

Expand Down Expand Up @@ -1686,6 +1628,62 @@ frappe.ui.form.on("Payment Entry", {

return current_tax_amount;
},

cost_center: function (frm) {
if (frm.doc.posting_date && (frm.doc.paid_from || frm.doc.paid_to)) {
return frappe.call({
method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_party_and_account_balance",
args: {
company: frm.doc.company,
date: frm.doc.posting_date,
paid_from: frm.doc.paid_from,
paid_to: frm.doc.paid_to,
ptype: frm.doc.party_type,
pty: frm.doc.party,
cost_center: frm.doc.cost_center,
},
callback: function (r, rt) {
if (r.message) {
frappe.run_serially([
() => {
frm.set_value(
"paid_from_account_balance",
r.message.paid_from_account_balance
);
frm.set_value("paid_to_account_balance", r.message.paid_to_account_balance);
frm.set_value("party_balance", r.message.party_balance);
},
]);
}
},
});
}
},

after_save: function (frm) {
const { matched_payment_requests } = frappe.last_response;
if (!matched_payment_requests) return;

const COLUMN_LABEL = [
[__("Reference DocType"), __("Reference Name"), __("Allocated Amount"), __("Payment Request")],
];

frappe.msgprint({
title: __("Unset Matched Payment Request"),
message: COLUMN_LABEL.concat(matched_payment_requests),
as_table: true,
wide: true,
primary_action: {
label: __("Allocate Payment Request"),
action() {
frappe.hide_msgprint();
frm.call("set_matched_payment_requests", { matched_payment_requests }, () => {
frm.dirty();
});
},
},
});
},
});

frappe.ui.form.on("Payment Entry Reference", {
Expand Down Expand Up @@ -1778,35 +1776,3 @@ frappe.ui.form.on("Payment Entry Deduction", {
frm.events.set_unallocated_amount(frm);
},
});
frappe.ui.form.on("Payment Entry", {
cost_center: function (frm) {
if (frm.doc.posting_date && (frm.doc.paid_from || frm.doc.paid_to)) {
return frappe.call({
method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_party_and_account_balance",
args: {
company: frm.doc.company,
date: frm.doc.posting_date,
paid_from: frm.doc.paid_from,
paid_to: frm.doc.paid_to,
ptype: frm.doc.party_type,
pty: frm.doc.party,
cost_center: frm.doc.cost_center,
},
callback: function (r, rt) {
if (r.message) {
frappe.run_serially([
() => {
frm.set_value(
"paid_from_account_balance",
r.message.paid_from_account_balance
);
frm.set_value("paid_to_account_balance", r.message.paid_to_account_balance);
frm.set_value("party_balance", r.message.party_balance);
},
]);
}
},
});
}
},
});
Loading
Loading