Browse Source
[IMP] partner_industry_secondary: Better handling of transition to this module (#741)
pull/592/merge
[IMP] partner_industry_secondary: Better handling of transition to this module (#741)
pull/592/merge
Pedro M. Baeza
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 84 deletions
-
67partner_industry_secondary/migrations/11.0.1.0.0/post-migration.py
-
30partner_industry_secondary/migrations/11.0.1.0.0/pre-migration.py
@ -1,67 +0,0 @@ |
|||||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
||||
from openupgradelib import openupgrade |
|
||||
from psycopg2.extensions import AsIs |
|
||||
|
|
||||
|
|
||||
def fill_res_partner_industry(cr): |
|
||||
cr.execute( |
|
||||
""" |
|
||||
INSERT INTO res_partner_industry (name, active, create_uid, |
|
||||
create_date, write_uid, write_date, %s) |
|
||||
SELECT name, TRUE as active, create_uid, create_date, write_uid, |
|
||||
write_date, id |
|
||||
FROM res_partner_sector |
|
||||
""", (AsIs(openupgrade.get_legacy_name('old_sector_id')), ), |
|
||||
) |
|
||||
# corrected parent_id here: |
|
||||
cr.execute( |
|
||||
""" |
|
||||
UPDATE res_partner_industry rpi |
|
||||
SET parent_id = rpi2.id |
|
||||
FROM res_partner_sector rps |
|
||||
INNER JOIN res_partner_industry rpi2 ON rps.parent_id = rpi2.%s |
|
||||
WHERE rpi.%s = rps.id |
|
||||
""", ( |
|
||||
AsIs(openupgrade.get_legacy_name('old_sector_id')), |
|
||||
AsIs(openupgrade.get_legacy_name('old_sector_id')), |
|
||||
), |
|
||||
) |
|
||||
|
|
||||
|
|
||||
def update_res_partner_industry(cr): |
|
||||
cr.execute( |
|
||||
""" |
|
||||
UPDATE res_partner rp |
|
||||
SET industry_id = rpi.id |
|
||||
FROM res_partner_industry rpi |
|
||||
WHERE rp.%s IS NOT NULL AND rp.%s = rpi.%s |
|
||||
""", ( |
|
||||
AsIs(openupgrade.get_legacy_name('sector_id')), |
|
||||
AsIs(openupgrade.get_legacy_name('sector_id')), |
|
||||
AsIs(openupgrade.get_legacy_name('old_sector_id')), |
|
||||
), |
|
||||
) |
|
||||
|
|
||||
|
|
||||
def fill_res_partner_industry_secondary(cr): |
|
||||
cr.execute( |
|
||||
""" |
|
||||
INSERT INTO res_partner_res_partner_industry_rel (res_partner_id, |
|
||||
res_partner_industry_id) |
|
||||
SELECT rel.res_partner_id, rpi.id |
|
||||
FROM res_partner_res_partner_sector_rel rel |
|
||||
LEFT JOIN res_partner_industry rpi |
|
||||
ON rel.res_partner_sector_id = rpi.%s |
|
||||
""", (AsIs(openupgrade.get_legacy_name('old_sector_id')), ), |
|
||||
) |
|
||||
|
|
||||
|
|
||||
@openupgrade.migrate(use_env=True) |
|
||||
def migrate(env, version): |
|
||||
cr = env.cr |
|
||||
if openupgrade.table_exists(cr, 'res_partner_sector'): |
|
||||
fill_res_partner_industry(cr) |
|
||||
env['res.partner.industry']._parent_store_compute() |
|
||||
update_res_partner_industry(cr) |
|
||||
fill_res_partner_industry_secondary(cr) |
|
@ -1,27 +1,25 @@ |
|||||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
||||
|
# Copyright 2019 Tecnativa - Pedro M. Baeza |
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
from openupgradelib import openupgrade |
|
||||
from psycopg2.extensions import AsIs |
|
||||
|
|
||||
_column_renames = { |
|
||||
'res_partner': [('sector_id', None)], |
|
||||
} |
|
||||
|
from openupgradelib import openupgrade |
||||
|
|
||||
_xmlid_renames = [ |
_xmlid_renames = [ |
||||
('partner_sector.group_use_partner_sector_for_person', |
|
||||
|
('partner_industry_secondary.group_use_partner_sector_for_person', |
||||
'partner_industry_secondary.group_use_partner_industry_for_person'), |
'partner_industry_secondary.group_use_partner_industry_for_person'), |
||||
] |
] |
||||
|
|
||||
|
|
||||
@openupgrade.migrate(use_env=True) |
|
||||
|
@openupgrade.migrate() |
||||
def migrate(env, version): |
def migrate(env, version): |
||||
cr = env.cr |
|
||||
if openupgrade.table_exists(cr, 'res_partner_sector'): |
|
||||
openupgrade.rename_columns(cr, _column_renames) |
|
||||
openupgrade.rename_xmlids(cr, _xmlid_renames) |
|
||||
cr.execute( |
|
||||
""" |
|
||||
ALTER TABLE res_partner_industry |
|
||||
ADD COLUMN %s integer; |
|
||||
""", (AsIs(openupgrade.get_legacy_name('old_sector_id')), ), |
|
||||
|
openupgrade.rename_xmlids(env.cr, _xmlid_renames) |
||||
|
# No need to check existence, as if getting to this, it will exist |
||||
|
openupgrade.rename_tables( |
||||
|
env.cr, [('res_partner_res_partner_sector_rel', |
||||
|
'res_partner_res_partner_industry_rel')], |
||||
) |
) |
||||
|
openupgrade.rename_columns(env.cr, { |
||||
|
'res_partner_res_partner_industry_rel': [ |
||||
|
('res_partner_sector_id', 'res_partner_industry_id'), |
||||
|
] |
||||
|
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue