From 25a729e96a91e1df32849cef341ddcf86beedb0d Mon Sep 17 00:00:00 2001 From: Andrea Stirpe Date: Mon, 7 Nov 2016 12:20:38 +0100 Subject: [PATCH] [MIG][10.0] Porting partner_street_number to V10 (#314) --- partner_street_number/README.rst | 32 +++++++++- partner_street_number/__init__.py | 24 +------- partner_street_number/__manifest__.py | 22 +++---- partner_street_number/hooks.py | 25 ++++++++ partner_street_number/i18n/es.po | 2 +- partner_street_number/i18n/nl.po | 2 +- .../i18n/partner_street_number.pot | 46 --------------- partner_street_number/i18n/pt_BR.po | 2 +- partner_street_number/i18n/sl.po | 2 +- partner_street_number/models/res_partner.py | 33 ++++++----- .../static/src/css/field.less | 26 ++++++++ partner_street_number/tests/__init__.py | 5 ++ .../tests/test_res_partner.py | 23 ++++++++ partner_street_number/views/assets.xml | 10 ++++ partner_street_number/views/res_partner.xml | 59 ++++++++++++------- 15 files changed, 191 insertions(+), 122 deletions(-) create mode 100644 partner_street_number/hooks.py delete mode 100644 partner_street_number/i18n/partner_street_number.pot create mode 100644 partner_street_number/static/src/css/field.less create mode 100644 partner_street_number/tests/__init__.py create mode 100644 partner_street_number/tests/test_res_partner.py create mode 100644 partner_street_number/views/assets.xml diff --git a/partner_street_number/README.rst b/partner_street_number/README.rst index 684f943a9..c8425226a 100644 --- a/partner_street_number/README.rst +++ b/partner_street_number/README.rst @@ -1,6 +1,8 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +============================ Split street name and number ============================ @@ -16,7 +18,7 @@ Changes to the Odoo datamodel Compatibility ============= -This module is compatible with OpenERP 8.0. +This module is compatible with Odoo 10.0. Installation @@ -25,6 +27,31 @@ Installation Upon installation, the module will do a simple migration of existing values in the street column to split up the street name and number. +Usage +===== + +To use this module, you need to: + +#. Open a partner form +#. Fill fields street name and number + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/134/10.0 + +Known issues / Roadmap +====================== + +* Add more unit tests + +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. + Credits ======= @@ -34,6 +61,7 @@ Contributors * Stefan Rijnhart * Ronald Portier * Pedro M. Baeza +* Andrea Stirpe Icon ---- diff --git a/partner_street_number/__init__.py b/partner_street_number/__init__.py index 55fd67147..cf7b68e44 100644 --- a/partner_street_number/__init__.py +++ b/partner_street_number/__init__.py @@ -18,26 +18,6 @@ # along with this program. If not, see . # ############################################################################## -from . import models - -import logging -from openerp import SUPERUSER_ID - -def post_init_hook(cr, registry): - """ - Post-install script. Because 'street' is now a stored function field, we - should be able to retrieve its values from the cursor. We use those to - fill the new name/number fields using the street field's inverse function, - which does a basic street name/number split. - """ - logging.getLogger('openerp.addons.partner_street_number').info( - 'Migrating existing street names') - cr.execute( - 'SELECT id, street FROM res_partner ' - 'WHERE street IS NOT NULL and street_name IS NULL' - ) - partner_obj = registry['res.partner'] - for partner in cr.fetchall(): - partner_obj.write( - cr, SUPERUSER_ID, partner[0], {'street': partner[1]}) +from . import models +from .hooks import post_init_hook diff --git a/partner_street_number/__manifest__.py b/partner_street_number/__manifest__.py index e6fdebe85..f99b0b586 100644 --- a/partner_street_number/__manifest__.py +++ b/partner_street_number/__manifest__.py @@ -19,19 +19,21 @@ # ############################################################################## { - "name": "Street name and number", - "summary": "Introduces separate fields for street name and street number.", - "version": "8.0.0.1.0", - "author": "Therp BV,Odoo Community Association (OCA)", - "website": "https://github.com/oca/partner-contact", - "category": 'Tools', - "depends": [ - 'base' + 'name': 'Street name and number', + 'summary': 'Introduces separate fields for street name and street number.', + 'version': '10.0.1.0.0', + 'author': 'Therp BV,Odoo Community Association (OCA)', + 'website': 'https://github.com/oca/partner-contact', + 'category': 'Tools', + 'depends': [ + 'base', + 'web', ], - "data": [ + 'data': [ 'views/res_partner.xml', + 'views/assets.xml', ], - 'installable': False, + 'installable': True, 'license': 'AGPL-3', 'post_init_hook': 'post_init_hook', } diff --git a/partner_street_number/hooks.py b/partner_street_number/hooks.py new file mode 100644 index 000000000..80ddc871a --- /dev/null +++ b/partner_street_number/hooks.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Copyright 2013-2015 Therp BV () +# Copyright 2016 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging +from odoo import SUPERUSER_ID, api + + +def post_init_hook(cr, registry): + """ + Post-install script. Because 'street' is now a stored function field, we + should be able to retrieve its values from the cursor. We use those to + fill the new name/number fields using the street field's inverse function, + which does a basic street name/number split. + """ + logging.getLogger('odoo.addons.partner_street_number').info( + 'Migrating existing street names') + + env = api.Environment(cr, SUPERUSER_ID, {}) + partners = env['res.partner'].with_context(active_test=False).search([ + ('street', '!=', False), + ('street_name', '=', False) + ]) + partners._write_street() diff --git a/partner_street_number/i18n/es.po b/partner_street_number/i18n/es.po index baac3abb1..e8c04bd83 100644 --- a/partner_street_number/i18n/es.po +++ b/partner_street_number/i18n/es.po @@ -5,7 +5,7 @@ # Translators: msgid "" msgstr "" -"Project-Id-Version: partner-contact (8.0)\n" +"Project-Id-Version: partner-contact (10.0)\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-10-09 15:48+0000\n" "PO-Revision-Date: 2015-10-06 13:57+0000\n" diff --git a/partner_street_number/i18n/nl.po b/partner_street_number/i18n/nl.po index 0cb2df6a1..3e9bdb270 100644 --- a/partner_street_number/i18n/nl.po +++ b/partner_street_number/i18n/nl.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-03-12 22:26+0000\n" "PO-Revision-Date: 2015-03-12 22:26+0000\n" diff --git a/partner_street_number/i18n/partner_street_number.pot b/partner_street_number/i18n/partner_street_number.pot deleted file mode 100644 index 8a8554a89..000000000 --- a/partner_street_number/i18n/partner_street_number.pot +++ /dev/null @@ -1,46 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * partner_street_number -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-03-12 22:26+0000\n" -"PO-Revision-Date: 2015-03-12 22:26+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: partner_street_number -#: view:res.partner:partner_street_number.view_partner_form -msgid "Number..." -msgstr "" - -#. module: partner_street_number -#: model:ir.model,name:partner_street_number.model_res_partner -msgid "Partner" -msgstr "" - -#. module: partner_street_number -#: field:res.partner,street_name:0 -msgid "Street name" -msgstr "" - -#. module: partner_street_number -#: field:res.partner,street_number:0 -msgid "Street number" -msgstr "" - -#. module: partner_street_number -#: view:res.partner:partner_street_number.view_partner_form -msgid "Street..." -msgstr "" - -#. module: partner_street_number -#: view:res.partner:partner_street_number.view_partner_form -msgid "{'default_parent_id': active_id, 'default_street_name': street_name, 'default_street_number': street_number, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_use_parent_address': True}" -msgstr "" diff --git a/partner_street_number/i18n/pt_BR.po b/partner_street_number/i18n/pt_BR.po index 150e38358..ea767b419 100644 --- a/partner_street_number/i18n/pt_BR.po +++ b/partner_street_number/i18n/pt_BR.po @@ -6,7 +6,7 @@ # danimaribeiro , 2015 msgid "" msgstr "" -"Project-Id-Version: partner-contact (8.0)\n" +"Project-Id-Version: partner-contact (10.0)\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-08-28 15:54+0000\n" "PO-Revision-Date: 2015-07-22 18:41+0000\n" diff --git a/partner_street_number/i18n/sl.po b/partner_street_number/i18n/sl.po index 02d10c647..038cb300c 100644 --- a/partner_street_number/i18n/sl.po +++ b/partner_street_number/i18n/sl.po @@ -6,7 +6,7 @@ # Matjaž Mozetič , 2015 msgid "" msgstr "" -"Project-Id-Version: partner-contact (8.0)\n" +"Project-Id-Version: partner-contact (10.0)\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-08-28 15:54+0000\n" "PO-Revision-Date: 2015-05-28 07:17+0000\n" diff --git a/partner_street_number/models/res_partner.py b/partner_street_number/models/res_partner.py index b28f44d2a..5401beca2 100644 --- a/partner_street_number/models/res_partner.py +++ b/partner_street_number/models/res_partner.py @@ -22,17 +22,18 @@ ############################################################################## import re -from openerp import models, fields, api +from odoo import models, fields, api class ResPartner(models.Model): _inherit = 'res.partner' - @api.one + @api.multi @api.depends('street_name', 'street_number') def _get_street(self): - self.street = ' '.join( - filter(None, [self.street_name, self.street_number])) + for partner in self: + partner.street = ' '.join( + filter(None, [partner.street_name, partner.street_number])) def _write_street(self): """ @@ -41,26 +42,26 @@ class ResPartner(models.Model): us with a way of easily restoring the data when this module is installed on a database that already contains addresses). """ - street_name = self.street and self.street.strip() or False - street_number = False - if self.street: - match = re.search(r'(.+)\s+(\d.*)', self.street.strip()) - if match and len(match.group(2)) < 6: - street_name = match.group(1) - street_number = match.group(2) for partner in self: - self.street_name = street_name - self.street_number = street_number + street_name = partner.street.strip() if partner.street else False + street_number = False + if street_name: + match = re.search(r'(.+)\s+(\d.*)', street_name) + if match and len(match.group(2)) < 6: + street_name = match.group(1) + street_number = match.group(2) + partner.street_name = street_name + partner.street_number = street_number - @api.model - def _display_address(self, address, without_company=False): + @api.multi + def _display_address(self, without_company=False): """ Inject a context key to prevent the 'street' name to be deleted from the result of _address_fields when called from the super. """ return super(ResPartner, self.with_context(display_address=True)).\ - _display_address(address, without_company=without_company) + _display_address(without_company=without_company) @api.model def _address_fields(self): diff --git a/partner_street_number/static/src/css/field.less b/partner_street_number/static/src/css/field.less new file mode 100644 index 000000000..520b1f50e --- /dev/null +++ b/partner_street_number/static/src/css/field.less @@ -0,0 +1,26 @@ +.o_form_view { + + &.o_form_editable .o_address_format { + input.o_address_street_name { + float: left; + margin-right: 2%; + width: 73%; + } + + input.o_address_street_number { + margin-right: 0%; + width: 25%; + } + } + + .o_address_format { + span.o_address_street_name { + float: left; + margin-right: 2%; + } + + span.o_address_street_number { + margin-right: 2%; + } + } +} diff --git a/partner_street_number/tests/__init__.py b/partner_street_number/tests/__init__.py new file mode 100644 index 000000000..fb7eea981 --- /dev/null +++ b/partner_street_number/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 ONESTEiN BV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_res_partner diff --git a/partner_street_number/tests/test_res_partner.py b/partner_street_number/tests/test_res_partner.py new file mode 100644 index 000000000..d85f9a3f7 --- /dev/null +++ b/partner_street_number/tests/test_res_partner.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2016 ONESTEiN BV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestResPartner(TransactionCase): + + def setUp(self): + super(TestResPartner, self).setUp() + self.main_partner = self.env.ref('base.main_partner') + + def test_display_address(self): + # method name_get() having show_address=True in context + # will invoke method _display_address() + partner_test = self.main_partner.with_context(show_address=True) + displayed_name = partner_test.name_get() + + self.assertEqual( + displayed_name[0][1], + 'YourCompany\n1725 Slough Ave.\nScranton PA 18540\nUnited States' + ) diff --git a/partner_street_number/views/assets.xml b/partner_street_number/views/assets.xml new file mode 100644 index 000000000..b02cb0ff4 --- /dev/null +++ b/partner_street_number/views/assets.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/partner_street_number/views/res_partner.xml b/partner_street_number/views/res_partner.xml index 148b0f8c6..06609a13e 100644 --- a/partner_street_number/views/res_partner.xml +++ b/partner_street_number/views/res_partner.xml @@ -1,52 +1,67 @@ - - + Add separate fields for street name and number res.partner - - -
- - -
- 1 - -
- - -
- 1 - {'default_parent_id': active_id, 'default_street_name': street_name, 'default_street_number': street_number, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_use_parent_address': True} + {'default_parent_id': active_id, 'default_street_name': street_name, 'default_street_number': street_number, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer}
-
-
+ + + Add separate fields for street name and number in address form + res.partner + + + + + + + + 1 + + + + +