From d02ffad04f6e5c133872f98e789730268a4c2895 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 09:03:55 +0100 Subject: [PATCH 1/9] improved_related bzr revid: fp@tinyerp.com-20081209080355-b3n01hbm3asej3mp --- bin/osv/expression.py | 3 +- bin/osv/fields.py | 94 ++++++++++++++++--------------------------- 2 files changed, 36 insertions(+), 61 deletions(-) diff --git a/bin/osv/expression.py b/bin/osv/expression.py index 93d3a0bc07b..37a2ad65ac1 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 e8c0c3b1ede..d7de7d013fd 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -639,60 +639,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 '%d' 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 = {} @@ -701,12 +668,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]] @@ -718,16 +685,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 From a0b7a8f4e6b9da9689a423f3de30e74ea7892ece Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 15:10:34 +0100 Subject: [PATCH 2/9] modifs bzr revid: fp@tinyerp.com-20081209141034-cj0f9clfgkr1eorz --- bin/osv/orm.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index c9c813da720..165bc86e126 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,)) From 887a992d587bce6cf7487a0b22460d55c7bdc3df Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 15:31:53 +0100 Subject: [PATCH 3/9] improvement bzr revid: fp@tinyerp.com-20081209143153-7t18385iv9bbwasn --- bin/addons/__init__.py | 16 +++++++++++++++- bin/addons/base/module/module.py | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 4eeed2e23c6..2ac9d6ed513 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -442,6 +442,18 @@ def load_module_graph(cr, graph, status=None, **kwargs): migrations = MigrationManager(cr, graph) + # only if update + register_class('base') + pool.instanciate('base', cr) + modobj = pool.get('ir.module.module') + modobj.update_list(cr, 1) + + mids = modobj.search(cr, 1, [('state','=','installed')]) + 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]) + for package in graph: status['progress'] = (float(statusi)+0.1)/len(graph) m = package.name @@ -493,8 +505,10 @@ def load_module_graph(cr, graph, status=None, **kwargs): cr.execute("update ir_module_module set state='installed', latest_version=%s where id=%d", (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() diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index a6767cd6c52..7fe32ab6a73 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -347,8 +347,8 @@ class module(osv.osv): self._update_dependencies(cr, uid, id, terp.get('depends', [])) self._update_category(cr, uid, id, terp.get('category', 'Uncategorized')) - import socket - socket.setdefaulttimeout(10) + #import socket + #socket.setdefaulttimeout(10) for repository in robj.browse(cr, uid, robj.search(cr, uid, [])): try: index_page = urllib.urlopen(repository.url).read() From 549458e0534cf77e53230462a57d21d6cbfc962b Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 15:34:26 +0100 Subject: [PATCH 4/9] improve bzr revid: fp@tinyerp.com-20081209143426-8hp2khrcdevqcdqs --- bin/addons/base/module/module.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index 7fe32ab6a73..0cb090c2bc7 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -325,14 +325,14 @@ class module(osv.osv): if not terp or not terp.get('installable', True): continue - if not os.path.isfile( mod_path ): - import imp - path = imp.find_module(mod_name, [addons.ad, addons._ad]) - imp.load_module(name, *path) - else: - import zipimport - zimp = zipimport.zipimporter(mod_path) - zimp.load_module(mod_name) + #if not os.path.isfile( mod_path ): + # import imp + # path = imp.find_module(mod_name, [addons.ad, addons._ad]) + # imp.load_module(name, *path) + #else: + # import zipimport + # zimp = zipimport.zipimporter(mod_path) + # zimp.load_module(mod_name) id = self.create(cr, uid, { 'name': mod_name, 'state': 'uninstalled', From 6b47dd274aa70dd07521b3ce848f49699de98428 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 15:37:20 +0100 Subject: [PATCH 5/9] improve bzr revid: fp@tinyerp.com-20081209143720-crwf3n3esq54400n --- bin/addons/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 2ac9d6ed513..2163e905178 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -424,6 +424,13 @@ def load_module_graph(cr, graph, status=None, **kwargs): statusi = 0 pool = pooler.get_pool(cr.dbname) + # only if update + register_class('base') + pool.instanciate('base', cr) + modobj = pool.get('ir.module.module') + modobj.update_list(cr, 1) + + # 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}) @@ -442,12 +449,6 @@ def load_module_graph(cr, graph, status=None, **kwargs): migrations = MigrationManager(cr, graph) - # only if update - register_class('base') - pool.instanciate('base', cr) - modobj = pool.get('ir.module.module') - modobj.update_list(cr, 1) - mids = modobj.search(cr, 1, [('state','=','installed')]) for m in modobj.browse(cr, 1, mids): for dep in m.dependencies_id: From a357aa85e58859855761eae990f62e8600204010 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 21:37:54 +0100 Subject: [PATCH 6/9] bugfix bzr revid: fp@tinyerp.com-20081209203754-2xk5qcy0vivsjy4f --- bin/addons/__init__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 2163e905178..7aa8a884f44 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -424,12 +424,6 @@ def load_module_graph(cr, graph, status=None, **kwargs): statusi = 0 pool = pooler.get_pool(cr.dbname) - # only if update - register_class('base') - pool.instanciate('base', cr) - modobj = pool.get('ir.module.module') - modobj.update_list(cr, 1) - # update the graph with values from the database (if exist) ## First, we set the default values for each package in graph @@ -449,12 +443,6 @@ def load_module_graph(cr, graph, status=None, **kwargs): migrations = MigrationManager(cr, graph) - mids = modobj.search(cr, 1, [('state','=','installed')]) - 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]) - for package in graph: status['progress'] = (float(statusi)+0.1)/len(graph) m = package.name @@ -538,11 +526,23 @@ 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) if update_module: for module in tools.config['init']: - # FIXME lp:304807 cr.execute('update ir_module_module set state=%s where state=%s and name=%s', ('to install', 'uninstalled', module)) cr.commit() + + register_class('base') + pool.instanciate('base', cr) + modobj = pool.get('ir.module.module') + modobj.update_list(cr, 1) + + 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')") From f500ecff15296379a6970e6b1eab6c67c3c21dd3 Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Wed, 10 Dec 2008 19:05:06 +0530 Subject: [PATCH 7/9] Reports: FormatLang() corrected - Reports will behave acc. to Language(res.lang),not locale. bzr revid: jvo@tinyerp.com-20081210133506-w9h48mu7qum7ok2g --- bin/addons/base/res/res_lang.py | 135 +++++++++++++++++++++++++- bin/addons/base/res/res_lang_view.xml | 28 ++++++ bin/report/report_sxw.py | 76 ++++++++++----- 3 files changed, 214 insertions(+), 25 deletions(-) diff --git a/bin/addons/base/res/res_lang.py b/bin/addons/base/res/res_lang.py index bdf8c25d283..c90c02e3b98 100644 --- a/bin/addons/base/res/res_lang.py +++ b/bin/addons/base/res/res_lang.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution +# OpenERP, Open Source Management Solution # Copyright (C) 2004-2008 Tiny SPRL (). 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/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 From 02663d978045949ba95de5bed40eea043cd7ee6d Mon Sep 17 00:00:00 2001 From: Najlaa Date: Wed, 10 Dec 2008 15:08:56 +0100 Subject: [PATCH 8/9] [IMP] convert varchar to text in database bzr revid: nel@silver-20081210140856-easnep218it0bnqu --- bin/osv/orm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 165bc86e126..06fb00c42ee 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1530,6 +1530,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)) From 5a836ab2754fa552b68cc5a70a52c50a2c3633da Mon Sep 17 00:00:00 2001 From: Najlaa Date: Wed, 10 Dec 2008 15:11:28 +0100 Subject: [PATCH 9/9] [FIX] correct graph loading when updating database or installing new module from command line lp bug: https://launchpad.net/bugs/304807 fixed bzr revid: nel@silver-20081210141128-oaknnb0rzj68htio --- bin/addons/__init__.py | 44 +++++++++++++++++++++++--------- bin/addons/base/module/module.py | 4 +++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 7aa8a884f44..f9f1e0196dd 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -527,28 +527,48 @@ def load_modules(db, force_demo=False, status=None, update_module=False): 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']: + 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() - register_class('base') - pool.instanciate('base', cr) - modobj = pool.get('ir.module.module') - modobj.update_list(cr, 1) - - 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]) +, + 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 0cb090c2bc7..0e5b976c97c 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