Browse Source

[MIG] base_location: Migration to 13.0

* Standard procedure
* Change v13 specifics
* Adapt tests + correct some practices
14.0
Pedro M. Baeza 5 years ago
parent
commit
1da1248a24
  1. 10
      base_location/README.rst
  2. 4
      base_location/__manifest__.py
  3. 32
      base_location/i18n/base_location.pot
  4. 66
      base_location/migrations/12.0.1.0.0/post-migration.py
  5. 15
      base_location/migrations/12.0.1.0.0/pre-migration.py
  6. 1
      base_location/models/res_city_zip.py
  7. 3
      base_location/models/res_company.py
  8. 6
      base_location/static/description/index.html
  9. 21
      base_location/tests/test_base_location.py
  10. 1
      base_location/views/res_city_view.xml
  11. 1
      base_location/views/res_city_zip_view.xml

10
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 <https://github.com/OCA/partner-contact/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 <https://github.com/OCA/partner-contact/issues/new?body=module:%20base_location%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20base_location%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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 <https://github.com/OCA/partner-contact/tree/12.0/base_location>`_ project on GitHub.
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/13.0/base_location>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

4
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',

32
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 ""

66
base_location/migrations/12.0.1.0.0/post-migration.py

@ -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')), ),
)

15
base_location/migrations/12.0.1.0.0/pre-migration.py

@ -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),
]
}
)

1
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:

3
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):

6
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. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/partner-contact/tree/12.0/base_location"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-base_location"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/134/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/partner-contact/tree/13.0/base_location"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-base_location"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/134/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module introduces a zip model that allows you to manage locations in a better way.</p>
<p>The zips will allow the users to complete automatically all address-related fields by just filling the zip.</p>
<p>Also allows different search filters.</p>
@ -412,7 +412,7 @@ ul.auto-toc {
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/partner-contact/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/partner-contact/issues/new?body=module:%20base_location%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/partner-contact/issues/new?body=module:%20base_location%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -454,7 +454,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/partner-contact/tree/12.0/base_location">OCA/partner-contact</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/partner-contact/tree/13.0/base_location">OCA/partner-contact</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

21
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)

1
base_location/views/res_city_view.xml

@ -39,7 +39,6 @@
<field name="name">Cities</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.city</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_ids"
eval="[(5,0,0),

1
base_location/views/res_city_zip_view.xml

@ -39,7 +39,6 @@
<record id="action_zip_tree" model="ir.actions.act_window">
<field name="name">Locations</field>
<field name="res_model">res.city.zip</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field ref="city_zip_tree" name="view_id"/>
<field name="search_view_id" ref="view_city_zip_filter"/>

Loading…
Cancel
Save