Browse Source

[MIG][10.0] Porting partner_street_number to V10 (#314)

pull/331/head
Andrea Stirpe 8 years ago
committed by Pedro M. Baeza
parent
commit
25a729e96a
  1. 32
      partner_street_number/README.rst
  2. 24
      partner_street_number/__init__.py
  3. 22
      partner_street_number/__manifest__.py
  4. 25
      partner_street_number/hooks.py
  5. 2
      partner_street_number/i18n/es.po
  6. 2
      partner_street_number/i18n/nl.po
  7. 46
      partner_street_number/i18n/partner_street_number.pot
  8. 2
      partner_street_number/i18n/pt_BR.po
  9. 2
      partner_street_number/i18n/sl.po
  10. 33
      partner_street_number/models/res_partner.py
  11. 26
      partner_street_number/static/src/css/field.less
  12. 5
      partner_street_number/tests/__init__.py
  13. 23
      partner_street_number/tests/test_res_partner.py
  14. 10
      partner_street_number/views/assets.xml
  15. 59
      partner_street_number/views/res_partner.xml

32
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
<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.
Credits
=======
@ -34,6 +61,7 @@ Contributors
* Stefan Rijnhart <stefan@therp.nl>
* Ronald Portier <ronald@therp.nl>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Andrea Stirpe <a.stirpe@onestein.nl>
Icon
----

24
partner_street_number/__init__.py

@ -18,26 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
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

22
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',
}

25
partner_street_number/hooks.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2013-2015 Therp BV (<http://therp.nl>)
# Copyright 2016 Onestein (<http://www.onestein.eu>)
# 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()

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

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

46
partner_street_number/i18n/partner_street_number.pot

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

2
partner_street_number/i18n/pt_BR.po

@ -6,7 +6,7 @@
# danimaribeiro <danimaribeiro@gmail.com>, 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"

2
partner_street_number/i18n/sl.po

@ -6,7 +6,7 @@
# Matjaž Mozetič <m.mozetic@matmoz.si>, 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"

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

26
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%;
}
}
}

5
partner_street_number/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 ONESTEiN BV (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_res_partner

23
partner_street_number/tests/test_res_partner.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 ONESTEiN BV (<http://www.onestein.eu>)
# 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'
)

10
partner_street_number/views/assets.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" name="partner_street_number backend assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/partner_street_number/static/src/css/field.less"/>
</xpath>
</template>
</odoo>

59
partner_street_number/views/res_partner.xml

@ -1,52 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">Add separate fields for street name and number</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet//div/field[@name='street']"
<xpath expr="//div[@class='o_address_format']//field[@name='street']"
position="after">
<div>
<field name="street_name" style="width: 80%%"
placeholder="Street..."
attrs="{'readonly': [('use_parent_address','=',True)]}"
<field name="street_name" class="o_address_street_name"
placeholder="Street..."
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"
/>
<field name="street_number" style="width: 19%%"
placeholder="Number..."
attrs="{'readonly': [('use_parent_address','=',True)]}"
<field name="street_number" class="o_address_street_number"
placeholder="Number..."
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"
/>
</div>
</xpath>
<xpath expr="/form/sheet//div/field[@name='street']"
<xpath expr="//div[@class='o_address_format']//field[@name='street']"
position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/group/div/field[@name='street']"
<xpath expr="//div[@name='div_address']//field[@name='street']"
position="after">
<div>
<field name="street_name" style="width: 80%%"
<field name="street_name" class="o_address_street_name"
placeholder="Street..."
/>
<field name="street_number" style="width: 19%%"
<field name="street_number" class="o_address_street_number"
placeholder="Number..."
/>
</div>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/group/div/field[@name='street']"
<xpath expr="//div[@name='div_address']//field[@name='street']"
position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='child_ids']" position="attributes">
<attribute name="context">{'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}</attribute>
<attribute name="context">{'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}</attribute>
</xpath>
</field>
</record>
</data>
</openerp>
<record id="view_partner_address_form" model="ir.ui.view">
<field name="name">Add separate fields for street name and number in address form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_address_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@class='o_address_format']//field[@name='street']"
position="after">
<field name="street_name" class="o_address_street_name"
placeholder="Street..."
/>
<field name="street_number" class="o_address_street_number"
placeholder="Number..."
/>
</xpath>
<xpath expr="//div[@class='o_address_format']//field[@name='street']"
position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save