From 35d3a3480a78f5f13f886cda133e6e6a6ad3f0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Tue, 9 Apr 2013 16:35:36 +0200 Subject: [PATCH 1/3] [FIX] point_of_sale: use correct rounding algorithm lp bug: https://launchpad.net/bugs/1157761 fixed bzr revid: fva@openerp.com-20130409143536-hgs38n0sqx8td607 --- addons/point_of_sale/static/src/js/models.js | 24 ++++--------------- addons/point_of_sale/static/src/js/screens.js | 2 +- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 660434ba53e..c0963068799 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1,24 +1,8 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sale var QWeb = instance.web.qweb; - // rounds a value with a fixed number of decimals. - // round(3.141492,2) -> 3.14 - function round(value,decimals){ - var mult = Math.pow(10,decimals || 0); - return Math.round(value*mult)/mult; - } - window.round = round; - - // rounds a value with decimal form precision - // round(3.141592,0.025) ->3.125 - function round_pr(value,precision){ - if(!precision || precision < 0){ - throw new Error('round_pr(): needs a precision greater than zero, got '+precision+' instead'); - } - return Math.round(value / precision) * precision; - } - window.round_pr = round_pr; - + var round_di = instance.web.round_digits; + var round_pr = instance.web.round_precision // The PosModel contains the Point Of Sale's representation of the backend. // Since the PoS must work in standalone ( Without connection to the server ) @@ -391,7 +375,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal var quant = Math.max(parseFloat(quantity) || 0, 0); var unit = this.get_unit(); if(unit){ - this.quantity = Math.max(unit.rounding, Math.round(quant / unit.rounding) * unit.rounding); + this.quantity = Math.max(unit.rounding, round_pr(quant, unit.rounding)); this.quantityStr = this.quantity.toFixed(Math.max(0,Math.ceil(Math.log(1.0 / unit.rounding) / Math.log(10)))); }else{ this.quantity = quant; @@ -484,7 +468,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(parseFloat(price) || 0, 2); + this.price = round_di(parseFloat(price) || 0, 2); this.trigger('change'); }, get_unit_price: function(){ diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index eca4a3c5915..0bd399428ed 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -983,7 +983,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa } if(this.pos_widget.action_bar){ - this.pos_widget.action_bar.set_button_disabled('validation', remaining > 0); + this.pos_widget.action_bar.set_button_disabled('validation', remaining > 0.000001); } }, set_numpad_state: function(numpadState) { From c176e1e7ca800b5e5d50f665dafcbdbcc47d0064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Tue, 9 Apr 2013 16:42:08 +0200 Subject: [PATCH 2/3] [IMP] point_of_sale: renamed round_digits to round_decimals bzr revid: fva@openerp.com-20130409144208-2wq4cozxstbdgld5 --- addons/point_of_sale/static/src/js/models.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index c0963068799..98ba49c8856 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1,7 +1,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sale var QWeb = instance.web.qweb; - var round_di = instance.web.round_digits; + var round_di = instance.web.round_decimals; var round_pr = instance.web.round_precision // The PosModel contains the Point Of Sale's representation of the backend. From b2a872846ca966f8fa6477cfa9404e82178ad061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Tue, 9 Apr 2013 18:00:21 +0200 Subject: [PATCH 3/3] [FIX] point_of_sale: use the correct rounding method for computing taxes bzr revid: fva@openerp.com-20130409160021-707f3vrxcrqytsl6 --- addons/point_of_sale/point_of_sale.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index b5b0763714d..756da2bb47b 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -909,6 +909,7 @@ class pos_order(osv.osv): account_tax_obj = self.pool.get('account.tax') user_proxy = self.pool.get('res.users') property_obj = self.pool.get('ir.property') + cur_obj = self.pool.get('res.currency') period = account_period_obj.find(cr, uid, context=context)[0] @@ -1010,11 +1011,11 @@ class pos_order(osv.osv): computed_taxes = account_tax_obj.compute_all(cr, uid, taxes, line.price_unit * (100.0-line.discount) / 100.0, line.qty)['taxes'] for tax in computed_taxes: - tax_amount += round(tax['amount'], 2) + tax_amount += cur_obj.round(cr, uid, cur, tax['amount']) group_key = (tax['tax_code_id'], tax['base_code_id'], tax['account_collected_id'], tax['id']) group_tax.setdefault(group_key, 0) - group_tax[group_key] += round(tax['amount'], 2) + group_tax[group_key] += cur_obj.round(cr, uid, cur, tax['amount']) amount = line.price_subtotal