[FIX] decimal_precision: signal workers to restart their registry when decimal precision change.
bzr revid: chs@openerp.com-20140110125433-soimmrpz2icvob60
This commit is contained in:
parent
3ed5b49e7a
commit
7dd16a558e
|
@ -22,6 +22,7 @@
|
|||
from openerp import SUPERUSER_ID
|
||||
from openerp import pooler, tools
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.modules.registry import RegistryManager
|
||||
|
||||
class decimal_precision(osv.osv):
|
||||
_name = 'decimal.precision'
|
||||
|
@ -43,23 +44,28 @@ class decimal_precision(osv.osv):
|
|||
res = cr.fetchone()
|
||||
return res[0] if res else 2
|
||||
|
||||
def create(self, cr, uid, data, context=None):
|
||||
res = super(decimal_precision, self).create(cr, uid, data, context=context)
|
||||
self.precision_get.clear_cache(self)
|
||||
return res
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
res = super(decimal_precision, self).unlink(cr, uid, ids, context=context)
|
||||
self.precision_get.clear_cache(self)
|
||||
return res
|
||||
|
||||
def write(self, cr, uid, ids, data, *args, **argv):
|
||||
res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv)
|
||||
def clear_cache(self, cr):
|
||||
"""clear cache and update models. Notify other workers to restart their registry."""
|
||||
self.precision_get.clear_cache(self)
|
||||
for obj in self.pool.obj_list():
|
||||
for colname, col in self.pool.get(obj)._columns.items():
|
||||
if isinstance(col, (fields.float, fields.function)):
|
||||
col.digits_change(cr)
|
||||
RegistryManager.signal_registry_change(cr.dbname)
|
||||
|
||||
def create(self, cr, uid, data, context=None):
|
||||
res = super(decimal_precision, self).create(cr, uid, data, context=context)
|
||||
self.clear_cache(cr)
|
||||
return res
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
res = super(decimal_precision, self).unlink(cr, uid, ids, context=context)
|
||||
self.clear_cache(cr)
|
||||
return res
|
||||
|
||||
def write(self, cr, uid, ids, data, *args, **argv):
|
||||
res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv)
|
||||
self.clear_cache(cr)
|
||||
return res
|
||||
|
||||
decimal_precision()
|
||||
|
|
Loading…
Reference in New Issue