Merge lp:~therp-nl/openupgrade-addons/6.1-hr into lp:openupgrade-addons/6.1

Proposed by Holger Brunn (Therp)
Status: Superseded
Proposed branch: lp:~therp-nl/openupgrade-addons/6.1-hr
Merge into: lp:openupgrade-addons/6.1
Diff against target: 116 lines (+55/-20)
3 files modified
hr/migrations/6.1.1.1/post-migration.py (+51/-16)
hr/migrations/6.1.1.1/pre-migration.py (+3/-3)
hr/migrations/6.1.1.1/user_notes.txt (+1/-1)
To merge this branch: bzr merge lp:~therp-nl/openupgrade-addons/6.1-hr
Reviewer Review Type Date Requested Status
OpenUpgrade Committers Pending
Review via email: mp+109608@code.launchpad.net

This proposal has been superseded by a proposal from 2012-06-11.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hr/migrations/6.1.1.1/post-migration.py'
--- hr/migrations/6.1.1.1/post-migration.py 2012-06-08 09:18:00 +0000
+++ hr/migrations/6.1.1.1/post-migration.py 2012-06-11 14:26:22 +0000
@@ -8,30 +8,65 @@
8@openupgrade.migrate()8@openupgrade.migrate()
9def migrate(cr, version):9def migrate(cr, version):
10 pool = pooler.get_pool(cr.dbname)10 pool = pooler.get_pool(cr.dbname)
11 #null values of the many2one are reset to first value in the selection, restore the null values11 #null values of the many2one are reset to first value in the selection,
12 cr.execute('update hr_employee set marital=NULL where openupgrade_legacy_marital is NULL')12 #restore the null values
13 #get possible marital states and if in the original many2one, update selection field13 cr.execute('update hr_employee set marital=NULL where '+
14 openupgrade.get_legacy_name('marital')+' is NULL')
15 #get possible marital states and if in the original many2one, update
16 #selection field
14 marital_states={}17 marital_states={}
15 for (marital_state,marital_state_name) in pool.get('hr.employee')._columns['marital'].selection:18 for (marital_state,marital_state_name) in pool.get('hr.employee')._columns['marital'].selection:
16 cr.execute(19 cr.execute(
17 'update hr_employee set marital=%(marital_state)s where openupgrade_legacy_marital in'+20 'update hr_employee set marital=%(marital_state)s where '+
18 '(select id from openupgrade_legacy_hr_employee_marital_status where lower(name) in %(marital_states)s)',21 openupgrade.get_legacy_name('marital')+' in'+
19 {'marital_state': marital_state, 'marital_states': tuple([marital_state.lower(),marital_state_name.lower()])})22 '(select id from '+
23 openupgrade.get_legacy_name('hr_employee_marital_status')+
24 ' where lower(name) in %(marital_states)s)',
25 {
26 'marital_state': marital_state,
27 'marital_states':
28 tuple([marital_state.lower(),marital_state_name.lower()])
29 })
20 marital_states[marital_state]=marital_state_name30 marital_states[marital_state]=marital_state_name
21 31
22 #get marital states not included in the selection32 #get marital states not included in the selection
23 cr.execute('select id from hr_employee where openupgrade_legacy_marital is not null and openupgrade_legacy_marital not in '+33 cr.execute(
24 '(select id from openupgrade_legacy_hr_employee_marital_status where lower(name) in %(marital_states)s)',34 'select id from hr_employee where '+
25 {'marital_states': tuple([v.lower() for v in marital_states.itervalues()]+[k.lower() for k in marital_states.iterkeys()])})35 openupgrade.get_legacy_name('marital')+' is not null and '+
36 openupgrade.get_legacy_name('marital')+' not in '+
37 '(select id from '+
38 openupgrade.get_legacy_name('hr_employee_marital_status')+
39 ' where lower(name) in %(marital_states)s)',
40 {
41 'marital_states':
42 tuple(
43 [v.lower() for v in marital_states.itervalues()]+
44 [k.lower() for k in marital_states.iterkeys()])
45 })
26 if cr.rowcount:46 if cr.rowcount:
27 logger.warning('not all values of hr_employee_marital_status are in the selection. review hr_employee ids %s', [row[0] for row in cr.fetchall()])47 logger.warning('not all values of hr_employee_marital_status are in '+
48 'the selection. review hr_employee ids %s',
49 [row[0] for row in cr.fetchall()])
28 else:50 else:
29 logger.info('all values of hr_employee_marital_status are in the selection')51 logger.info('all values of hr_employee_marital_status are in the selection')
30 openupgrade.drop_columns(cr, [('hr_employee', 'openupgrade_legacy_marital')])52 openupgrade.drop_columns(
31 cr.execute('drop table openupgrade_legacy_hr_employee_marital_status')53 cr,
54 [('hr_employee',
55 openupgrade.get_legacy_name('marital'))])
56 cr.execute('drop table '+
57 openupgrade.get_legacy_name('hr_employee_marital_status'))
3258
33 #fields have been calculated already59 #fields have been calculated already
34 cr.execute('update hr_job set no_of_recruitment=openupgrade_legacy_expected_employees-no_of_employee')60 cr.execute(
61 'update hr_job set no_of_recruitment='+
62 openupgrade.get_legacy_name('expected_employees')+
63 '-no_of_employee')
35 #recalculate expectred employees64 #recalculate expectred employees
36 cr.execute('update hr_job set expected_employees=no_of_recruitment+no_of_employee')65 cr.execute(
37 openupgrade.drop_columns(cr, [('hr_job', 'openupgrade_legacy_expected_employees')])66 'update hr_job set expected_employees=no_of_recruitment+no_of_employee')
67 openupgrade.drop_columns(
68 cr,
69 [(
70 'hr_job',
71 openupgrade.get_legacy_name('expected_employees')
72 )])
3873
=== modified file 'hr/migrations/6.1.1.1/pre-migration.py'
--- hr/migrations/6.1.1.1/pre-migration.py 2012-06-07 13:13:15 +0000
+++ hr/migrations/6.1.1.1/pre-migration.py 2012-06-11 14:26:22 +0000
@@ -4,15 +4,15 @@
44
5@openupgrade.migrate()5@openupgrade.migrate()
6def migrate(cr, version):6def migrate(cr, version):
7 openupgrade.rename_tables(cr, [('hr_employee_marital_status', 'openupgrade_legacy_hr_employee_marital_status')])7 openupgrade.rename_tables(cr, [('hr_employee_marital_status', openupgrade.get_legacy_name('hr_employee_marital_status'))])
8 openupgrade.rename_columns(cr, 8 openupgrade.rename_columns(cr,
9 {9 {
10 'hr_employee': 10 'hr_employee':
11 [11 [
12 ('marital', 'openupgrade_legacy_marital'), 12 ('marital', openupgrade.get_legacy_name('marital')),
13 ],13 ],
14 'hr_job': 14 'hr_job':
15 [15 [
16 ('expected_employees', 'openupgrade_legacy_expected_employees')16 ('expected_employees', openupgrade.get_legacy_name('expected_employees'))
17 ],17 ],
18 })18 })
1919
=== modified file 'hr/migrations/6.1.1.1/user_notes.txt'
--- hr/migrations/6.1.1.1/user_notes.txt 2012-06-08 13:03:40 +0000
+++ hr/migrations/6.1.1.1/user_notes.txt 2012-06-11 14:26:22 +0000
@@ -1,2 +1,2 @@
1Marital status has been changed (back) to be a selection. The script tries to find a suitable selection entry from the list of marital states. This will fail if you customized this list, you'll get a warning about the employee IDs with marital states not in the selection, and find the original values in column openupgrade_legacy_marital. If you customize the selection *before* the migration with the same values used in the list of martial states, this script will pick up those values too.1Marital status has been changed (back) to be a selection. The script tries to find a suitable selection entry from the list of marital states. This will fail if you customized this list, you'll get a warning about the employee IDs with marital states not in the selection, and find the original values in column openupgrade_6_1_1_1_legacy_marital. If you customize the selection *before* the migration with the same values used in the list of martial states, this script will pick up those values too.
2If there are no unknown marital states (either because you didn't customize them or you put your customizations into the selection), the legacy column and the table will be dropped after migration.2If there are no unknown marital states (either because you didn't customize them or you put your customizations into the selection), the legacy column and the table will be dropped after migration.

Subscribers

People subscribed via source and target branches