Improvements
bzr revid: fp@tinyerp.com-3bf3ca5f392a63f5285035e50e972129f442ae35
This commit is contained in:
parent
3bf4d5294d
commit
fca1637a6e
|
@ -123,10 +123,24 @@ class users(osv.osv):
|
|||
_sql_constraints = [
|
||||
('login_key', 'UNIQUE (login)', 'You can not have two users with the same login !')
|
||||
]
|
||||
def _get_action(self,cr, uid, context={}):
|
||||
ids = self.pool.get('ir.ui.menu').search(cr, uid, [('usage','=','menu')])
|
||||
return ids and ids[0] or False
|
||||
|
||||
def _get_company(self,cr, uid, context={}):
|
||||
return self.pool.get('res.users').browse(cr, uid, uid, context).company_id.id
|
||||
|
||||
def _get_menu(self,cr, uid, context={}):
|
||||
ids = self.pool.get('ir.actions.act_window').search(cr, uid, [('usage','=','menu')])
|
||||
return ids and ids[0] or False
|
||||
|
||||
_defaults = {
|
||||
'password' : lambda obj,cr,uid,context={} : '',
|
||||
'context_lang': lambda *args: 'en_US',
|
||||
'active' : lambda obj,cr,uid,context={} : True,
|
||||
'menu_id': _get_menu,
|
||||
'action_id': _get_menu,
|
||||
'company_id': _get_company,
|
||||
}
|
||||
def company_get(self, cr, uid, uid2):
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
|
||||
|
|
|
@ -107,7 +107,7 @@ class browse_record_list(list):
|
|||
|
||||
|
||||
class browse_record(object):
|
||||
def __init__(self, cr, uid, id, table, cache, context=None, list_class = None):
|
||||
def __init__(self, cr, uid, id, table, cache, context=None, list_class = None, fields_process={}):
|
||||
'''
|
||||
table : the object (inherited from orm)
|
||||
context : a dictionnary with an optionnal context
|
||||
|
@ -122,6 +122,7 @@ class browse_record(object):
|
|||
self._table = table
|
||||
self._table_name = self._table._name
|
||||
self._context = context
|
||||
self._fields_process = fields_process
|
||||
|
||||
cache.setdefault(table._name, {})
|
||||
self._data = cache[table._name]
|
||||
|
@ -160,7 +161,13 @@ class browse_record(object):
|
|||
ffields = [(name,col)]
|
||||
ids = filter(lambda id: not self._data[id].has_key(name), self._data.keys())
|
||||
# read the data
|
||||
datas = self._table.read(self._cr, self._uid, ids, map(lambda x: x[0], ffields), context=self._context, load="_classic_write")
|
||||
fffields = map(lambda x: x[0], ffields)
|
||||
datas = self._table.read(self._cr, self._uid, ids, fffields, context=self._context, load="_classic_write")
|
||||
if self._fields_process:
|
||||
for n,f in ffields:
|
||||
if f._type in self._fields_process:
|
||||
for d in datas:
|
||||
d[n] = self._fields_process[f._type](d[n], self)
|
||||
|
||||
# create browse records for 'remote' objects
|
||||
for data in datas:
|
||||
|
@ -174,13 +181,13 @@ class browse_record(object):
|
|||
else:
|
||||
ids2 = data[n]
|
||||
if ids2:
|
||||
data[n] = browse_record(self._cr, self._uid, ids2, obj, self._cache, context=self._context, list_class=self._list_class)
|
||||
data[n] = browse_record(self._cr, self._uid, ids2, obj, self._cache, context=self._context, list_class=self._list_class, fields_process=self._fields_process)
|
||||
else:
|
||||
data[n] = browse_null()
|
||||
else:
|
||||
data[n] = browse_null()
|
||||
elif f._type in ('one2many', 'many2many') and len(data[n]):
|
||||
data[n] = self._list_class([browse_record(self._cr,self._uid,id,self._table.pool.get(f._obj),self._cache, context=self._context, list_class=self._list_class) for id in data[n]], self._context)
|
||||
data[n] = self._list_class([browse_record(self._cr,self._uid,id,self._table.pool.get(f._obj),self._cache, context=self._context, list_class=self._list_class, fields_process=self._fields_process) for id in data[n]], self._context)
|
||||
self._data[data['id']].update(data)
|
||||
return self._data[self._id][name]
|
||||
|
||||
|
@ -360,7 +367,7 @@ class orm_template(object):
|
|||
if not self._table:
|
||||
self._table=self._name.replace('.','_')
|
||||
|
||||
def browse(self, cr, uid, select, context=None, list_class=None):
|
||||
def browse(self, cr, uid, select, context=None, list_class=None, fields_process={}):
|
||||
if not context:
|
||||
context={}
|
||||
self._list_class = list_class or browse_record_list
|
||||
|
@ -368,9 +375,9 @@ class orm_template(object):
|
|||
# need to accepts ints and longs because ids coming from a method
|
||||
# launched by button in the interface have a type long...
|
||||
if isinstance(select, (int, long)):
|
||||
return browse_record(cr,uid,select,self,cache, context=context, list_class=self._list_class)
|
||||
return browse_record(cr,uid,select,self,cache, context=context, list_class=self._list_class, fields_process=fields_process)
|
||||
elif isinstance(select,list):
|
||||
return self._list_class([browse_record(cr,uid,id,self,cache, context=context, list_class=self._list_class) for id in select], context)
|
||||
return self._list_class([browse_record(cr,uid,id,self,cache, context=context, list_class=self._list_class, fields_process=fields_process) for id in select], context)
|
||||
else:
|
||||
return browse_null()
|
||||
|
||||
|
|
|
@ -145,6 +145,57 @@ _LOCALE2WIN32 = {
|
|||
'vi_VN': 'Vietnamese_Viet Nam',
|
||||
}
|
||||
|
||||
class _format(object):
|
||||
def __init__(self, name, object):
|
||||
#super(_date_format, self).__init__(self)
|
||||
self.object = object
|
||||
self.name=name
|
||||
lc, encoding = locale.getdefaultlocale()
|
||||
if encoding == 'utf':
|
||||
encoding = 'UTF-8'
|
||||
if encoding == 'cp1252':
|
||||
encoding= '1252'
|
||||
lang = self.object._context.get('lang', 'en_US') or 'en_US'
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
locale.setlocale(locale.LC_ALL, _LOCALE2WIN32.get(lang, lang) + '.' + encoding)
|
||||
else:
|
||||
locale.setlocale(locale.LC_ALL, lang + '.' + encoding)
|
||||
except Exception:
|
||||
netsvc.Logger().notifyChannel('report', netsvc.LOG_WARNING,
|
||||
'report %s: unable to set locale "%s"' % (self.name,
|
||||
self.object._context.get('lang', 'en_US') or 'en_US'))
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class _float_format(_format):
|
||||
def __str__(self):
|
||||
if not self.object._context:
|
||||
return self.name
|
||||
return locale.format('%.' + str(2) + 'f', self.name, True)
|
||||
|
||||
class _int_format(_format):
|
||||
def __str__(self):
|
||||
if not self.object._context:
|
||||
return self.name
|
||||
return locale.format('%d', self.name, True)
|
||||
|
||||
class _date_format(_format):
|
||||
def __str__(self):
|
||||
if not self.object._context:
|
||||
return self.name
|
||||
if self.name:
|
||||
datedata = time.strptime(self.name, DT_FORMAT)
|
||||
return time.strftime(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'),
|
||||
datedata)
|
||||
return ''
|
||||
|
||||
_fields_process = {
|
||||
'float': _float_format,
|
||||
'date': _date_format,
|
||||
'integer': _int_format
|
||||
}
|
||||
|
||||
#
|
||||
# Context: {'node': node.dom}
|
||||
#
|
||||
|
@ -276,7 +327,6 @@ class rml_parse(object):
|
|||
else:
|
||||
obj._cache[table][id] = {'id': id}
|
||||
|
||||
|
||||
def formatLang(self, value, digit=2, date=False):
|
||||
lc, encoding = locale.getdefaultlocale()
|
||||
if encoding == 'utf':
|
||||
|
@ -377,8 +427,8 @@ class rml_parse(object):
|
|||
if isinstance(newtext, list):
|
||||
todo.append((key, newtext))
|
||||
else:
|
||||
if not isinstance(newtext, basestring):
|
||||
newtext = str(newtext)
|
||||
#if not isinstance(newtext, basestring):
|
||||
newtext = str(newtext)
|
||||
# if there are two [[]] blocks the same, it will replace both
|
||||
# but it's ok because it should evaluate to the same thing
|
||||
# anyway
|
||||
|
@ -491,7 +541,7 @@ class report_sxw(report_rml):
|
|||
|
||||
def getObjects(self, cr, uid, ids, context):
|
||||
table_obj = pooler.get_pool(cr.dbname).get(self.table)
|
||||
return table_obj.browse(cr, uid, ids, list_class=browse_record_list, context=context)
|
||||
return table_obj.browse(cr, uid, ids, list_class=browse_record_list, context=context, fields_process=_fields_process)
|
||||
|
||||
def create(self, cr, uid, ids, data, context=None):
|
||||
logo = None
|
||||
|
|
Loading…
Reference in New Issue