Browse Source
[MIG] base_location: Migration to 13.0
[MIG] base_location: Migration to 13.0
* Standard procedure * Change v13 specifics * Adapt tests + correct some practices14.0
Pedro M. Baeza
5 years ago
11 changed files with 37 additions and 123 deletions
-
10base_location/README.rst
-
4base_location/__manifest__.py
-
30base_location/i18n/base_location.pot
-
66base_location/migrations/12.0.1.0.0/post-migration.py
-
15base_location/migrations/12.0.1.0.0/pre-migration.py
-
1base_location/models/res_city_zip.py
-
3base_location/models/res_company.py
-
6base_location/static/description/index.html
-
21base_location/tests/test_base_location.py
-
1base_location/views/res_city_view.xml
-
1base_location/views/res_city_zip_view.xml
@ -1,66 +0,0 @@ |
|||||
# Copyright 2018 Tecnativa - Pedro M. Baeza |
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|
||||
|
|
||||
from psycopg2.extensions import AsIs |
|
||||
from openupgradelib import openupgrade |
|
||||
|
|
||||
|
|
||||
@openupgrade.migrate() |
|
||||
def migrate(env, version): |
|
||||
column_name = openupgrade.get_legacy_name('better_zip_id') |
|
||||
openupgrade.logged_query( |
|
||||
env.cr, |
|
||||
"ALTER TABLE res_city_zip ADD %s INTEGER", (AsIs(column_name), ), |
|
||||
) |
|
||||
# Create a city for ZIPs without it |
|
||||
openupgrade.logged_query( |
|
||||
env.cr, """ |
|
||||
INSERT INTO res_city ( |
|
||||
name, state_id, country_id, |
|
||||
create_uid, create_date, write_uid, write_date |
|
||||
) |
|
||||
SELECT |
|
||||
city, state_id, country_id, |
|
||||
MIN(create_uid), MIN(create_date), MIN(write_uid), MIN(write_date) |
|
||||
FROM res_better_zip rbz |
|
||||
WHERE city_id IS NULL |
|
||||
AND rbz.country_id IS NOT NULL |
|
||||
AND rbz.name IS NOT NULL |
|
||||
GROUP BY city, state_id, country_id |
|
||||
ON CONFLICT DO NOTHING""", |
|
||||
) |
|
||||
# Update city_id in res_better_zip |
|
||||
openupgrade.logged_query( |
|
||||
env.cr, """ |
|
||||
UPDATE res_better_zip rbz |
|
||||
SET city_id = rc.id |
|
||||
FROM res_city rc |
|
||||
WHERE rc.name = rbz.city |
|
||||
AND rc.state_id = rbz.state_id |
|
||||
AND rc.country_id = rbz.country_id |
|
||||
AND rbz.city_id IS NULL""", |
|
||||
) |
|
||||
# Create records for new model |
|
||||
openupgrade.logged_query( |
|
||||
env.cr, """ |
|
||||
INSERT INTO res_city_zip ( |
|
||||
%s, name, city_id |
|
||||
) |
|
||||
SELECT |
|
||||
id, name, city_id |
|
||||
FROM res_better_zip |
|
||||
WHERE city_id IS NOT NULL |
|
||||
ON CONFLICT DO NOTHING""", |
|
||||
(AsIs(column_name), ), |
|
||||
) |
|
||||
# Recompute display name for entries inserted by SQL |
|
||||
env['res.city.zip'].search([])._compute_new_display_name() |
|
||||
# Link res.partner with corresponding new entries |
|
||||
openupgrade.logged_query( |
|
||||
env.cr, """ |
|
||||
UPDATE res_partner rp |
|
||||
SET zip_id = rcz.id |
|
||||
FROM res_city_zip rcz |
|
||||
WHERE rcz.%s = rp.%s""", |
|
||||
(AsIs(column_name), AsIs(openupgrade.get_legacy_name('zip_id')), ), |
|
||||
) |
|
@ -1,15 +0,0 @@ |
|||||
# Copyright 2018 Tecnativa - Pedro M. Baeza |
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|
||||
|
|
||||
from openupgradelib import openupgrade |
|
||||
|
|
||||
|
|
||||
@openupgrade.migrate() |
|
||||
def migrate(env, version): |
|
||||
openupgrade.rename_columns( |
|
||||
env.cr, { |
|
||||
'res_partner': [ |
|
||||
('zip_id', None), |
|
||||
] |
|
||||
} |
|
||||
) |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue