Skip to content

[MIG] hr_recruitment module migration script - #682

Merged
pedrobaeza merged 13 commits into
OCA:9.0from
Tecnativa:9.0-mig-hr_recruitment
Dec 7, 2016
Merged

[MIG] hr_recruitment module migration script#682
pedrobaeza merged 13 commits into
OCA:9.0from
Tecnativa:9.0-mig-hr_recruitment

Conversation

@cubells

@cubells cubells commented Nov 28, 2016

Copy link
Copy Markdown
Member
  • Added analysis files
  • Created pre and post files

 * Added analisys
 * Created pre and post files
@legalsylvain

Copy link
Copy Markdown
Contributor

Hi @cubells Thanks for your work. Could you add in your PR the change of the module coverage file. (set to 'Done' hr_recrutment line.)
https://github.com/OCA/OpenUpgrade/blob/9.0/openerp/openupgrade/doc/source/modules80-90.rst

kind regards.

@legalsylvain legalsylvain added this to the 9.0 milestone Nov 28, 2016
@cubells

cubells commented Nov 28, 2016

Copy link
Copy Markdown
Member Author

Done @legalsylvain

# Nothing to do

hr_recruitment / hr.applicant / availability (integer) : type is now 'date' ('integer')
# Unable to calculate date form a integer --> Nothing to do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should take field create_date and add this number of days to get the new date.

# Done: Adapt to new range

hr_recruitment / hr.applicant / source_id (many2one) : relation is now 'utm.source' ('hr.recruitment.source')
# Nothing to do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to create an utm.source for each of the existing hr.recruitment.source, as now the object inherits (via delegation) of this object, and fill the corresponding field:

cr.execute('INSERT INTO utm_source ... RETURNING id')
new_id = cr.fetchone()
cr.execute('UPDATE hr_applicant SET source_id = %s WHERE id = %s', (new_id, old_id))
```

]}


def migrate_applicant_source(cr):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do this on post-migration, as utm.source doesn't have yet the new structure.

cr,
openupgrade.get_legacy_name('priority'),
'priority',
[('4', '3'), ('3', '1'), ('2', '0'), ('1', '0')],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must change the map_values order, as this is got iterating over values, so in your current map, you will replace 4 value by 3, and next iteration, the existing 3 and the new 3 will be replaced by 1. You must reverse the mapping.

And another thing, why there's no 2 in the new mapping?

@cubells cubells Nov 30, 2016

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do that mapping:
4 is excellent and is mapped to excellent.
3 is good and is mapped to good.
All the others are mapped to normal.
Very good is not mapped.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But right now three of the old values map to the new 0 (0, 1 and 2). Is that correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, It is.

Average, Below Average and Bad are mapped to Normal because there is not another similar value.

"""
UPDATE hr_applicant SET availability = %s
WHERE id = %s
WHERE id = '%s'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do this because you're not using psycopg capability to convert types. You have to do this:

WHERE id = %s
""", (new_date, applicant[0]))

This will also prevent SQL injection possibilities: https://github.com/OCA/maintainer-tools/blob/master/CONTRIBUTING.md#no-sql-injection

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true.
thanks @pedrobaeza

for old_id in cr.fetchall():
cr.execute("INSERT INTO utm_source (name) "
"SELECT name "
"FROM hr_recruitment_source "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to rename table to avoid the removal of the significant fields in the update process

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you have to access to the migrated table name, not the new one.

@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<openerp>

@susport susport Dec 6, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove labels openerp data by odoo in v9.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an automatic file generated by https://github.com/OCA/OpenUpgrade/blob/9.0/scripts/compare_noupdate_xml_records.py, so we can leave it as is for this version and change the script for next one.

@pedrobaeza
pedrobaeza merged commit 2428a7f into OCA:9.0 Dec 7, 2016
@pedrobaeza
pedrobaeza deleted the 9.0-mig-hr_recruitment branch December 7, 2016 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants