From 609e2b4ca36a80444b1efb74589acca8b76d295e Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 31 Aug 2016 02:04:37 +0530 Subject: [PATCH] [POS] Currency format issue --- erpnext/controllers/taxes_and_totals.py | 12 ++++++++---- erpnext/public/js/controllers/taxes_and_totals.js | 12 +++++++----- erpnext/public/js/payment/payment_details.html | 2 +- erpnext/public/js/payment/payments.js | 14 +++++++------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 30e21ceff1..d8b5e2ebd8 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -441,12 +441,15 @@ class calculate_taxes_and_totals(object): paid_amount = self.doc.paid_amount \ if self.doc.party_account_currency == self.doc.currency else self.doc.base_paid_amount + change_amount = self.doc.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) + - flt(self.doc.change_amount), self.doc.precision("outstanding_amount")) - + flt(change_amount), self.doc.precision("outstanding_amount")) + elif self.doc.doctype == "Purchase Invoice": self.doc.outstanding_amount = flt(total_amount_to_pay, self.doc.precision("outstanding_amount")) @@ -462,12 +465,13 @@ class calculate_taxes_and_totals(object): def calculate_change_amount(self): self.doc.change_amount = 0.0 + self.doc.base_change_amount = 0.0 if 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.base_change_amount = flt(self.doc.change_amount * self.doc.conversion_rate, - self.doc.precision("base_change_amount")) + self.doc.base_change_amount = flt(self.doc.base_paid_amount - self.doc.base_grand_total + + self.doc.base_write_off_amount, self.doc.precision("base_change_amount")) def calculate_write_off_amount(self): if flt(self.doc.change_amount) > 0: diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 28924128dd..06298ca477 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -572,7 +572,10 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ var paid_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ? this.frm.doc.paid_amount : this.frm.doc.base_paid_amount; - this.frm.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) + + var change_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ? + this.frm.doc.change_amount : this.frm.doc.base_change_amount; + + this.frm.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) + flt(this.frm.doc.change_amount * this.frm.doc.conversion_rate), precision("outstanding_amount")); } else if(this.frm.doc.doctype == "Purchase Invoice") { @@ -612,12 +615,11 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ calculate_change_amount: function(){ 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.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.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.change_amount * this.frm.doc.conversion_rate, - precision("base_change_amount")); }, calculate_write_off_amount: function(){ diff --git a/erpnext/public/js/payment/payment_details.html b/erpnext/public/js/payment/payment_details.html index 596f139ea0..3e6394483e 100644 --- a/erpnext/public/js/payment/payment_details.html +++ b/erpnext/public/js/payment/payment_details.html @@ -2,7 +2,7 @@
{{mode_of_payment}}
- + diff --git a/erpnext/public/js/payment/payments.js b/erpnext/public/js/payment/payments.js index 4fa0390a53..c5d0749460 100644 --- a/erpnext/public/js/payment/payments.js +++ b/erpnext/public/js/payment/payments.js @@ -85,7 +85,7 @@ erpnext.payments = erpnext.stock.StockController.extend({ if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){ //When user first time click on row this.payment_val = flt(this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, precision("outstanding_amount")) - this.selected_mode.val(format_number(this.payment_val, 2)); + this.selected_mode.val(format_currency(this.payment_val, this.frm.doc.currency)); this.update_payment_amount() }else if(flt(this.selected_mode.val()) > 0){ //If user click on existing row which has value @@ -137,14 +137,14 @@ erpnext.payments = erpnext.stock.StockController.extend({ var me = this; $(this.$body).find('.pos-keyboard-key').click(function(){ me.payment_val += $(this).text(); - me.selected_mode.val(format_number(me.payment_val, 2)) + me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)) me.idx = me.selected_mode.attr("idx") me.update_paid_amount() }) $(this.$body).find('.delete-btn').click(function(){ me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1); - me.selected_mode.val(format_number(me.payment_val, 2)); + me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)); me.idx = me.selected_mode.attr("idx") me.update_paid_amount(); }) @@ -155,7 +155,7 @@ erpnext.payments = erpnext.stock.StockController.extend({ var me = this; this.selected_mode.change(function(){ me.payment_val = flt($(this).val()) || 0.0; - me.selected_mode.val(format_number(me.payment_val, 2)) + me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)) me.idx = me.selected_mode.attr("idx") me.update_payment_amount() }) @@ -199,7 +199,7 @@ erpnext.payments = erpnext.stock.StockController.extend({ if(me.idx == 'change_amount'){ me.change_amount(value) } else{ - if(value == 0 && update_write_off) { + if(flt(value) == 0 && update_write_off) { value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx)); } 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(format_number(this.frm.doc.write_off_amount, precision("write_off_amount"))); + $(this.$body).find(".write_off_amount").val(format_currency(this.frm.doc.write_off_amount, this.frm.doc.currency)); $(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency)); - $(this.$body).find('.change_amount').val(format_number(this.frm.doc.change_amount, precision("change_amount"))) + $(this.$body).find('.change_amount').val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency)) $(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency)) this.update_invoice(); }