diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index f61b5f16ba0..983af9d17e9 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -424,6 +424,7 @@ def load_module_graph(cr, graph, status=None, **kwargs): statusi = 0 pool = pooler.get_pool(cr.dbname) + # update the graph with values from the database (if exist) ## First, we set the default values for each package in graph additional_data = dict.fromkeys([p.name for p in graph], {'id': 0, 'state': 'uninstalled', 'dbdemo': False, 'latest_version': None}) @@ -493,8 +494,10 @@ def load_module_graph(cr, graph, status=None, **kwargs): cr.execute("update ir_module_module set state='installed', latest_version=%s where id=%s", (ver, mid,)) cr.commit() - # Update translations for all installed languages + # Set new modules and dependencies modobj = pool.get('ir.module.module') + + # Update translations for all installed languages if modobj: modobj.update_translations(cr, 1, [mid], None) cr.commit() @@ -523,17 +526,49 @@ def load_modules(db, force_demo=False, status=None, update_module=False): force = [] if force_demo: force.append('demo') + pool = pooler.get_pool(cr.dbname) + report = tools.assertion_report() if update_module: - for module in tools.config['init']: - # FIXME lp:304807 + basegraph = create_graph(['base'], force) + load_module_graph(cr, basegraph, status, report=report) + + modobj = pool.get('ir.module.module') + modobj.update_list(cr, 1) + + if tools.config['init']: + ids = modobj.search(cr, 1, ['&', ('state', '=', 'uninstalled'), ('name', 'in', tools.config['init'])]) + if ids: + #modobj.write(cr, ids, {'state': 'to install'}) + modobj.button_install(cr, 1, ids) + + ids = modobj.search(cr, 1, ['&', '!', ('name', '=', 'base'), ('state', 'in', ('installed', 'to upgrade'))]) + if ids: + modobj.button_upgrade(cr, 1, ids) + + """ + for module in modobj.browse(cr, uid, modobj.search(crtools.config['init']: cr.execute('update ir_module_module set state=%s where state=%s and name=%s', ('to install', 'uninstalled', module)) cr.commit() + +, + mids = modobj.search(cr, 1, [('state','in',('installed','to install'))]) + for m in modobj.browse(cr, 1, mids): + for dep in m.dependencies_id: + if dep.state=='uninstalled': + modobj.button_install(cr, 1, [m.id]) + #""" + cr.execute("select name from ir_module_module where state in ('installed', 'to install', 'to upgrade','to remove')") else: cr.execute("select name from ir_module_module where state in ('installed', 'to upgrade', 'to remove')") module_list = [name for (name,) in cr.fetchall()] graph = create_graph(module_list, force) - report = tools.assertion_report() + + base = graph['base'] + for kind in ('init', 'demo', 'update'): + if hasattr(base, kind): + delattr(base, kind) + load_module_graph(cr, graph, status, report=report) if report.get_report(): logger.notifyChannel('init', netsvc.LOG_INFO, 'assert: %s' % report) diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index de2544df472..49450970a6f 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -261,6 +261,7 @@ class module(osv.osv): def button_upgrade(self, cr, uid, ids, context=None): depobj = self.pool.get('ir.module.module.dependency') todo = self.browse(cr, uid, ids, context=context) + to_install = set() i = 0 while i). All Rights Reserved # $Id$ # @@ -21,24 +21,153 @@ ############################################################################## from osv import fields, osv +from locale import localeconv class lang(osv.osv): _name = "res.lang" + _description = "Languages" + + def _get_default_date_format(self,cursor,user,context={}): + return '%Y-%m-%d' + + def _get_default_time_format(self,cursor,user,context={}): + return '%H:%M:%S' + _columns = { 'name': fields.char('Name', size=64, required=True), 'code': fields.char('Code', size=5, required=True), 'translatable': fields.boolean('Translatable'), 'active': fields.boolean('Active'), - 'direction': fields.selection([('ltr', 'Left-to-right'), ('rtl', 'Right-to-left')], 'Direction',resuired=True), + 'direction': fields.selection([('ltr', 'Left-to-Right'), ('rtl', 'Right-to-Left')], 'Direction',required=True), + 'date_format':fields.char('Date Format',size=64,required=True), + 'time_format':fields.char('Time Format',size=64,required=True), + 'grouping':fields.char('Separator Format',size=64,required=True,help="The Separator Format should be like [,n] where 0 < n :starting from Unit digit.-1 will end the separation. e.g. [3,2,-1] will represent 106500 to be 1,06,500;[1,2,-1] will represent it to be 106,50,0;[3] will represent it as 106,500. Provided ',' as the thousand separator in each case."), + 'decimal_point':fields.char('Decimal Separator', size=64,required=True), + 'thousands_sep':fields.char('Thousands Separator',size=64), + 'legend':fields.text('Legends for Date and Time Formats',readonly=True), } _defaults = { 'active': lambda *a: 1, 'translatable': lambda *a: 0, 'direction': lambda *a: 'ltr', + 'date_format':_get_default_date_format, + 'time_format':_get_default_time_format, + 'grouping':lambda *a: '[]', + 'decimal_point':lambda *a: '.', + 'thousands_sep':lambda *a: ',', + 'legend': lambda *a: '%a - Abbreviated weekday name.\ +\n%A - Full weekday name.\ +\n%b - Abbreviated month name.\ +\n%B - Full month name. \ +\n%c - Appropriate date and time representation.\ +\n%d - Day of the month as a decimal number [01,31].\ +\n%H - Hour (24-hour clock) as a decimal number [00,23].\ +\n%I - Hour (12-hour clock) as a decimal number [01,12].\ +\n%j - Day of the year as a decimal number [001,366].\ +\n%m - Month as a decimal number [01,12].\ +\n%M - Minute as a decimal number [00,59].\ +\n%p - Equivalent of either AM or PM.\ +\n%S - Second as a decimal number [00,61].\ +\n%U - Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.\ +\n%w - Weekday as a decimal number [0(Sunday),6].\ +\n%W - Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.\ +\n%x - Appropriate date representation.\ +\n%X - Appropriate time representation.\ +\n%y - Year without century as a decimal number [00,99].\ +\n%Y - Year with century as a decimal number.\ +\n ==========================================\ +\n\nExamples:\ +\n1. %c ==> Fri Dec 5 18:25:20 2008\ +\n2. %a ,%A ==> Fri, Friday\ +\n3. %x ,%X ==> 12/05/08, 18:25:20\ +\n4. %b, %B ==> Dec, December\ +\n5. %y, %Y ==> 08, 2008\ +\n6. %d, %m ==> 05, 12\ +\n7. %H:%M:%S ==> 18:25:20\ +\n8. %I:%M:%S %p ==> 06:25:20 PM\ +\n9. %j ==> 340\ +\n10. %S ==> 20\ +\n11. %U or %W ==> 48 (49th week)\ +\n12. %w ==> 5 ( Friday is the 6th day)', } + + def _group(self,cr,uid,ids,s, monetary=False): + conv = localeconv() + + lang_obj=self.browse(cr,uid,ids[0]) + thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep'] + + grouping = eval(lang_obj.grouping) + + if not grouping: + return (s, 0) + result = "" + seps = 0 + spaces = "" + if s[-1] == ' ': + sp = s.find(' ') + spaces = s[sp:] + s = s[:sp] + while s and grouping: + # if grouping is -1, we are done + if grouping[0] == -1: + break + # 0: re-use last group ad infinitum + elif grouping[0] != 0: + #process last group + group = grouping[0] + grouping = grouping[1:] + if result: + result = s[-group:] + thousands_sep + result + seps += 1 + else: + result = s[-group:] + s = s[:-group] + if s and s[-1] not in "0123456789": + # the leading string is only spaces and signs + return s + result + spaces, seps + if not result: + return s + spaces, seps + if s: + result = s + thousands_sep + result + seps += 1 + return result + spaces, seps + + def format(self,cr,uid,ids,percent, value, grouping=False, monetary=False): + """ Format() will return the language-specific output for float values""" + + if percent[0] != '%': + raise ValueError("format() must be given exactly one %char format specifier") + + lang_obj=self.browse(cr,uid,ids[0]) + + formatted = percent % value + # floats and decimal ints need special action! + if percent[-1] in 'eEfFgG': + seps = 0 + parts = formatted.split('.') + + if grouping: + parts[0], seps = self._group(cr,uid,ids,parts[0], monetary=monetary) + + decimal_point=lang_obj.decimal_point + formatted = decimal_point.join(parts) + while seps: + sp = formatted.find(' ') + if sp == -1: break + formatted = formatted[:sp] + formatted[sp+1:] + seps -= 1 + elif percent[-1] in 'diu': + if grouping: + formatted = self._group(cr,uid,ids,formatted, monetary=monetary)[0] + + return formatted + +# import re, operator +# _percent_re = re.compile(r'%(?:\((?P.*?)\))?' +# r'(?P[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]') lang() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/bin/addons/base/res/res_lang_view.xml b/bin/addons/base/res/res_lang_view.xml index 3c6f45f0ad4..428edcdad44 100644 --- a/bin/addons/base/res/res_lang_view.xml +++ b/bin/addons/base/res/res_lang_view.xml @@ -15,6 +15,34 @@ + + res.lang.form + res.lang + form + +
+ + + + + + + + + + + + + + + + + + + + +
+ Languages res.lang diff --git a/bin/osv/expression.py b/bin/osv/expression.py index 0ec1e74765b..d572ae85f3a 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -22,6 +22,7 @@ ############################################################################## from tools import flatten, reverse_enumerate +import fields class expression(object): @@ -190,7 +191,7 @@ class expression(object): dom = _rec_get(ids2, working_table, left) self.__exp = self.__exp[:i] + dom + self.__exp[i+1:] else: - if isinstance(right, basestring): + if isinstance(right, basestring): # and not isinstance(field, fields.related): res_ids = field_obj.name_search(cr, uid, right, [], operator, limit=None) right = map(lambda x: x[0], res_ids) self.__exp[i] = (left, 'in', right) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 617399478f1..9c2640bcc4c 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -638,60 +638,27 @@ class function(_column): class related(function): - def _fnct_search(self, tobj, cr, uid, obj=None, name=None, context=None): - where_flag = 0 - where = " where" - query = "select %s.id from %s" % (obj._table, obj._table) - relation_child = obj._name - relation = obj._name - for i in range(len(self._arg)): - field_detail = self._field_get(cr, uid, obj, relation, self._arg[i]) - relation = field_detail[0] - if field_detail[1] in ('one2many', 'many2many'): - obj_child = obj.pool.get(field_detail[2][self._arg[i]]['relation']) - field_detail_child = obj_child.fields_get(cr, uid,) - - fields_filter = dict(filter(lambda x: x[1].get('relation', False) - and x[1].get('relation') == relation_child - and x[1].get('type')=='many2one', field_detail_child.items())) - query += " inner join %s on %s.id = %s.%s" % (obj_child._table, obj._table, obj_child._table, fields_filter.keys()[0]) - relation_child = relation - elif field_detail[1] in ('many2one'): - obj_child = obj.pool.get(field_detail[2][self._arg[i]]['relation']) - obj_child2 = obj.pool.get(relation_child) - if obj_child._name == obj_child2._name: -# select res_partner.id from res_partner where res_partner.parent_id in(select id from res_partner where res_partner.date >= '2008-10-01'); -# where +=" %s.id = %s.%s in (select id from %s where %s.%s %s %s"%(obj_child._table,obj_child2._table,self._arg[i]) - pass - else: - query += " inner join %s on %s.id = %s.%s" % (obj_child._table, obj_child._table, obj_child2._table, self._arg[i]) - relation_child = field_detail[0] - if i == (len(self._arg)-1): - if obj_child._inherits: - obj_child_inherits = obj.pool.get(obj_child._inherits.keys()[0]) - query += " inner join %s on %s.id = %s.%s" % (obj_child_inherits._table, obj_child_inherits._table, obj_child._table, obj_child._inherits.values()[0]) - obj_child = obj_child_inherits - where += " %s.%s %s '%%%s%%' and" % (obj_child._table, obj_child._rec_name, context[0][1], context[0][2]) + def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}): + self._field_get2(cr, uid, obj, context) + i = len(self._arg)-1 + sarg = name + while i>0: + if type(sarg) in [type([]), type( (1,) )]: + where = [(self._arg[i], 'in', sarg)] else: - obj_child = obj.pool.get(relation_child) - if field_detail[1] in ('char'): - where += " %s.%s %s '%%%s%%' and" % (obj_child._table, self._arg[i], context[0][1], context[0][2]) - if field_detail[1] in ('date'): - where += " %s.%s %s '%s' and" % (obj_child._table, self._arg[i], context[0][1], context[0][2]) - if field_detail[1] in ['integer', 'long', 'float','integer_big']: - where += " %s.%s %s '%s' and" % (obj_child._table, self._arg[i], context[0][1], context[0][2]) - if len(where)>10: - query += where.rstrip('and') - cr.execute(query) - ids = [] - for id in cr.fetchall(): - ids.append(id[0]) - return [('id', 'in', ids)] + where = [(self._arg[i], '=', sarg)] + if domain: + where = map(lambda x: (self._arg[i],x[1], x[2]), domain) + domain = [] + sarg = obj.pool.get(self._relations[i]['object']).search(cr, uid, where, context=context) + i -= 1 + return [(self._arg[0], 'in', sarg)] -# def _fnct_write(self,obj,cr, uid, ids,values, field_name, args, context=None): -# raise 'Not Implemented Yet' + def _fnct_write(self,obj,cr, uid, ids,values, field_name, args, context=None): + raise 'Not Implemented Yet' def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None): + self._field_get2(cr, uid, obj, context) if not ids: return {} relation = obj._name res = {} @@ -700,12 +667,12 @@ class related(function): t_data = data relation = obj._name for i in range(len(self.arg)): - field_detail = self._field_get(cr, uid, obj, relation, self.arg[i]) - relation = field_detail[0] + field_detail = self._relations[i] + relation = field_detail['object'] if not t_data[self.arg[i]]: t_data = False break - if field_detail[1] in ('one2many', 'many2many'): + if field_detail['type'] in ('one2many', 'many2many'): t_data = t_data[self.arg[i]][0] else: t_data = t_data[self.arg[i]] @@ -717,16 +684,23 @@ class related(function): def __init__(self, *arg, **args): self.arg = arg + self._relations = [] super(related, self).__init__(self._fnct_read, arg, fnct_inv_arg=arg, method=True, fnct_search=self._fnct_search, **args) - # TODO: call field_get on the object, not in the DB - def _field_get(self, cr, uid, obj, model_name, prop): - fields = obj.pool.get(model_name).fields_get(cr, uid,[prop]) - if fields.get(prop, False): - return(fields[prop].get('relation', False), fields[prop].get('type', False), fields) - else: - raise 'Field %s not exist in %s' % (prop, model_name) + def _field_get2(self, cr, uid, obj, context={}): + if self._relations: + return + obj_name = obj._name + for i in range(len(self._arg)): + f = obj.pool.get(obj_name).fields_get(cr, uid, [self._arg[i]], context=context)[self._arg[i]] + self._relations.append({ + 'object': obj_name, + 'type': f['type'] + }) + if f.get('relation',False): + obj_name = f['relation'] + self._relations[-1]['relation'] = f['relation'] # --------------------------------------------------------- # Serialized fields diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 5a2c8aaf34b..f623e10471e 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -308,12 +308,16 @@ class orm_template(object): cr.execute('SELECT nextval(%s)', ('ir_model_id_seq',)) model_id = cr.fetchone()[0] cr.execute("INSERT INTO ir_model (id,model, name, info,state) VALUES (%s, %s, %s, %s,%s)", (model_id, self._name, self._description, self.__doc__, 'base')) - if 'module' in context: - cr.execute("INSERT INTO ir_model_data (name,date_init,date_update,module,model,res_id) VALUES (%s, now(), now(), %s, %s, %s)", \ - ('model_'+self._name.replace('.','_'), context['module'], 'ir.model', model_id) - ) else: model_id = cr.fetchone()[0] + if 'module' in context: + name_id = 'model_'+self._name.replace('.','_') + cr.execute('select * from ir_model_data where name=%s and res_id=%s', (name_id,model_id)) + if not cr.rowcount: + cr.execute("INSERT INTO ir_model_data (name,date_init,date_update,module,model,res_id) VALUES (%s, now(), now(), %s, %s, %s)", \ + (name_id, context['module'], 'ir.model', model_id) + ) + cr.commit() cr.execute("SELECT * FROM ir_model_fields WHERE model=%s", (self._name,)) @@ -1523,6 +1527,12 @@ class orm(orm_template): cr.execute('UPDATE "%s" SET "%s"=temp_change_size::VARCHAR(%d)' % (self._table, k, f.size)) cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size' % (self._table,)) cr.commit() + if f_pg_type == 'varchar' and f._type == 'text': + cr.execute("ALTER TABLE \"%s\" RENAME COLUMN \"%s\" TO temp_change_type" % (self._table, k)) + cr.execute("ALTER TABLE \"%s\" ADD COLUMN \"%s\" text " % (self._table, k)) + cr.execute("UPDATE \"%s\" SET \"%s\"=temp_change_type" % (self._table, k)) + cr.execute("ALTER TABLE \"%s\" DROP COLUMN temp_change_type" % (self._table,)) + cr.commit() if f_pg_type == 'date' and f._type == 'datetime': cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_type' % (self._table, k)) cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" TIMESTAMP' % (self._table, k)) diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index a776e4ee6c3..ddf0393e910 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -36,6 +36,7 @@ import copy import StringIO import zipfile import os +import mx.DateTime DT_FORMAT = '%Y-%m-%d' DHM_FORMAT = '%Y-%m-%d %H:%M:%S' @@ -255,6 +256,7 @@ class rml_parse(object): 'format': self.format, 'formatLang': self.formatLang, 'logo' : user.company_id.logo, + 'lang' : user.company_id.partner_id.lang, } self.localcontext.update(context) self.rml_header = user.company_id.rml_header @@ -333,31 +335,61 @@ class rml_parse(object): else: obj._cache[table][id] = {'id': id} - def formatLang(self, value, digit=2, date=False): + def formatLang(self, value, digits=2, date=False,date_time=False, grouping=True, monetary=False, currency=None): if not value: return '' - lc, encoding = locale.getdefaultlocale() - if not encoding: - encoding = 'UTF-8' - if encoding == 'utf': - encoding = 'UTF-8' - if encoding == 'cp1252': - encoding= '1252' + + pool_lang=self.pool.get('res.lang') lang = self.localcontext.get('lang', 'en_US') or 'en_US' - try: - if os.name == 'nt': - locale.setlocale(locale.LC_ALL, _LOCALE2WIN32.get(lang, lang) + '.' + encoding) + lang_obj = pool_lang.browse(self.cr,self.uid,pool_lang.search(self.cr,self.uid,[('code','=',lang)])[0]) + + if date or date_time: + date_format = lang_obj.date_format + if date_time: + date_format = lang_obj.date_format + " " + lang_obj.time_format + + if not isinstance(value, time.struct_time): + # assume string, parse it + if len(str(value)) == 10: + # length of date like 2001-01-01 is ten + # assume format '%Y-%m-%d' + date = mx.DateTime.strptime(str(value),DT_FORMAT) + else: + # assume format '%Y-%m-%d %H:%M:%S' + value = str(value)[:19] + date = mx.DateTime.strptime(str(value),DHM_FORMAT) 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.localcontext.get('lang', 'en_US') or 'en_US')) - if date: - date = time.strptime(value, DT_FORMAT) - return time.strftime(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'), - date) - return locale.format('%.' + str(digit) + 'f', value, True) + date = mx.DateTime.DateTime(*(value.timetuple()[:6])) + + return date.strftime(date_format) + + return lang_obj.format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary) + +# def formatLang(self, value, digit=2, date=False): +# if not value: +# return '' +# lc, encoding = locale.getdefaultlocale() +# if not encoding: +# encoding = 'UTF-8' +# if encoding == 'utf': +# encoding = 'UTF-8' +# if encoding == 'cp1252': +# encoding= '1252' +# lang = self.localcontext.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.localcontext.get('lang', 'en_US') or 'en_US')) +# if date: +# date = time.strptime(value, DT_FORMAT) +# return time.strftime(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'), +# date) +# return locale.format('%.' + str(digit) + 'f', value, True) def repeatIn(self, lst, name, nodes_parent=False): self._node.data = '' @@ -555,7 +587,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, fields_process=_fields_process) + return table_obj.browse(cr, uid, ids, list_class=browse_record_list, context=context) def create(self, cr, uid, ids, data, context=None): logo = None