fix: resolved pos return setting to default mode of payment instead of user selection (backport #45377) (#45419)
fix: resolved pos return setting to default mode of payment instead of user selection (#45377)
* fix: resolved pos return setting to default mode of payment instead of user selection
* refactor: removed console log statement
* refactor: moved get_payment_data to sales_and_purchase_return.py
(cherry picked from commit 54d234e05d)
Co-authored-by: Diptanil Saha <diptanil@frappe.io>
This commit is contained in:
@@ -1150,3 +1150,9 @@ def get_available_serial_nos(serial_nos, warehouse):
|
||||
return frappe.get_all(
|
||||
"Serial No", filters={"warehouse": warehouse, "name": ("in", serial_nos)}, pluck="name"
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_data(invoice):
|
||||
payment = frappe.db.get_all("Sales Invoice Payment", {"parent": invoice}, ["mode_of_payment", "amount"])
|
||||
return payment
|
||||
|
||||
@@ -822,7 +822,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
}
|
||||
}
|
||||
|
||||
set_total_amount_to_default_mop() {
|
||||
async set_total_amount_to_default_mop() {
|
||||
let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
|
||||
let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
|
||||
|
||||
@@ -844,6 +844,45 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
During returns, if an user select mode of payment other than
|
||||
default mode of payment, it should retain the user selection
|
||||
instead resetting it to default mode of payment.
|
||||
*/
|
||||
|
||||
let payment_amount = 0;
|
||||
this.frm.doc.payments.forEach(payment => {
|
||||
payment_amount += payment.amount
|
||||
});
|
||||
|
||||
if (payment_amount == total_amount_to_pay) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
For partial return, if the payment was made using single mode of payment
|
||||
it should set the return to that mode of payment only.
|
||||
*/
|
||||
|
||||
let return_against_mop = await frappe.call({
|
||||
method: 'erpnext.controllers.sales_and_purchase_return.get_payment_data',
|
||||
args: {
|
||||
invoice: this.frm.doc.return_against
|
||||
}
|
||||
});
|
||||
|
||||
if (return_against_mop.message.length === 1) {
|
||||
this.frm.doc.payments.forEach(payment => {
|
||||
if (payment.mode_of_payment == return_against_mop.message[0].mode_of_payment) {
|
||||
payment.amount = total_amount_to_pay;
|
||||
} else {
|
||||
payment.amount = 0;
|
||||
}
|
||||
});
|
||||
this.frm.refresh_fields();
|
||||
return;
|
||||
}
|
||||
|
||||
this.frm.doc.payments.find(payment => {
|
||||
if (payment.default) {
|
||||
payment.amount = total_amount_to_pay;
|
||||
|
||||
Reference in New Issue
Block a user