fix: Mode of payment getting overwritten by defautl mode of payment for returns

This commit is contained in:
Deepesh Garg
2020-10-12 13:32:49 +05:30
parent 103866a367
commit 772ccde33f
2 changed files with 48 additions and 33 deletions

View File

@@ -629,22 +629,29 @@ class calculate_taxes_and_totals(object):
self.doc.other_charges_calculation = get_itemised_tax_breakup_html(self.doc) self.doc.other_charges_calculation = get_itemised_tax_breakup_html(self.doc)
def update_paid_amount_for_return(self, total_amount_to_pay): def update_paid_amount_for_return(self, total_amount_to_pay):
default_mode_of_payment = frappe.db.get_value('Sales Invoice Payment', existing_amount = 0
{'parent': self.doc.pos_profile, 'default': 1},
['mode_of_payment', 'type', 'account'], as_dict=1)
self.doc.payments = [] for payment in self.doc.payments:
existing_amount += payment.amount
if default_mode_of_payment: # do not override user entered amount if equal to total_amount_to_pay
self.doc.append('payments', { if existing_amount != total_amount_to_pay:
'mode_of_payment': default_mode_of_payment.mode_of_payment, default_mode_of_payment = frappe.db.get_value('Sales Invoice Payment',
'type': default_mode_of_payment.type, {'parent': self.doc.pos_profile, 'default': 1},
'account': default_mode_of_payment.account, ['mode_of_payment', 'type', 'account'], as_dict=1)
'amount': total_amount_to_pay
}) self.doc.payments = []
else:
self.doc.is_pos = 0 if default_mode_of_payment:
self.doc.pos_profile = '' self.doc.append('payments', {
'mode_of_payment': default_mode_of_payment.mode_of_payment,
'type': default_mode_of_payment.type,
'account': default_mode_of_payment.account,
'amount': total_amount_to_pay
})
else:
self.doc.is_pos = 0
self.doc.pos_profile = ''
self.calculate_paid_amount() self.calculate_paid_amount()

View File

@@ -672,25 +672,33 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
); );
} }
frappe.db.get_value('Sales Invoice Payment', {'parent': this.frm.doc.pos_profile, 'default': 1}, let existing_amount = 0
['mode_of_payment', 'account', 'type'], (value) => { $.each(this.frm.doc.payments || [], function(i, row) {
if (this.frm.is_dirty()) { existing_amount += row.amount;
frappe.model.clear_table(this.frm.doc, 'payments'); })
if (value) {
let row = frappe.model.add_child(this.frm.doc, 'Sales Invoice Payment', 'payments');
row.mode_of_payment = value.mode_of_payment;
row.type = value.type;
row.account = value.account;
row.default = 1;
row.amount = total_amount_to_pay;
} else {
this.frm.set_value('is_pos', 1);
}
this.frm.refresh_fields();
}
}, 'Sales Invoice');
this.calculate_paid_amount(); if (existing_amount != total_amount_to_pay) {
frappe.db.get_value('Sales Invoice Payment', {'parent': this.frm.doc.pos_profile, 'default': 1},
['mode_of_payment', 'account', 'type'], (value) => {
if (this.frm.is_dirty()) {
frappe.model.clear_table(this.frm.doc, 'payments');
if (value) {
let row = frappe.model.add_child(this.frm.doc, 'Sales Invoice Payment', 'payments');
row.mode_of_payment = value.mode_of_payment;
row.type = value.type;
row.account = value.account;
row.default = 1;
row.amount = total_amount_to_pay;
} else {
this.frm.set_value('is_pos', 1);
}
this.frm.refresh_fields();
this.calculate_paid_amount();
}
}, 'Sales Invoice');
} else {
this.calculate_paid_amount();
}
}, },
set_default_payment: function(total_amount_to_pay, update_paid_amount) { set_default_payment: function(total_amount_to_pay, update_paid_amount) {