From d314626a204eb5746ed21a45bc041c8a0364e02d Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 26 Jan 2009 10:35:16 +0100 Subject: [PATCH 1/6] [IMP] remove commented code bzr revid: christophe@tinyerp.com-20090126093516-or5huux2zssxtnay --- bin/addons/base/ir/ir_model.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 69729317471..1631d7e1229 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -96,11 +96,6 @@ class ir_model_grid(osv.osv): _table = 'ir_model' _inherit = 'ir.model' _description = "Objects Security Grid" - #_rec_name = 'name' - #_columns = { - # 'name': fields.char('Object', size=64), - # 'model': fields.char('Object Name', size=64), - #} def create(self, cr, uid, vals, context=None): raise osv.except_osv('Error !', 'You cannot add an entry to this view !') From 8adc58fa92075da8f923839bd4b8f780a3f53d8e Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 26 Jan 2009 16:47:04 +0100 Subject: [PATCH 2/6] [FIX] use _inherit for inherited objects bzr revid: christophe@tinyerp.com-20090126154704-gexicefs2528dg51 --- bin/addons/base/ir/ir_actions.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/addons/base/ir/ir_actions.py b/bin/addons/base/ir/ir_actions.py index 02b4fa6da6e..a544048bbb1 100644 --- a/bin/addons/base/ir/ir_actions.py +++ b/bin/addons/base/ir/ir_actions.py @@ -233,6 +233,7 @@ act_window_view() class act_wizard(osv.osv): _name = 'ir.actions.wizard' + _inherit = 'ir.actions.actions' _table = 'ir_act_wizard' _sequence = 'ir_actions_id_seq' _columns = { @@ -669,12 +670,8 @@ actions_server() class act_window_close(osv.osv): _name = 'ir.actions.act_window_close' + _inherit = 'ir.actions.actions' _table = 'ir_actions' - _sequence = 'ir_actions_id_seq' - _columns = { - 'name': fields.char('Action Name', size=64, translate=True), - 'type': fields.char('Action Type', size=32, required=True), - } _defaults = { 'type': lambda *a: 'ir.actions.act_window_close', } From ab41714295af23aa5c95790777fbe2e65dff8efa Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 26 Jan 2009 16:50:46 +0100 Subject: [PATCH 3/6] [IMP] log in logger 'orm' instead of 'init' [FIX] warn the user when a column has been remove from a object bzr revid: christophe@tinyerp.com-20090126155046-quegkdj9l5a4d3ub --- bin/osv/orm.py | 52 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 1a5d67456af..f55bc2e28ed 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1368,7 +1368,7 @@ class orm(orm_template): def _parent_store_compute(self, cr): logger = netsvc.Logger() - logger.notifyChannel('init', netsvc.LOG_INFO, 'Computing parent left and right for table %s...' % (self._table, )) + logger.notifyChannel('orm', netsvc.LOG_INFO, 'Computing parent left and right for table %s...' % (self._table, )) def browse_rec(root, pos=0): # TODO: set order where = self._parent_name+'='+str(root) @@ -1388,7 +1388,7 @@ class orm(orm_template): def _update_store(self, cr, f, k): logger = netsvc.Logger() - logger.notifyChannel('init', netsvc.LOG_INFO, "storing computed values of fields.function '%s'" % (k,)) + logger.notifyChannel('orm', netsvc.LOG_INFO, "storing computed values of fields.function '%s'" % (k,)) ss = self._columns[k]._symbol_set update_query = 'UPDATE "%s" SET "%s"=%s WHERE id=%%s' % (self._table, k, ss[0]) cr.execute('select id from '+self._table) @@ -1425,11 +1425,11 @@ class orm(orm_template): """, (self._table, 'parent_left')) if not cr.rowcount: if 'parent_left' not in self._columns: - logger.notifyChannel('init', netsvc.LOG_ERROR, 'create a column parent_left on object %s: fields.integer(\'Left Parent\', select=1)' % (self._table, )) + logger.notifyChannel('orm', netsvc.LOG_ERROR, 'create a column parent_left on object %s: fields.integer(\'Left Parent\', select=1)' % (self._table, )) if 'parent_right' not in self._columns: - logger.notifyChannel('init', netsvc.LOG_ERROR, 'create a column parent_right on object %s: fields.integer(\'Right Parent\', select=1)' % (self._table, )) + logger.notifyChannel('orm', netsvc.LOG_ERROR, 'create a column parent_right on object %s: fields.integer(\'Right Parent\', select=1)' % (self._table, )) if self._columns[self._parent_name].ondelete<>'cascade': - logger.notifyChannel('init', netsvc.LOG_ERROR, "the columns %s on object must be set as ondelete='cascasde'" % (self._name, self._parent_name)) + logger.notifyChannel('orm', netsvc.LOG_ERROR, "the columns %s on object must be set as ondelete='cascasde'" % (self._name, self._parent_name)) cr.execute('ALTER TABLE "%s" ADD COLUMN "parent_left" INTEGER' % (self._table,)) cr.execute('ALTER TABLE "%s" ADD COLUMN "parent_right" INTEGER' % (self._table,)) cr.commit() @@ -1454,15 +1454,20 @@ class orm(orm_template): # iterate on the database columns to drop the NOT NULL constraints # of fields which were required but have been removed - cr.execute( - "SELECT a.attname, a.attnotnull "\ - "FROM pg_class c, pg_attribute a "\ - "WHERE c.oid=a.attrelid AND c.relname=%s", (self._table,)) - db_columns = cr.dictfetchall() - for column in db_columns: - if column['attname'] not in ('id', 'oid', 'tableoid', 'ctid', 'xmin', 'xmax', 'cmin', 'cmax'): - if column['attnotnull'] and column['attname'] not in self._columns: - cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, column['attname'])) + columns = [c for c in self._columns if not (isinstance(self._columns[c], fields.function) and not self._columns[c].store)] + columns += ('id', 'write_uid', 'write_date', 'create_uid', 'create_date') # openerp access columns + cr.execute("SELECT a.attname, a.attnotnull" + " FROM pg_class c, pg_attribute a" + " WHERE c.relname=%%s" + " AND c.oid=a.attrelid" + " AND a.attisdropped=%%s" + " AND pg_catalog.format_type(a.atttypid, a.atttypmod) NOT IN ('cid', 'tid', 'oid', 'xid')" + " AND a.attname NOT IN (%s)" % ",".join(['%s']*len(columns)), + [self._table, False] + columns) + for column in cr.dictfetchall(): + logger.notifyChannel("orm", netsvc.LOG_WARNING, "column %s is in the table %s but not in the corresponding object %s" % (column['attname'], self._table, self._name)) + if column['attnotnull']: + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, column['attname'])) # iterate on the "object columns" todo_update_store = [] @@ -1512,9 +1517,9 @@ class orm(orm_template): query = 'UPDATE "%s" SET "%s"=%s' % (self._table, k, ss[0]) cr.execute(query, (ss[1](default),)) cr.commit() - logger.notifyChannel('init', netsvc.LOG_DEBUG, 'setting default value of new column %s of table %s'% (k, self._table)) + logger.notifyChannel('orm', netsvc.LOG_DEBUG, 'setting default value of new column %s of table %s'% (k, self._table)) elif not create: - logger.notifyChannel('init', netsvc.LOG_DEBUG, 'creating new column %s of table %s'% (k, self._table)) + logger.notifyChannel('orm', netsvc.LOG_DEBUG, 'creating new column %s of table %s'% (k, self._table)) if isinstance(f, fields.function): order = 10 @@ -1539,7 +1544,7 @@ class orm(orm_template): cr.commit() cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k)) except Exception, e: - logger.notifyChannel('init', netsvc.LOG_WARNING, 'WARNING: unable to set column %s of table %s not null !\nTry to re-run: openerp-server.py --update=module\nIf it doesn\'t work, update records and execute manually:\nALTER TABLE %s ALTER COLUMN %s SET NOT NULL' % (k, self._table, self._table, k)) + logger.notifyChannel('orm', netsvc.LOG_WARNING, 'WARNING: unable to set column %s of table %s not null !\nTry to re-run: openerp-server.py --update=module\nIf it doesn\'t work, update records and execute manually:\nALTER TABLE %s ALTER COLUMN %s SET NOT NULL' % (k, self._table, self._table, k)) cr.commit() elif len(res)==1: f_pg_def = res[0] @@ -1547,7 +1552,7 @@ class orm(orm_template): f_pg_size = f_pg_def['size'] f_pg_notnull = f_pg_def['attnotnull'] if isinstance(f, fields.function) and not f.store: - logger.notifyChannel('init', netsvc.LOG_INFO, 'column %s (%s) in table %s removed: converted to a function !\n' % (k, f.string, self._table)) + logger.notifyChannel('orm', netsvc.LOG_INFO, 'column %s (%s) in table %s removed: converted to a function !\n' % (k, f.string, self._table)) cr.execute('ALTER TABLE %s DROP COLUMN %s'% (self._table, k)) cr.commit() f_obj_type = None @@ -1563,7 +1568,7 @@ class orm(orm_template): ('date', 'datetime', 'TIMESTAMP', '::TIMESTAMP'), ] if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size != f.size: - logger.notifyChannel('init', netsvc.LOG_INFO, "column '%s' in table '%s' changed size" % (k, self._table)) + logger.notifyChannel('orm', netsvc.LOG_INFO, "column '%s' in table '%s' changed size" % (k, self._table)) cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k)) cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" VARCHAR(%d)' % (self._table, k, f.size)) cr.execute('UPDATE "%s" SET "%s"=temp_change_size::VARCHAR(%d)' % (self._table, k, f.size)) @@ -1571,7 +1576,7 @@ class orm(orm_template): cr.commit() for c in casts: if (f_pg_type==c[0]) and (f._type==c[1]): - logger.notifyChannel('init', netsvc.LOG_INFO, "column '%s' in table '%s' changed type to %s." % (k, self._table, c[1])) + logger.notifyChannel('orm', netsvc.LOG_INFO, "column '%s' in table '%s' changed type to %s." % (k, self._table, c[1])) ok = True cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k)) cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, c[2])) @@ -1581,7 +1586,7 @@ class orm(orm_template): if f_pg_type != f_obj_type: if not ok: - logger.notifyChannel('init', netsvc.LOG_WARNING, "column '%s' in table '%s' has changed type (DB = %s, def = %s) but unable to migrate this change !" % (k, self._table, f_pg_type, f._type)) + logger.notifyChannel('orm', netsvc.LOG_WARNING, "column '%s' in table '%s' has changed type (DB = %s, def = %s) but unable to migrate this change !" % (k, self._table, f_pg_type, f._type)) # if the field is required and hasn't got a NOT NULL constraint if f.required and f_pg_notnull == 0: @@ -1598,7 +1603,7 @@ class orm(orm_template): cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k)) cr.commit() except Exception, e: - logger.notifyChannel('init', netsvc.LOG_WARNING, 'unable to set a NOT NULL constraint on column %s of the %s table !\nIf you want to have it, you should update the records and execute manually:\nALTER TABLE %s ALTER COLUMN %s SET NOT NULL' % (k, self._table, self._table, k)) + logger.notifyChannel('orm', netsvc.LOG_WARNING, 'unable to set a NOT NULL constraint on column %s of the %s table !\nIf you want to have it, you should update the records and execute manually:\nALTER TABLE %s ALTER COLUMN %s SET NOT NULL' % (k, self._table, self._table, k)) cr.commit() elif not f.required and f_pg_notnull == 1: cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, k)) @@ -1644,7 +1649,6 @@ class orm(orm_template): cr.execute('ALTER TABLE "' + self._table + '" ADD FOREIGN KEY ("' + k + '") REFERENCES "' + ref + '" ON DELETE ' + f.ondelete) cr.commit() else: - logger = netsvc.Logger() logger.notifyChannel('orm', netsvc.LOG_ERROR, "Programming error !") for order,f,k in todo_update_store: todo_end.append((order, self._update_store, (f, k))) @@ -1661,7 +1665,7 @@ class orm(orm_template): cr.execute('alter table "%s" add constraint "%s_%s" %s' % (self._table, self._table, key, con,)) cr.commit() except: - logger.notifyChannel('init', netsvc.LOG_WARNING, 'unable to add \'%s\' constraint on table %s !\n If you want to have it, you should update the records and execute manually:\nALTER table %s ADD CONSTRAINT %s_%s %s' % (con, self._table, self._table, self._table, key, con,)) + logger.notifyChannel('orm', netsvc.LOG_WARNING, 'unable to add \'%s\' constraint on table %s !\n If you want to have it, you should update the records and execute manually:\nALTER table %s ADD CONSTRAINT %s_%s %s' % (con, self._table, self._table, self._table, key, con,)) if create: if hasattr(self, "_sql"): From 8822ada31f82c568583dd39def2510f42179b584 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 27 Jan 2009 11:25:15 +0100 Subject: [PATCH 4/6] bugfix_ptt bzr revid: fp@tinyerp.com-20090127102515-ric7p0yptywmy2qk --- bin/addons/base/ir/ir_model.py | 2 +- bin/addons/base/module/module.py | 17 +++++++---------- bin/osv/orm.py | 9 ++++++++- bin/report/report_sxw.py | 26 -------------------------- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 0e2f61fd0ba..c67a758ae91 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -40,7 +40,7 @@ class ir_model(osv.osv): _rec_name = 'name' _columns = { 'name': fields.char('Object Name', size=64, translate=True, required=True), - 'model': fields.char('Object Name', size=64, required=True, select=1), + 'model': fields.char('Object', size=64, required=True, select=1), 'info': fields.text('Information'), 'field_id': fields.one2many('ir.model.fields', 'model_id', 'Fields', required=True), 'state': fields.selection([('manual','Custom Object'),('base','Base Object')],'Manualy Created',readonly=True), diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index 984d67f01a2..7ce02e3c1e8 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -490,16 +490,13 @@ class module(osv.osv): def create(self, cr, uid, data, context={}): id = super(module, self).create(cr, uid, data, context) - print 'Create', { - 'name': 'module_name_translation', - 'model': 'ir.module.module', - 'res_id': id, - } - self.pool.get('ir.model.data').create(cr, uid, { - 'name': 'module_name_translation', - 'model': 'ir.module.module', - 'res_id': id, - }) + if data.get('name'): + self.pool.get('ir.model.data').create(cr, uid, { + 'name': 'module_name_translation', + 'model': 'ir.module.module', + 'res_id': id, + 'module': data['name'] + }) return id module() diff --git a/bin/osv/orm.py b/bin/osv/orm.py index f55bc2e28ed..ea135309033 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1382,8 +1382,15 @@ class orm(orm_template): for id in childs: pos2 = browse_rec(id[0], pos2) cr.execute('update '+self._table+' set parent_left=%s, parent_right=%s where id=%s', (pos,pos2,root)) + print 'Updating', self._table, pos,pos2,root return pos2+1 - browse_rec(None) + query = 'SELECT id FROM '+self._table+' WHERE '+self._parent_name+' IS NULL' + if self._parent_order: + query += ' order by '+self._parent_order + pos = 0 + cr.execute(query) + for (root,) in cr.fetchall(): + pos = browse_rec(root, pos) return True def _update_store(self, cr, f, k): diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index db0e0c6ed58..1b2406a2581 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -358,32 +358,6 @@ class rml_parse(object): 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 = '' From 7cb41c31ec5f78f7959ffca2589abb5bd7646a6b Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 27 Jan 2009 11:29:31 +0100 Subject: [PATCH 5/6] removed_print bzr revid: fp@tinyerp.com-20090127102931-h5sk00kornccw4fr --- bin/osv/orm.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index ea135309033..4658d57b541 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1382,7 +1382,6 @@ class orm(orm_template): for id in childs: pos2 = browse_rec(id[0], pos2) cr.execute('update '+self._table+' set parent_left=%s, parent_right=%s where id=%s', (pos,pos2,root)) - print 'Updating', self._table, pos,pos2,root return pos2+1 query = 'SELECT id FROM '+self._table+' WHERE '+self._parent_name+' IS NULL' if self._parent_order: From 270bbb151b9213d0ef0a51b8a1f9555ff76a4032 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 27 Jan 2009 12:14:25 +0100 Subject: [PATCH 6/6] [IMP] change level of message when a column is not present in the object bzr revid: christophe@tinyerp.com-20090127111425-ktutr1iuvldwnaq0 --- bin/osv/orm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 4658d57b541..f0ee01fa204 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1471,7 +1471,8 @@ class orm(orm_template): " AND a.attname NOT IN (%s)" % ",".join(['%s']*len(columns)), [self._table, False] + columns) for column in cr.dictfetchall(): - logger.notifyChannel("orm", netsvc.LOG_WARNING, "column %s is in the table %s but not in the corresponding object %s" % (column['attname'], self._table, self._name)) + # TODO display this information only when all modules are loaded + logger.notifyChannel("orm", netsvc.LOG_DEBUG, "column %s is in the table %s but not in the corresponding object %s" % (column['attname'], self._table, self._name)) if column['attnotnull']: cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, column['attname']))