From fade5ab2c27d31143b40d856c40f0fee3bd994df Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Tue, 11 Nov 2014 17:41:20 +0100 Subject: [PATCH] [FIX] point_of_sale: decimal precision was hardcoded to 2 in various places --- addons/point_of_sale/static/src/js/models.js | 16 +++++++++++++--- addons/point_of_sale/static/src/js/screens.js | 2 +- .../point_of_sale/static/src/js/widget_base.js | 7 ++++--- addons/point_of_sale/static/src/xml/pos.xml | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index fadb4ba819c..44ff38e3587 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -235,6 +235,12 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal ids: function(self){ return [self.pricelist.currency_id[0]]; }, loaded: function(self, currencies){ self.currency = currencies[0]; + if (self.currency.rounding > 0) { + self.currency.decimals = Math.ceil(Math.log(1.0 / self.currency.rounding) / Math.log(10)); + } else { + self.currency.decimals = 0; + } + }, },{ model: 'product.packaging', @@ -789,7 +795,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }, // changes the base price of the product for this orderline set_unit_price: function(price){ - this.price = round_di(parseFloat(price) || 0, 2); + this.price = round_di(parseFloat(price) || 0, this.pos.currency.decimals); this.trigger('change',this); }, get_unit_price: function(){ @@ -874,16 +880,20 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal this.cashregister = options.cashregister; this.name = this.cashregister.journal_id[1]; this.selected = false; + this.pos = options.pos; }, //sets the amount of money on this payment line set_amount: function(value){ - this.amount = round_di(parseFloat(value) || 0, 2); + this.amount = round_di(parseFloat(value) || 0, this.pos.currency.decimals); this.trigger('change:amount',this); }, // returns the amount of money on this paymentline get_amount: function(){ return this.amount; }, + get_amount_str: function(){ + return this.amount.toFixed(this.pos.currency.decimals); + }, set_selected: function(selected){ if(this.selected !== selected){ this.selected = selected; @@ -1008,7 +1018,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }, addPaymentline: function(cashregister) { var paymentLines = this.get('paymentLines'); - var newPaymentline = new module.Paymentline({},{cashregister:cashregister}); + var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos}); if(cashregister.journal.type !== 'cash'){ newPaymentline.set_amount( Math.max(this.getDueLeft(),0) ); } diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index 3a09233d3b2..0d3933e0b34 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -1130,7 +1130,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa paymentlines.bind('change:selected', this.rerender_paymentline, this); paymentlines.bind('change:amount', function(line){ if(!line.selected && line.node){ - line.node.value = line.amount.toFixed(2); + line.node.value = line.amount.toFixed(this.pos.currency.decimals); } this.update_payment_summary(); },this); diff --git a/addons/point_of_sale/static/src/js/widget_base.js b/addons/point_of_sale/static/src/js/widget_base.js index 1b6daaa9a5a..e58e50160a7 100644 --- a/addons/point_of_sale/static/src/js/widget_base.js +++ b/addons/point_of_sale/static/src/js/widget_base.js @@ -1,5 +1,8 @@ function openerp_pos_basewidget(instance, module){ //module is instance.point_of_sale + var round_di = instance.web.round_decimals; + var round_pr = instance.web.round_precision + // This is a base class for all Widgets in the POS. It exposes relevant data to the // templates : // - widget.currency : { symbol: '$' | '€' | ..., position: 'before' | 'after } @@ -25,12 +28,10 @@ function openerp_pos_basewidget(instance, module){ //module is instance.point_of this.currency = {symbol: '$', position: 'after', rounding: 0.01}; } - var decimals = Math.max(0,Math.ceil(Math.log(1.0 / this.currency.rounding) / Math.log(10))); this.format_currency = function(amount){ if(typeof amount === 'number'){ - amount = Math.round(amount*100)/100; - amount = amount.toFixed(decimals); + amount = round_di(amount,this.currency.decimals).toFixed(this.currency.decimals); } if(this.currency.position === 'after'){ return amount + ' ' + (this.currency.symbol || ''); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 7832b2d0d0a..ef548830310 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -873,7 +873,7 @@
- + @@ -886,7 +886,7 @@ - +