diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 125f4fedb62..da803cf75e6 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -471,7 +471,8 @@ class calculate_taxes_and_totals(object): def calculate_write_off_amount(self): if flt(self.doc.change_amount) > 0: - self.doc.write_off_amount = self.doc.grand_total - self.doc.paid_amount + self.doc.change_amount + self.doc.write_off_amount = flt(self.doc.grand_total - self.doc.paid_amount + self.doc.change_amount, + self.doc.precision("write_off_amount")) self.doc.base_write_off_amount = flt(self.doc.write_off_amount * self.doc.conversion_rate, self.doc.precision("base_write_off_amount")) diff --git a/erpnext/public/js/payment/payments.js b/erpnext/public/js/payment/payments.js index 6133fcf2455..23db61fcb4c 100644 --- a/erpnext/public/js/payment/payments.js +++ b/erpnext/public/js/payment/payments.js @@ -112,15 +112,15 @@ erpnext.payments = erpnext.stock.StockController.extend({ $(this.$body).find('.form-control').click(function(){ me.idx = $(this).attr("idx"); me.set_outstanding_amount(); - me.update_paid_amount(); + me.update_paid_amount(true); }) $(this.$body).find('.write_off_amount').change(function(){ - me.write_off_amount(flt($(this).val())); + me.write_off_amount(flt($(this).val()), precision("write_off_amount")); }) $(this.$body).find('.change_amount').change(function(){ - me.change_amount(flt($(this).val())); + me.change_amount(flt($(this).val()), precision("change_amount")); }) }, @@ -139,7 +139,7 @@ erpnext.payments = erpnext.stock.StockController.extend({ me.payment_val += $(this).text(); me.selected_mode.val(format_number(me.payment_val, 2)) me.idx = me.selected_mode.attr("idx") - me.selected_mode.change() + me.update_paid_amount() }) $(this.$body).find('.delete-btn').click(function(){ @@ -192,14 +192,14 @@ erpnext.payments = erpnext.stock.StockController.extend({ this.show_amounts() }, - update_paid_amount: function() { + update_paid_amount: function(update_write_off) { var me = this; if(in_list(['change_amount', 'write_off_amount'], this.idx)){ value = me.selected_mode.val(); if(me.idx == 'change_amount'){ me.change_amount(value) } else{ - if(value == 0) { + if(value == 0 && update_write_off) { value = me.frm.doc.outstanding_amount; } me.write_off_amount(value) @@ -224,9 +224,9 @@ erpnext.payments = erpnext.stock.StockController.extend({ show_amounts: function(){ var me = this; - $(this.$body).find(".write_off_amount").val(flt(this.frm.doc.write_off_amount, precision("write_off_amount"))); + $(this.$body).find(".write_off_amount").val(format_number(this.frm.doc.write_off_amount, precision("write_off_amount"))); $(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency)); - $(this.$body).find('.change_amount').val(flt(this.frm.doc.change_amount, precision("change_amount"))) + $(this.$body).find('.change_amount').val(format_number(this.frm.doc.change_amount, precision("change_amount"))) $(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, this.frm.doc.currency)) this.update_invoice(); }