diff --git a/addons/product/_common.py b/addons/product/_common.py
index c05dcee66a2..f44f6b11a4c 100644
--- a/addons/product/_common.py
+++ b/addons/product/_common.py
@@ -20,9 +20,6 @@
##############################################################################
from openerp import tools
-import math
-
-
def rounding(f, r):
# TODO for trunk: log deprecation warning
# _logger.warning("Deprecated rounding method, please use tools.float_round to round floats.")
@@ -32,4 +29,4 @@ def rounding(f, r):
def ceiling(f, r):
if not r:
return f
- return math.ceil(f / r) * r
+ return tools.float_round(f, precision_rounding=r, rounding_method='UP')
diff --git a/addons/product/product.py b/addons/product/product.py
index dd117e41d63..38bb85e4f1c 100644
--- a/addons/product/product.py
+++ b/addons/product/product.py
@@ -132,10 +132,10 @@ class product_uom(osv.osv):
'name': fields.char('Unit of Measure', required=True, translate=True),
'category_id': fields.many2one('product.uom.categ', 'Category', required=True, ondelete='cascade',
help="Conversion between Units of Measure can only occur if they belong to the same category. The conversion will be made based on the ratios."),
- 'factor': fields.float('Ratio', required=True,digits=(12, 12),
+ 'factor': fields.float('Ratio', required=True, digits=0, # force NUMERIC with unlimited precision
help='How much bigger or smaller this unit is compared to the reference Unit of Measure for this category:\n'\
'1 * (reference unit) = ratio * (this unit)'),
- 'factor_inv': fields.function(_factor_inv, digits=(12,12),
+ 'factor_inv': fields.function(_factor_inv, digits=0, # force NUMERIC with unlimited precision
fnct_inv=_factor_inv_write,
string='Bigger Ratio',
help='How many times this Unit of Measure is bigger than the reference Unit of Measure in this category:\n'\
diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml
index 7260d4a4b5b..666622f092d 100644
--- a/addons/product/product_view.xml
+++ b/addons/product/product_view.xml
@@ -514,8 +514,14 @@
e.g: 1 * (reference unit) = ratio * (this unit)
diff --git a/openerp/addons/base/test/base_test.yml b/openerp/addons/base/test/base_test.yml index e73d8177fc0..3a4ccf1c0bd 100644 --- a/openerp/addons/base/test/base_test.yml +++ b/openerp/addons/base/test/base_test.yml @@ -199,8 +199,7 @@ !python {model: res.currency}: | from openerp.tools import float_compare, float_is_zero, float_round, float_repr def try_round(amount, expected, precision_digits=3, float_round=float_round, float_repr=float_repr): - result = float_repr(float_round(amount, precision_digits=precision_digits), - precision_digits=precision_digits) + result = float_repr(float_round(amount, precision_digits=precision_digits, rounding_method=rounding_method), assert result == expected, 'Rounding error: got %s, expected %s' % (result, expected) try_round(2.6745, '2.675') try_round(-2.6745, '-2.675') @@ -213,6 +212,18 @@ try_round(457.4554, '457.455') try_round(-457.4554, '-457.455') + # Try some rounding value with rounding method UP instead of HALF-UP + # We use 8.175 because when normalizing 8.175 with precision_digits=3 it gives + # us 8175,0000000001234 as value, and if not handle correctly the rounding UP + # value will be incorrect (should be 8,175 and not 8,176) + try_round(8.175, '8.175', rounding_method='UP') + try_round(8.1751, '8.176', rounding_method='UP') + try_round(-8.175, '-8.175', rounding_method='UP') + try_round(-8.1751, '-8.176', rounding_method='UP') + try_round(-6.000, '-6.000', rounding_method='UP') + try_round(1.8, '2', 0, rounding_method='UP') + try_round(-1.8, '-2', 0, rounding_method='UP') + # Extended float range test, inspired by Cloves Almeida's test on bug #882036. fractions = [.0, .015, .01499, .675, .67499, .4555, .4555, .45555] expecteds = ['.00', '.02', '.01', '.68', '.67', '.46', '.456', '.4556'] diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index bcec1ac98f0..62ef9eba902 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -597,7 +597,12 @@ def get_pg_type(f, type_override=None): if field_type in FIELDS_TO_PGTYPES: pg_type = (FIELDS_TO_PGTYPES[field_type], FIELDS_TO_PGTYPES[field_type]) elif issubclass(field_type, fields.float): - if f.digits: + # Explicit support for "falsy" digits (0, False) to indicate a + # NUMERIC field with no fixed precision. The values will be saved + # in the database with all significant digits. + # FLOAT8 type is still the default when there is no precision because + # it is faster for most operations (sums, etc.) + if f.digits is not None: pg_type = ('numeric', 'NUMERIC') else: pg_type = ('float8', 'DOUBLE PRECISION') diff --git a/openerp/report/render/rml2pdf/trml2pdf.py b/openerp/report/render/rml2pdf/trml2pdf.py index 61eedafb59e..dab7ee53fd2 100644 --- a/openerp/report/render/rml2pdf/trml2pdf.py +++ b/openerp/report/render/rml2pdf/trml2pdf.py @@ -91,7 +91,6 @@ class NumberedCanvas(canvas.Canvas): self._saved_page_states = [] def showPage(self): - self._saved_page_states.append(dict(self.__dict__)) self._startPage() def save(self): @@ -126,6 +125,8 @@ class PageCount(platypus.Flowable): class PageReset(platypus.Flowable): def draw(self): + """Flag to close current story page numbering and prepare for the next + should be executed after the rendering of the full story""" self.canv._doPageReset = True class _rml_styles(object,): @@ -936,6 +937,9 @@ class TinyDocTemplate(platypus.BaseDocTemplate): self.handle_frameBegin() def afterPage(self): + if isinstance(self.canv, NumberedCanvas): + # save current page states before eventual reset + self.canv._saved_page_states.append(dict(self.canv.__dict__)) if self.canv._doPageReset: # Following a