[FIX] base: QWeb monetary field rounding
authorGoffin Simon <simon.goffin@outlook.com>
Thu, 13 Nov 2014 14:33:26 +0000 (15:33 +0100)
committerMartin Trigaux <mat@odoo.com>
Fri, 28 Nov 2014 14:00:59 +0000 (15:00 +0100)
QWeb monetary widget uses the precision of the currency to know the number of
digits to display on a price. The number of digits is based on log10(rounding).
For currency with rounding different than 10^x (e.g. in Switzerland 0.05
to allow 5 cents coins only), the number of displayed digits should be rounded
up. e.g. log10(0.05) is -1.3, rounded up to 2 digits.

Fixes #3233

openerp/addons/base/ir/ir_qweb.py

index 958cc32..4e8d60d 100644 (file)
@@ -818,7 +818,7 @@ class MonetaryConverter(osv.AbstractModel):
         # The log10 of the rounding should be the number of digits involved if
         # negative, if positive clamp to 0 digits and call it a day.
         # nb: int() ~ floor(), we want nearest rounding instead
-        precision = int(round(math.log10(display_currency.rounding)))
+        precision = int(math.floor(math.log10(display_currency.rounding)))
         fmt = "%.{0}f".format(-precision if precision < 0 else 0)
 
         from_amount = record[field_name]