From: Jay (Open ERP) Date: Fri, 18 Sep 2009 13:55:56 +0000 (+0530) Subject: [FIX] Price Accuracy : rounding made to be based on --price_accuracy option X-Git-Tag: 5.0.6-addons~7 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;ds=sidebyside;h=20bc712f9c8658940f24126801b563431ca6e210;p=odoo%2Fodoo.git [FIX] Price Accuracy : rounding made to be based on --price_accuracy option lp bug: https://launchpad.net/bugs/407332 fixed bzr revid: jvo@tinyerp.com-20090918135556-lmun5j8d27437xkc --- diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py index 7033abe..0ce4cbb 100644 --- a/bin/addons/base/res/res_currency.py +++ b/bin/addons/base/res/res_currency.py @@ -26,6 +26,7 @@ import ir from tools.misc import currency from tools.translate import _ +from tools import config import mx.DateTime from mx.DateTime import RelativeDateTime, now, DateTime, localtime @@ -67,7 +68,7 @@ class res_currency(osv.osv): if currency.rounding == 0: return 0.0 else: - return round(amount / currency.rounding) * currency.rounding + return round(amount / currency.rounding, int(config['price_accuracy'])) * currency.rounding def is_zero(self, cr, uid, currency, amount): return abs(self.round(cr, uid, currency, amount)) < currency.rounding diff --git a/bin/osv/fields.py b/bin/osv/fields.py index dbd37ec..cde2a0e 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -607,6 +607,12 @@ class function(_column): self._multi = multi if 'relation' in args: self._obj = args['relation'] + + if 'digits' in args: + self.digits = args['digits'] + else: + self.digits = (16,2) + self._fnct_inv_arg = fnct_inv_arg if not fnct_inv: self.readonly = 1 diff --git a/bin/osv/orm.py b/bin/osv/orm.py index f5be539..26afced 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -299,7 +299,10 @@ def get_pg_type(f): t = eval('fields.'+(f._type)) f_type = (type_dict[t], type_dict[t]) elif isinstance(f, fields.function) and f._type == 'float': - f_type = ('float8', 'DOUBLE PRECISION') + if f.digits: + f_type = ('numeric', 'NUMERIC(%d,%d)' % (f.digits[0], f.digits[1])) + else: + f_type = ('float8', 'DOUBLE PRECISION') elif isinstance(f, fields.function) and f._type == 'selection': f_type = ('text', 'text') elif isinstance(f, fields.function) and f._type == 'char': @@ -997,9 +1000,10 @@ class orm_template(object): attrs = {'views': views} if node.hasAttribute('widget') and node.getAttribute('widget')=='selection': # We can not use the 'string' domain has it is defined according to the record ! - dom = None + dom = [] if column._domain and not isinstance(column._domain, (str, unicode)): dom = column._domain + attrs['selection'] = self.pool.get(relation).name_search(cr, user, '', dom, context=context) if (node.hasAttribute('required') and not int(node.getAttribute('required'))) or not column.required: attrs['selection'].append((False,''))