[POS] Currency format issue

This commit is contained in:
Rohit Waghchaure 2016-08-31 02:04:37 +05:30
parent 4f71190a85
commit 609e2b4ca3
4 changed files with 23 additions and 17 deletions

View File

@ -441,12 +441,15 @@ class calculate_taxes_and_totals(object):
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 \
if self.doc.party_account_currency == self.doc.currency else self.doc.base_change_amount
self.calculate_write_off_amount() self.calculate_write_off_amount()
self.calculate_change_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(self.doc.change_amount), self.doc.precision("outstanding_amount")) flt(change_amount), self.doc.precision("outstanding_amount"))
elif self.doc.doctype == "Purchase Invoice": elif self.doc.doctype == "Purchase Invoice":
self.doc.outstanding_amount = flt(total_amount_to_pay, self.doc.precision("outstanding_amount")) 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): def calculate_change_amount(self):
self.doc.change_amount = 0.0 self.doc.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:
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"))
self.doc.base_change_amount = flt(self.doc.change_amount * self.doc.conversion_rate, self.doc.base_change_amount = flt(self.doc.base_paid_amount - self.doc.base_grand_total +
self.doc.precision("base_change_amount")) self.doc.base_write_off_amount, self.doc.precision("base_change_amount"))
def calculate_write_off_amount(self): def calculate_write_off_amount(self):
if flt(self.doc.change_amount) > 0: if flt(self.doc.change_amount) > 0:

View File

@ -572,7 +572,10 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
var paid_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ? 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.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")); flt(this.frm.doc.change_amount * this.frm.doc.conversion_rate), precision("outstanding_amount"));
} else if(this.frm.doc.doctype == "Purchase Invoice") { } else if(this.frm.doc.doctype == "Purchase Invoice") {
@ -612,12 +615,11 @@ 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){ 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.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(){ calculate_write_off_amount: function(){

View File

@ -2,7 +2,7 @@
<div class="col-xs-6" style="padding:20px">{{mode_of_payment}}</div> <div class="col-xs-6" style="padding:20px">{{mode_of_payment}}</div>
<div class="col-xs-6"> <div class="col-xs-6">
<div class="input-group"> <div class="input-group">
<input disabled class="form-control text-right amount" idx="{{idx}}" type="text" value="{{format_number(amount, 2)}}"> <input disabled class="form-control text-right amount" idx="{{idx}}" type="text" value="{%= format_currency(amount, currency) %}">
<span class="input-group-btn"> <span class="input-group-btn">
<button type="button" class="btn btn-default clr" idx="{{idx}}" style="border:1px solid #d1d8dd">C</button> <button type="button" class="btn btn-default clr" idx="{{idx}}" style="border:1px solid #d1d8dd">C</button>
</span> </span>

View File

@ -85,7 +85,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){ if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){
//When user first time click on row //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.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() this.update_payment_amount()
}else if(flt(this.selected_mode.val()) > 0){ }else if(flt(this.selected_mode.val()) > 0){
//If user click on existing row which has value //If user click on existing row which has value
@ -137,14 +137,14 @@ erpnext.payments = erpnext.stock.StockController.extend({
var me = this; var me = this;
$(this.$body).find('.pos-keyboard-key').click(function(){ $(this.$body).find('.pos-keyboard-key').click(function(){
me.payment_val += $(this).text(); 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.idx = me.selected_mode.attr("idx")
me.update_paid_amount() me.update_paid_amount()
}) })
$(this.$body).find('.delete-btn').click(function(){ $(this.$body).find('.delete-btn').click(function(){
me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1); 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.idx = me.selected_mode.attr("idx")
me.update_paid_amount(); me.update_paid_amount();
}) })
@ -155,7 +155,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
var me = this; var me = this;
this.selected_mode.change(function(){ this.selected_mode.change(function(){
me.payment_val = flt($(this).val()) || 0.0; 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.idx = me.selected_mode.attr("idx")
me.update_payment_amount() me.update_payment_amount()
}) })
@ -199,7 +199,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
if(me.idx == 'change_amount'){ if(me.idx == 'change_amount'){
me.change_amount(value) me.change_amount(value)
} else{ } 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)); value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx));
} }
me.write_off_amount(value) me.write_off_amount(value)
@ -224,9 +224,9 @@ erpnext.payments = erpnext.stock.StockController.extend({
show_amounts: function(){ show_amounts: function(){
var me = this; 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('.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.$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(); this.update_invoice();
} }