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

Proposed by Anup(SerpentCS)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/opw-update_selection_field-ach
Merge into: lp:openobject-server
Diff against target: 45 lines (+10/-10)
1 file modified
openerp/osv/orm.py (+10/-10)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/opw-update_selection_field-ach
Reviewer Review Type Date Requested Status
Jay Vora (Serpent Consulting Services) Pending
Olivier Dony (Odoo) Pending
Review via email: mp+52398@code.launchpad.net

Description of the change

Hello,

    Currently we are not able to update the selection field in the database. Using this solution we can update the selection fields.

Thanks.

To post a comment you must log in.
Revision history for this message
xrg (xrg) wrote :

On Monday 07 March 2011, you wrote:
> Anup(OpenERP) has proposed merging
> lp:~openerp-dev/openobject-server/opw-update_selection_field-ach into
> lp:openobject-server.
>
> Requested reviews:
> Jay Vora (OpenERP) (jvo-openerp)
> Olivier Dony (OpenERP) (odo)
>
> For more details, see:
> https://code.launchpad.net/~openerp-dev/openobject-server/opw-update_select
> ion_field-ach/+merge/52398
>
> Hello,
>
> Currently we are not able to update the selection field in the
> database. Using this solution we can update the selection fields.
>
> Thanks.

This reminds me of commit 1273b880acb46f1ed

http://git.hellug.gr/?p=xrg/openobject-server;a=commit;h=1273b880acb46f1ed

--
Say NO to spam and viruses. Stop using Microsoft Windows!

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Panos,

    IMHO the size of the field should never be decreased. The reason would be, what about the data that are already existing and that are beyond the new size. In existing db it cause loss of data.

Thanks.

Revision history for this message
Vo Minh Thu (thu) wrote :

This could be merged after https://code.launchpad.net/~openerp-dev/openobject-server/trunk-improve-get-pg-types-xmo/+merge/74831 and in that case, setting f_size = 16 would not be needed.

Revision history for this message
Vo Minh Thu (thu) wrote :

The above branch has been merged. So setting an arbitrary f_size=16 is now unnecessary. We still have to make the change for 'selection' columns but the test f_pg_size < f_size is no more correct: f_pg_size can currently be negative if the varcahr column has no limit.

Unmerged revisions

3202. By Anup(SerpentCS)

[FIX] update : Updating a size of a selection field is now possible (Maintenance Case : 4374)

3201. By Anup(SerpentCS)

[FIX] committed from the main trunk server

3200. By Anup(SerpentCS)

[MERGE] Merged from the main trunk server

3199. By Anup(OpenERP) <email address hidden>

[MERGE] Merged from the main trunk server

3198. By Anup(SerpentCS)

[FIX] optimized the code for position='after' in inherited view

3197. By Anup(SerpentCS)

[MERGE] Merged from the main trunk server

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/orm.py'
2--- openerp/osv/orm.py 2011-02-21 17:27:57 +0000
3+++ openerp/osv/orm.py 2011-03-07 11:43:53 +0000
4@@ -1511,16 +1511,12 @@
5 else:
6 del(node.attrib[attribute[0]])
7 else:
8- sib = node.getnext()
9 for child in node2:
10 if pos == 'inside':
11 node.append(child)
12 elif pos == 'after':
13- if sib is None:
14- node.addnext(child)
15- node = child
16- else:
17- sib.addprevious(child)
18+ node.addnext(child)
19+ node = child
20 elif pos == 'before':
21 node.addprevious(child)
22 else:
23@@ -2522,14 +2518,18 @@
24 ('numeric', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
25 ('float8', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
26 ]
27- if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size < f.size:
28+ f_size = f.size
29+ if f._type == 'selection':
30+ if f_size is None and f_pg_size != 16:
31+ f_size = 16
32+ if f_pg_type == 'varchar' and f._type in ('char','selection') and f_pg_size < f_size:
33 cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k))
34- cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" VARCHAR(%d)' % (self._table, k, f.size))
35- cr.execute('UPDATE "%s" SET "%s"=temp_change_size::VARCHAR(%d)' % (self._table, k, f.size))
36+ cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" VARCHAR(%d)' % (self._table, k, f_size))
37+ cr.execute('UPDATE "%s" SET "%s"=temp_change_size::VARCHAR(%d)' % (self._table, k, f_size))
38 cr.execute('ALTER TABLE "%s" DROP COLUMN temp_change_size CASCADE' % (self._table,))
39 cr.commit()
40 self.__schema.debug("Table '%s': column '%s' (type varchar) changed size from %s to %s",
41- self._table, k, f_pg_size, f.size)
42+ self._table, k, f_pg_size, f_size)
43 for c in casts:
44 if (f_pg_type==c[0]) and (f._type==c[1]):
45 if f_pg_type != f_obj_type: