From 1da1248a24a55cc7312912ee97c9c0606fa600e4 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 30 Sep 2019 16:00:32 +0200 Subject: [PATCH] [MIG] base_location: Migration to 13.0 * Standard procedure * Change v13 specifics * Adapt tests + correct some practices --- base_location/README.rst | 10 +-- base_location/__manifest__.py | 4 +- base_location/i18n/base_location.pot | 32 +++++---- .../migrations/12.0.1.0.0/post-migration.py | 66 ------------------- .../migrations/12.0.1.0.0/pre-migration.py | 15 ----- base_location/models/res_city_zip.py | 1 - base_location/models/res_company.py | 3 +- base_location/static/description/index.html | 6 +- base_location/tests/test_base_location.py | 21 ++---- base_location/views/res_city_view.xml | 1 - base_location/views/res_city_zip_view.xml | 1 - 11 files changed, 37 insertions(+), 123 deletions(-) delete mode 100644 base_location/migrations/12.0.1.0.0/post-migration.py delete mode 100644 base_location/migrations/12.0.1.0.0/pre-migration.py diff --git a/base_location/README.rst b/base_location/README.rst index 33b6fe83c..1f7304658 100644 --- a/base_location/README.rst +++ b/base_location/README.rst @@ -14,13 +14,13 @@ Location management (aka Better ZIP) :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github - :target: https://github.com/OCA/partner-contact/tree/12.0/base_location + :target: https://github.com/OCA/partner-contact/tree/13.0/base_location :alt: OCA/partner-contact .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-base_location + :target: https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-base_location :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/134/12.0 + :target: https://runbot.odoo-community.org/runbot/134/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -63,7 +63,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -110,6 +110,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/partner-contact `_ project on GitHub. +This module is part of the `OCA/partner-contact `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_location/__manifest__.py b/base_location/__manifest__.py index e01879bc9..9f26154e6 100644 --- a/base_location/__manifest__.py +++ b/base_location/__manifest__.py @@ -1,10 +1,10 @@ # Copyright 2016 Nicolas Bessi, Camptocamp SA -# Copyright 2018 Tecnativa - Pedro M. Baeza +# Copyright 2018-2019 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Location management (aka Better ZIP)', - 'version': '12.0.1.0.1', + 'version': '13.0.1.0.0', 'depends': [ 'base_address_city', 'contacts', diff --git a/base_location/i18n/base_location.pot b/base_location/i18n/base_location.pot index f8f21bf28..5c903e607 100644 --- a/base_location/i18n/base_location.pot +++ b/base_location/i18n/base_location.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * base_location +# * base_location # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -20,7 +20,9 @@ msgstr "" #. module: base_location #: model:ir.model.fields,help:base_location.field_res_company__country_enforce_cities -msgid "Check this box to ensure every address created in that country has a 'City' chosen in the list of the country's cities." +msgid "" +"Check this box to ensure every address created in that country has a 'City' " +"chosen in the list of the country's cities." msgstr "" #. module: base_location @@ -83,7 +85,8 @@ msgstr "" #. module: base_location #: model_terms:ir.actions.act_window,help:base_location.action_res_city_full -msgid "Display and manage the list of all cities that can be assigned to\n" +msgid "" +"Display and manage the list of all cities that can be assigned to\n" " your partner records. Note that an option can be set on each country separately\n" " to enforce any address of it to have a city in this list." msgstr "" @@ -129,19 +132,19 @@ msgid "Search zip" msgstr "" #. module: base_location -#: code:addons/base_location/models/res_partner.py:69 +#: code:addons/base_location/models/res_partner.py:0 #, python-format msgid "The city of partner %s differs from that in location %s" msgstr "" #. module: base_location -#: code:addons/base_location/models/res_partner.py:65 +#: code:addons/base_location/models/res_partner.py:0 #, python-format msgid "The country of the partner %s differs from that in location %s" msgstr "" #. module: base_location -#: code:addons/base_location/models/res_partner.py:61 +#: code:addons/base_location/models/res_partner.py:0 #, python-format msgid "The state of the partner %s differs from that in location %s" msgstr "" @@ -152,13 +155,17 @@ msgid "Use the city name or the zip code to search the location" msgstr "" #. module: base_location -#: sql_constraint:res.city:0 -msgid "You already have a city with that name in the same state.The city must have a unique name within it's state and it's country" +#: model:ir.model.constraint,message:base_location.constraint_res_city_name_state_country_uniq +msgid "" +"You already have a city with that name in the same state.The city must have " +"a unique name within it's state and it's country" msgstr "" #. module: base_location -#: sql_constraint:res.city.zip:0 -msgid "You already have a zip with that code in the same city. The zip code must be unique within it's city" +#: model:ir.model.constraint,message:base_location.constraint_res_city_zip_name_city_uniq +msgid "" +"You already have a zip with that code in the same city. The zip code must be" +" unique within it's city" msgstr "" #. module: base_location @@ -190,4 +197,3 @@ msgstr "" #: model:ir.model.fields,field_description:base_location.field_res_city__zip_ids msgid "Zips in this city" msgstr "" - diff --git a/base_location/migrations/12.0.1.0.0/post-migration.py b/base_location/migrations/12.0.1.0.0/post-migration.py deleted file mode 100644 index db2a67baa..000000000 --- a/base_location/migrations/12.0.1.0.0/post-migration.py +++ /dev/null @@ -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')), ), - ) diff --git a/base_location/migrations/12.0.1.0.0/pre-migration.py b/base_location/migrations/12.0.1.0.0/pre-migration.py deleted file mode 100644 index f9a069612..000000000 --- a/base_location/migrations/12.0.1.0.0/pre-migration.py +++ /dev/null @@ -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), - ] - } - ) diff --git a/base_location/models/res_city_zip.py b/base_location/models/res_city_zip.py index 12c679a96..a95fe4e74 100644 --- a/base_location/models/res_city_zip.py +++ b/base_location/models/res_city_zip.py @@ -28,7 +28,6 @@ class ResCityZip(models.Model): 'The zip code must be unique within it\'s city'), ] - @api.multi @api.depends('name', 'city_id') def _compute_new_display_name(self): for rec in self: diff --git a/base_location/models/res_company.py b/base_location/models/res_company.py index 49548920b..e398e1892 100644 --- a/base_location/models/res_company.py +++ b/base_location/models/res_company.py @@ -31,12 +31,11 @@ class ResCompany(models.Model): string='ZIP Location', compute='_compute_address', inverse='_inverse_zip_id', - oldname="better_zip_id", help='Use the city name or the zip code to search the location', ) country_enforce_cities = fields.Boolean( - related='country_id.enforce_cities' + related='partner_id.country_id.enforce_cities', ) def _get_company_address_fields(self, partner): diff --git a/base_location/static/description/index.html b/base_location/static/description/index.html index 3cb399ec6..a9ebe67bb 100644 --- a/base_location/static/description/index.html +++ b/base_location/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

This module introduces a zip model that allows you to manage locations in a better way.

The zips will allow the users to complete automatically all address-related fields by just filling the zip.

Also allows different search filters.

@@ -412,7 +412,7 @@ ul.auto-toc {

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -454,7 +454,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/partner-contact project on GitHub.

+

This module is part of the OCA/partner-contact project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/base_location/tests/test_base_location.py b/base_location/tests/test_base_location.py index 91a81c700..60b19581e 100644 --- a/base_location/tests/test_base_location.py +++ b/base_location/tests/test_base_location.py @@ -13,12 +13,12 @@ class TestBaseLocation(common.SavepointCase): @classmethod def setUpClass(cls): super().setUpClass() - country_obj = cls.env['res.country.state'] + state_obj = cls.env['res.country.state'] city_obj = cls.env['res.city'] zip_obj = cls.env['res.city.zip'] cls.partner_obj = cls.env['res.partner'] cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) - cls.state_vd = country_obj.create({ + cls.state_vd = state_obj.create({ 'name': 'Vaud', 'code': 'VD', 'country_id': cls.env.ref('base.ch').id, @@ -28,12 +28,12 @@ class TestBaseLocation(common.SavepointCase): }) cls.company = cls.env.ref('base.main_company') - cls.state_bcn = country_obj.create({ + cls.state_bcn = state_obj.create({ 'name': 'Barcelona', 'code': '08', 'country_id': cls.env.ref('base.es').id, }) - cls.state_madrid = country_obj.create({ + cls.state_madrid = state_obj.create({ 'name': 'Madrid', 'code': '28', 'country_id': cls.env.ref('base.es').id, @@ -67,7 +67,6 @@ class TestBaseLocation(common.SavepointCase): partner1 = self.partner_obj.new({ 'name': 'Camptocamp', }) - self.barcelona.city_id.country_id.enforce_cities = True partner1.zip_id = self.barcelona partner1._onchange_zip_id() self.assertEqual(partner1.zip, self.barcelona.name) @@ -107,14 +106,10 @@ class TestBaseLocation(common.SavepointCase): def test_company_address_fields_inverse(self): """Test inverse fields from res.company""" - company = self.env['res.company'].new({ + company = self.env['res.company'].create({ 'name': 'Test', - 'partner_id': self.partner_obj.new({}).id - # Partner must be initiated in order to be filled - }) - company.update({ - 'zip_id': self.barcelona.id, }) + company.zip_id = self.barcelona.id company._inverse_city_id() company._inverse_zip_id() self.assertEqual(company.zip_id, company.partner_id.zip_id) @@ -179,13 +174,11 @@ class TestBaseLocation(common.SavepointCase): def test_partner_onchange_country(self): """Test partner onchange country_id""" - country_es = self.env.ref('base.es') - country_es.enforce_cities = True partner = self.partner_obj.new({ 'name': 'TEST', 'zip_id': self.lausanne.id }) - partner.country_id = country_es + partner.country_id = self.env.ref('base.es') partner._onchange_country_id() self.assertFalse(partner.zip_id) diff --git a/base_location/views/res_city_view.xml b/base_location/views/res_city_view.xml index 5ad6fb9aa..f138e1c09 100644 --- a/base_location/views/res_city_view.xml +++ b/base_location/views/res_city_view.xml @@ -39,7 +39,6 @@ Cities ir.actions.act_window res.city - form tree,form Locations res.city.zip - form tree,form