From 95e79c9f6f03f9350c247b3098bffc11bdf06f7b Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Tue, 11 Nov 2014 19:32:52 +0100 Subject: [PATCH] [FIX] point_of_sale: use 'Product Price' decimal precision for product prices --- addons/point_of_sale/static/src/js/models.js | 14 ++++++++-- .../static/src/js/widget_base.js | 28 ++++++++----------- addons/point_of_sale/static/src/js/widgets.js | 1 - addons/point_of_sale/static/src/xml/pos.xml | 6 ++-- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 44ff38e3587..88d17b5d2bb 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -139,6 +139,15 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal ids: function(self){ return [self.user.company_id[0]] }, loaded: function(self,companies){ self.company = companies[0]; }, },{ + model: 'decimal.precision', + fields: ['name','digits'], + loaded: function(self,dps){ + self.dp = {}; + for (var i = 0; i < dps.length; i++) { + self.dp[dps[i].name] = dps[i].digits; + } + }, + },{ model: 'product.uom', fields: [], domain: null, @@ -795,12 +804,11 @@ 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, this.pos.currency.decimals); + this.price = round_di(parseFloat(price) || 0, this.pos.dp['Product Price']); this.trigger('change',this); }, get_unit_price: function(){ - var rounding = this.pos.currency.rounding; - return round_pr(this.price,rounding); + return this.price; }, get_display_price: function(){ var rounding = this.pos.currency.rounding; 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 e58e50160a7..934cc130a6c 100644 --- a/addons/point_of_sale/static/src/js/widget_base.js +++ b/addons/point_of_sale/static/src/js/widget_base.js @@ -18,28 +18,24 @@ function openerp_pos_basewidget(instance, module){ //module is instance.point_of options = options || {}; this.pos = options.pos || (parent ? parent.pos : undefined); this.pos_widget = options.pos_widget || (parent ? parent.pos_widget : undefined); - this.build_currency_template(); }, - build_currency_template: function(){ + format_currency: function(amount,precision){ + var currency = (this.pos && this.pos.currency) ? this.pos.currency : {symbol:'$', position: 'after', rounding: 0.01, decimals: 2}; + var decimals = currency.decimals; - if(this.pos && this.pos.currency){ - this.currency = this.pos.currency; - }else{ - this.currency = {symbol: '$', position: 'after', rounding: 0.01}; + if (precision && (typeof this.pos.dp[precision]) !== undefined) { + decimals = this.pos.dp[precision]; } - - this.format_currency = function(amount){ - if(typeof amount === 'number'){ - amount = round_di(amount,this.currency.decimals).toFixed(this.currency.decimals); - } - if(this.currency.position === 'after'){ - return amount + ' ' + (this.currency.symbol || ''); - }else{ - return (this.currency.symbol || '') + ' ' + amount; - } + if (typeof amount === 'number') { + amount = round_di(amount,decimals).toFixed(decimals); } + if (currency.position === 'after') { + return amount + ' ' + (currency.symbol || ''); + } else { + return (currency.symbol || '') + ' ' + amount; + } }, show: function(){ this.$el.removeClass('oe_hidden'); diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index 41900fffa66..8e02ddd22d6 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -972,7 +972,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa $('.oe_web_client').off(); $('.openerp_webclient_container').off(); - self.build_currency_template(); self.renderElement(); self.$('.neworder-button').click(function(){ diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index ef548830310..c9dd59305ba 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -746,12 +746,12 @@ - + - + @@ -777,7 +777,7 @@ at - + /