diff --git a/bin/addons/base/base_data.xml b/bin/addons/base/base_data.xml
index 675e72252bb..cbf8bc125ef 100644
--- a/bin/addons/base/base_data.xml
+++ b/bin/addons/base/base_data.xml
@@ -1026,7 +1026,7 @@
EUR
EUR
- 2
+ 0.01
4
diff --git a/bin/addons/base/base_demo.xml b/bin/addons/base/base_demo.xml
index 38ebd2fdb38..ab7704a7282 100644
--- a/bin/addons/base/base_demo.xml
+++ b/bin/addons/base/base_demo.xml
@@ -13,7 +13,7 @@
USD
- 2
+ 0.01
4
diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py
index e70342596d1..d4a82c6b9a5 100644
--- a/bin/addons/base/res/res_currency.py
+++ b/bin/addons/base/res/res_currency.py
@@ -56,7 +56,7 @@ class res_currency(osv.osv):
'rate': fields.function(_current_rate, method=True, string='Current rate',digits=(12,6)),
'rate_ids': fields.one2many('res.currency.rate', 'currency_id', 'Rates'),
'accuracy': fields.integer('Computational Accuracy'),
- 'rounding': fields.float('Rounding factor'),
+ 'rounding': fields.float('Rounding factor', digits=(12,6)),
'active': fields.boolean('Active'),
}
_defaults = {
@@ -65,7 +65,7 @@ class res_currency(osv.osv):
_order = "code"
def round(self, cr, uid, currency, amount):
- return round(amount, currency.rouding)
+ return round(amount / currency.rounding) * currency.rounding
def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount):
if to_currency_id==from_currency_id:
@@ -74,7 +74,7 @@ class res_currency(osv.osv):
[to_currency] = self.read(cr, uid, [to_currency_id])
if from_currency['rate'] == 0 or to_currency['rate'] == 0:
raise osv.except_osv('Error', 'No rate found for the currency')
- return currency(from_amount * from_currency['rate']/to_currency['rate'], to_currency['accuracy'], to_currency['rounding'])
+ return self.round(cr, uid, to_currency, from_amount * from_currency['rate']/to_currency['rate'])
res_currency()
class res_currency_rate(osv.osv):
diff --git a/bin/tools/config.py b/bin/tools/config.py
index 591a2318330..45ab813f989 100644
--- a/bin/tools/config.py
+++ b/bin/tools/config.py
@@ -58,6 +58,7 @@ class configmanager(object):
'secure': False,
'smtp_server': 'localhost',
'stop_after_init': False, # this will stop the server after initialization
+ 'price_accuracy': 2,
}
parser = optparse.OptionParser(version=tinyerp_version_string)
@@ -79,6 +80,7 @@ class configmanager(object):
parser.add_option('--debug', dest='debug_mode', action='store_true', default=False, help='enable debug mode')
parser.add_option("-S", "--secure", dest="secure", action="store_true", help="launch server over https instead of http", default=False)
parser.add_option('--smtp', dest='smtp_server', default='', help='specify the SMTP server for sending mail')
+ parser.add_option('--price_accuracy', dest='price_accuracy', default='2', help='specify the price accuracy')
group = optparse.OptionGroup(parser, "Modules related options")
group.add_option("-g", "--upgrade", action="store_true", dest="upgrade", default=False, help="Upgrade/install/uninstall modules")
@@ -129,7 +131,7 @@ class configmanager(object):
self.options['pidfile'] = False
for arg in ('interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host',
- 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server'):
+ 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'price_accuracy'):
if getattr(opt, arg):
self.options[arg] = getattr(opt, arg)
diff --git a/bin/tools/misc.py b/bin/tools/misc.py
index 2e37836c029..0874dadfb0d 100644
--- a/bin/tools/misc.py
+++ b/bin/tools/misc.py
@@ -205,6 +205,7 @@ class UpdateableStr(local):
def __nonzero__(self):
return bool(self.string)
+# Don't use ! Use res.currency.round()
class currency(float):
def __init__(self, value, accuracy=2, rounding=None):
diff --git a/doc/migrate/4.0.0-x.x.x/pre.py b/doc/migrate/4.0.0-x.x.x/pre.py
new file mode 100644
index 00000000000..47992e2b2e6
--- /dev/null
+++ b/doc/migrate/4.0.0-x.x.x/pre.py
@@ -0,0 +1,91 @@
+##############################################################################
+#
+# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+__author__ = 'Gaetan de Menten, '
+__version__ = '0.1.0'
+
+import psycopg
+import optparse
+import ConfigParser
+
+# -----
+
+parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
+
+parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
+
+group = optparse.OptionGroup(parser, "Database related options")
+group.add_option("--db_host", dest="db_host", help="specify the database host")
+group.add_option("--db_port", dest="db_port", help="specify the database port")
+group.add_option("-d", "--database", dest="db_name", help="specify the database name")
+group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
+group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
+parser.add_option_group(group)
+
+options = optparse.Values()
+options.db_name = 'terp' # default value
+parser.parse_args(values=options)
+
+if hasattr(options, 'config'):
+ configparser = ConfigParser.ConfigParser()
+ configparser.read([options.config])
+ for name, value in configparser.items('options'):
+ if not (hasattr(options, name) and getattr(options, name)):
+ if value in ('true', 'True'):
+ value = True
+ if value in ('false', 'False'):
+ value = False
+ setattr(options, name, value)
+
+# -----
+
+host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
+port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
+name = "dbname=%s" % options.db_name
+user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
+password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
+
+db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
+cr = db.cursor()
+
+# ------------------------ #
+# change currency rounding #
+# ------------------------ #
+
+cr.execute("""SELECT c.relname,a.attname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,t.typname,CASE WHEN a.attlen=-1 THEN a.atttypmod-4 ELSE a.attlen END as size FROM pg_class c,pg_attribute a,pg_type t WHERE c.relname='res_currency' AND a.attname='rounding' AND c.oid=a.attrelid AND a.atttypid=t.oid""")
+res = cr.dictfetchall()
+if res[0]['typname'] != 'float':
+ for line in (
+ "ALTER TABLE res_currency RENAME rounding TO rounding_bak",
+ "ALTER TABLE res_currency ADD rounding NUMERIC(12,6)",
+ "UPDATE res_currency SET rounding = power(10, - rounding_bak)",
+ "ALTER TABLE res_currency DROP rounding_bak",
+ ):
+ cr.execute(line)
+cr.commit()
+
+cr.close
diff --git a/man/terp_serverrc.5 b/man/terp_serverrc.5
index c6b62a7f7b8..770ba38df1a 100644
--- a/man/terp_serverrc.5
+++ b/man/terp_serverrc.5
@@ -88,6 +88,10 @@ Specify the database host.
Specify the database port.
.br
(default None)
+.TP
+.IR price_accuracy
+Specify the price accuracy.
+.br
.SH AUTHORS
diff --git a/man/tinyerp-server.1 b/man/tinyerp-server.1
index a6494899e4e..1bb935953f9 100644
--- a/man/tinyerp-server.1
+++ b/man/tinyerp-server.1
@@ -56,6 +56,10 @@ Initialize a module (use "all" for all modules).
.B \-u \fIMODULE\fB, \-\-update=\fIMODULE\fB
Update a module (use "all" for all modules).
+.TP
+.B \-\-price_accuracy=\fIPRICE_ACCURACY\fB
+Specify the price accuracy.
+
.TP
.B \-v, \-\-verbose
Enable verbose mode.