← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-server/6.0-opw-update_selection_field-ach into lp:openobject-server/6.0

 

Anup(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/6.0-opw-update_selection_field-ach into lp:openobject-server/6.0.

Requested reviews:
  Olivier Dony (OpenERP) (odo)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-update_selection_field-ach/+merge/52401

Hello,

    Currently it's not possible to update a selection field. Using this fix we'll be able to update the selection field.


Thanks.
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-update_selection_field-ach/+merge/52401
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/6.0-opw-update_selection_field-ach.
=== modified file 'bin/osv/orm.py'
--- bin/osv/orm.py	2011-03-03 14:24:25 +0000
+++ bin/osv/orm.py	2011-03-07 12:06:44 +0000
@@ -2525,14 +2525,19 @@
                                 ('numeric', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
                                 ('float8', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
                             ]
-                            if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size < f.size:
+                            f_size = f.size
+                            if f._type == 'selection':
+                                if f_size is None and f_pg_size != 16:
+                                    f_size = 16
+                            
+                            if f_pg_type == 'varchar' and f._type in ('char','selection') and f_pg_size < f_size:
                                 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))
+                                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))
                                 cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size CASCADE' % (self._table,))
                                 cr.commit()
                                 self.__schema.debug("Table '%s': column '%s' (type varchar) changed size from %s to %s",
-                                    self._table, k, f_pg_size, f.size)
+                                    self._table, k, f_pg_size, f_size)
                             for c in casts:
                                 if (f_pg_type==c[0]) and (f._type==c[1]):
                                     if f_pg_type != f_obj_type:


Follow ups