1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools import cache
27 class decimal_precision(osv.osv):
28 _name = 'decimal.precision'
30 'name': fields.char('Usage', size=50, required=True),
31 'digits': fields.integer('Digits', required=True),
34 'digits': lambda *a : 2,
38 ('name_uniq', 'unique (name)', """The Usage of the decimal precision must be unique!"""),
42 def precision_get(self, cr, uid, application):
43 cr.execute('select digits from decimal_precision where name=%s', (application,))
45 return res and res[0] or 2
47 def write(self, cr, uid, ids, data, *args, **argv):
48 res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv)
49 self.precision_get.clear_cache(cr.dbname)
50 for obj in self.pool.obj_list():
51 for colname, col in self.pool.get(obj)._columns.items():
52 if isinstance(col, (fields.float, fields.function)):
59 def get_precision(application):
61 res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, 1, application)