Set change amount automatically only if it is a cash transaction (#9065)
This commit is contained in:
parent
5d7e8d9e83
commit
ac3b2aa913
@ -299,6 +299,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
|||||||
this.calculate_write_off_amount()
|
this.calculate_write_off_amount()
|
||||||
}else {
|
}else {
|
||||||
this.frm.set_value("change_amount", 0.0)
|
this.frm.set_value("change_amount", 0.0)
|
||||||
|
this.frm.set_value("base_change_amount", 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frm.refresh_fields();
|
this.frm.refresh_fields();
|
||||||
|
@ -442,15 +442,15 @@ class calculate_taxes_and_totals(object):
|
|||||||
|
|
||||||
if self.doc.doctype == "Sales Invoice":
|
if self.doc.doctype == "Sales Invoice":
|
||||||
self.doc.round_floats_in(self.doc, ["paid_amount"])
|
self.doc.round_floats_in(self.doc, ["paid_amount"])
|
||||||
|
self.calculate_write_off_amount()
|
||||||
|
self.calculate_change_amount()
|
||||||
|
|
||||||
paid_amount = self.doc.paid_amount \
|
paid_amount = self.doc.paid_amount \
|
||||||
if self.doc.party_account_currency == self.doc.currency else self.doc.base_paid_amount
|
if self.doc.party_account_currency == self.doc.currency else self.doc.base_paid_amount
|
||||||
|
|
||||||
change_amount = self.doc.change_amount \
|
change_amount = self.doc.change_amount \
|
||||||
if self.doc.party_account_currency == self.doc.currency else self.doc.base_change_amount
|
if self.doc.party_account_currency == self.doc.currency else self.doc.base_change_amount
|
||||||
|
|
||||||
self.calculate_write_off_amount()
|
|
||||||
self.calculate_change_amount()
|
|
||||||
|
|
||||||
self.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) +
|
self.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) +
|
||||||
flt(change_amount), self.doc.precision("outstanding_amount"))
|
flt(change_amount), self.doc.precision("outstanding_amount"))
|
||||||
|
|
||||||
@ -475,7 +475,9 @@ class calculate_taxes_and_totals(object):
|
|||||||
def calculate_change_amount(self):
|
def calculate_change_amount(self):
|
||||||
self.doc.change_amount = 0.0
|
self.doc.change_amount = 0.0
|
||||||
self.doc.base_change_amount = 0.0
|
self.doc.base_change_amount = 0.0
|
||||||
if self.doc.paid_amount > self.doc.grand_total:
|
if self.doc.paid_amount > self.doc.grand_total and not self.doc.is_return \
|
||||||
|
and any([d.type == "Cash" for d in self.doc.payments]):
|
||||||
|
|
||||||
self.doc.change_amount = flt(self.doc.paid_amount - self.doc.grand_total +
|
self.doc.change_amount = flt(self.doc.paid_amount - self.doc.grand_total +
|
||||||
self.doc.write_off_amount, self.doc.precision("change_amount"))
|
self.doc.write_off_amount, self.doc.precision("change_amount"))
|
||||||
|
|
||||||
|
@ -604,11 +604,18 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
|
|
||||||
calculate_change_amount: function(){
|
calculate_change_amount: function(){
|
||||||
this.frm.doc.change_amount = 0.0;
|
this.frm.doc.change_amount = 0.0;
|
||||||
if(this.frm.doc.paid_amount > this.frm.doc.grand_total && !this.frm.doc.is_return){
|
this.frm.doc.base_change_amount = 0.0;
|
||||||
|
if(this.frm.doc.paid_amount > this.frm.doc.grand_total && !this.frm.doc.is_return) {
|
||||||
|
var payment_types = $.map(cur_frm.doc.payments, function(d) { return d.type });
|
||||||
|
if (in_list(payment_types, 'Cash')) {
|
||||||
this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - this.frm.doc.grand_total +
|
this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - this.frm.doc.grand_total +
|
||||||
this.frm.doc.write_off_amount, precision("change_amount"));
|
this.frm.doc.write_off_amount, precision("change_amount"));
|
||||||
this.frm.doc.base_change_amount = flt(this.frm.doc.base_paid_amount - this.frm.doc.base_grand_total +
|
|
||||||
this.frm.doc.base_write_off_amount, precision("base_change_amount"));
|
this.frm.doc.base_change_amount = flt(this.frm.doc.base_paid_amount -
|
||||||
|
this.frm.doc.base_grand_total + this.frm.doc.base_write_off_amount,
|
||||||
|
precision("base_change_amount"));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user