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 openerp import SUPERUSER_ID
23 from openerp import pooler, tools
24 from openerp.osv import osv, fields
26 class decimal_precision(osv.osv):
27 _name = 'decimal.precision'
29 'name': fields.char('Usage', size=50, select=True, required=True),
30 'digits': fields.integer('Digits', required=True),
37 ('name_uniq', 'unique (name)', """Only one value can be defined for each given usage!"""),
40 @tools.ormcache(skiparg=3)
41 def precision_get(self, cr, uid, application):
42 cr.execute('select digits from decimal_precision where name=%s', (application,))
44 return res[0] if res else 2
46 def create(self, cr, uid, data, context=None):
47 res = super(decimal_precision, self).create(cr, uid, data, context=context)
48 self.precision_get.clear_cache(self)
51 def unlink(self, cr, uid, ids, context=None):
52 res = super(decimal_precision, self).unlink(cr, uid, ids, context=context)
53 self.precision_get.clear_cache(self)
56 def write(self, cr, uid, ids, data, *args, **argv):
57 res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv)
58 self.precision_get.clear_cache(self)
59 for obj in self.pool.obj_list():
60 for colname, col in self.pool.get(obj)._columns.items():
61 if isinstance(col, (fields.float, fields.function)):
67 def get_precision(application):
69 res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, SUPERUSER_ID, application)
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: