Browse Source

[PRT] partner_street_number 8.0

pull/96/head
Stefan Rijnhart 10 years ago
parent
commit
187ebf0562
  1. 48
      partner_street_number/README.rst
  2. 44
      partner_street_number/__init__.py
  3. 28
      partner_street_number/__openerp__.py
  4. 39
      partner_street_number/i18n/nl.po
  5. 43
      partner_street_number/i18n/partner_street_number.pot
  6. 46
      partner_street_number/migrations/0.1/post-migrate.py
  7. 0
      partner_street_number/models/__init__.py
  8. 87
      partner_street_number/models/res_partner.py
  9. BIN
      partner_street_number/static/description/icon.png
  10. 4
      partner_street_number/views/res_partner.xml

48
partner_street_number/README.rst

@ -0,0 +1,48 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License
Split street name and number
============================
This module introduces separate fields for street name and street number.
Changes to the Odoo datamodel
=============================
- Introduce two new fields for street name and number
- Keep 'Street' field as a function field to return street name + number
- Data written to the 'Street' field will be parsed into street name and number
if possible. This will be performed upon installation of the module for
existing partners.
Compatibility
=============
This module is compatible with OpenERP 8.0.
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.
Credits
=======
Contributors
------------
* Stefan Rijnhart <stefan@therp.nl>
* Ronald Portier <ronald@therp.nl>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit http://odoo-community.org.

44
partner_street_number/__init__.py

@ -1 +1,43 @@
from . import model
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2013-2015 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# 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]})

28
partner_street_number/__openerp__.py

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013-2014 Therp BV (<http://therp.nl>).
# Odoo, an open source suite of business apps
# This module copyright (C) 2013-2015 Therp BV (<http://therp.nl>).
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -19,31 +19,19 @@
# #
############################################################################## ##############################################################################
{ {
"name": "Split street name and number",
"name": "Street name and number",
"summary": "Introduces separate fields for street name and street number.",
"version": "0.1", "version": "0.1",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"website": "https://github.com/oca/partner-contact",
"category": 'Tools', "category": 'Tools',
"description": """
This module introduces separate fields for street name and street number.
Changes to the OpenERP datamodel
================================
- Introduce two new fields for street name and number
- Keep 'Street' field as a function field to return street name + number
- Data written to the 'Street' field will be parsed into street name and number
if possible. This will be performed upon installation of the module for
existing partners.
Compatibility
=============
This module is compatible with OpenERP 7.0.
""",
"depends": [ "depends": [
'base' 'base'
], ],
"data": [ "data": [
'view/res_partner.xml',
'views/res_partner.xml',
], ],
'installable': True, 'installable': True,
'license': 'AGPL-3',
'post_init_hook': 'post_init_hook',
} }

39
partner_street_number/i18n/nl.po

@ -1,13 +1,13 @@
# Translation of OpenERP Server.
# Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * partner_street_number
# * partner_street_number
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-12-07 13:50+0000\n"
"PO-Revision-Date: 2013-12-07 13:50+0000\n"
"POT-Creation-Date: 2015-03-12 22:26+0000\n"
"PO-Revision-Date: 2015-03-12 22:26+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -15,6 +15,16 @@ msgstr ""
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: partner_street_number
#: view:res.partner:partner_street_number.view_partner_form
msgid "Number..."
msgstr "Nummer..."
#. module: partner_street_number
#: model:ir.model,name:partner_street_number.model_res_partner
msgid "Partner"
msgstr "Relatie"
#. module: partner_street_number #. module: partner_street_number
#: field:res.partner,street_name:0 #: field:res.partner,street_name:0
msgid "Street name" msgid "Street name"
@ -26,22 +36,11 @@ msgid "Street number"
msgstr "Huisnummer" msgstr "Huisnummer"
#. module: partner_street_number #. module: partner_street_number
#: view:res.partner:0
msgid "Number..."
msgstr "Nummer..."
#. module: partner_street_number
#: view:res.partner:0
#: view:res.partner:partner_street_number.view_partner_form
msgid "Street..." msgid "Street..."
msgstr "Straat..." msgstr "Straat..."
#. module: partner_street_number #. module: partner_street_number
#: view:res.partner:0
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}"
msgstr "{'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}"
#. module: partner_street_number
#: model:ir.model,name:partner_street_number.model_res_partner
msgid "Partner"
msgstr "Relatie"
#: 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 ""

43
partner_street_number/i18n/partner_street_number.pot

@ -1,41 +1,46 @@
# Translation of OpenERP Server.
# Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * partner_street_number
# * partner_street_number
# #
msgid "" msgid ""
msgstr "" 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 #. module: partner_street_number
#: field:res.partner,street_name:0
msgid "Street name"
#: view:res.partner:partner_street_number.view_partner_form
msgid "Number..."
msgstr "" msgstr ""
#. module: partner_street_number #. module: partner_street_number
#: field:res.partner,street_number:0
msgid "Street number"
#: model:ir.model,name:partner_street_number.model_res_partner
msgid "Partner"
msgstr "" msgstr ""
#. module: partner_street_number #. module: partner_street_number
#: view:res.partner:0
msgid "Number..."
#: field:res.partner,street_name:0
msgid "Street name"
msgstr "" msgstr ""
#. module: partner_street_number #. module: partner_street_number
#: view:res.partner:0
msgid "Street..."
#: field:res.partner,street_number:0
msgid "Street number"
msgstr "" msgstr ""
#. module: partner_street_number #. module: partner_street_number
#: view:res.partner:0
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}"
#: view:res.partner:partner_street_number.view_partner_form
msgid "Street..."
msgstr "" msgstr ""
#. module: partner_street_number #. module: partner_street_number
#: model:ir.model,name:partner_street_number.model_res_partner
msgid "Partner"
#: 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 "" msgstr ""

46
partner_street_number/migrations/0.1/post-migrate.py

@ -1,46 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013-2014 Therp BV (<http://therp.nl>).
#
# @autors: Stefan Rijnhart, Ronald Portier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
from openerp import pooler, SUPERUSER_ID
def migrate(cr, version):
"""
Post-install script. If version is not set, we are called at installation
time. 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.
"""
if version:
return
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 = pooler.get_pool(cr.dbname)['res.partner']
for partner in cr.fetchall():
partner_obj.write(
cr, SUPERUSER_ID, partner[0], {'street': partner[1]})

0
partner_street_number/model/__init__.py → partner_street_number/models/__init__.py

87
partner_street_number/model/res_partner.py → partner_street_number/models/res_partner.py

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013-2014 Therp BV (<http://therp.nl>).
# Odoo, an open source suite of business apps
# This module copyright (C) 2013-2015 Therp BV (<http://therp.nl>).
# #
# @autors: Stefan Rijnhart, Ronald Portier
# @authors: Stefan Rijnhart, Ronald Portier
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -22,64 +22,48 @@
############################################################################## ##############################################################################
import re import re
from openerp.osv import orm, fields
from openerp import models, fields, api
class ResPartner(orm.Model):
class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
def get_street(self, cr, uid, partner, context=None):
"""
Allow to override the field function's value composition
:param partner: res.partner browse record
:rtype: string
"""
return ' '.join(filter(None, [
partner.street_name,
partner.street_number,
]))
def _get_street(self, cr, uid, select, field_name, args, context=None):
""" Delegates the function field 'street' to an inheritable method"""
res = {}
for partner in self.browse(cr, uid, select, context=context):
res[partner.id] = self.get_street(
cr, uid, partner, context=context)
return res
@api.one
@api.depends('street_name', 'street_number')
def _get_street(self):
self.street = ' '.join(
filter(None, [self.street_name, self.street_number]))
def _write_street(self, cr, uid, ids, name, value, arg, context=None):
def _write_street(self):
""" """
Simplistically try to parse in case a value should get written Simplistically try to parse in case a value should get written
to the 'street' field (for instance at import time, which provides to the 'street' field (for instance at import time, which provides
us with a way of easily restoring the data when this module is us with a way of easily restoring the data when this module is
installed on a database that already contains addresses). installed on a database that already contains addresses).
""" """
street_name = value and value.strip() or False
street_name = self.street and self.street.strip() or False
street_number = False street_number = False
if value:
match = re.search(r'(.+)\s+(\d.*)', value.strip())
if self.street:
match = re.search(r'(.+)\s+(\d.*)', self.street.strip())
if match and len(match.group(2)) < 6: if match and len(match.group(2)) < 6:
street_name = match.group(1) street_name = match.group(1)
street_number = match.group(2) street_number = match.group(2)
return self.write(cr, uid, ids, {
'street_name': street_name,
'street_number': street_number,
}, context=context)
for partner in self:
self.street_name = street_name
self.street_number = street_number
def _display_address(
self, cr, uid, address, without_company=False, context=None):
@api.model
def _display_address(self, address, without_company=False):
""" """
Inject a context key to prevent the 'street' name to be Inject a context key to prevent the 'street' name to be
deleted from the result of _address_fields when called from deleted from the result of _address_fields when called from
the super. the super.
""" """
local_context = dict(context or {}, display_address=True)
return super(ResPartner, self)._display_address(
cr, uid, address, without_company=without_company,
context=local_context)
return super(ResPartner, self.with_context(display_address=True)).\
_display_address(address, without_company=without_company)
def _address_fields(self, cr, uid, context=None):
@api.model
def _address_fields(self):
""" """
Pass on the fields for address synchronisation to contacts. Pass on the fields for address synchronisation to contacts.
@ -100,25 +84,14 @@ class ResPartner(orm.Model):
lead to silent data corruption should the synchronisation API lead to silent data corruption should the synchronisation API
ever change. ever change.
""" """
res = super(ResPartner, self)._address_fields(cr, uid, context=context)
res = super(ResPartner, self)._address_fields()
if 'street' in res and not ( if 'street' in res and not (
context and context.get('display_address')):
self._context.get('display_address')):
res.remove('street') res.remove('street')
return res + ['street_name', 'street_number'] return res + ['street_name', 'street_number']
_columns = {
'street_name': fields.char(
'Street name', size=118),
'street_number': fields.char(
'Street number', size=10),
'street': fields.function(
_get_street, fnct_inv=_write_street,
type='char', string="Street",
# Must be stored as per https://bugs.launchpad.net/bugs/1253200
store={
'res.partner': (
lambda self, cr, uid, ids, context=None: ids,
['street_name', 'street_number'], 10),
},
),
}
street_name = fields.Char('Street name')
street_number = fields.Char('Street number')
# Must be stored as per https://bugs.launchpad.net/bugs/1253200
street = fields.Char(
compute='_get_street', store=True, inverse='_write_street')

BIN
partner_street_number/static/description/icon.png

After

Width: 180  |  Height: 180  |  Size: 12 KiB

4
partner_street_number/view/res_partner.xml → partner_street_number/views/res_partner.xml

@ -27,17 +27,15 @@
<div> <div>
<field name="street_name" style="width: 80%%" <field name="street_name" style="width: 80%%"
placeholder="Street..." placeholder="Street..."
attrs="{'readonly': [('use_parent_address','=',True)]}"
/> />
<field name="street_number" style="width: 19%%" <field name="street_number" style="width: 19%%"
placeholder="Number..." placeholder="Number..."
attrs="{'readonly': [('use_parent_address','=',True)]}"
/> />
</div> </div>
</xpath> </xpath>
<xpath expr="//field[@name='child_ids']" position="attributes"> <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}</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, 'default_use_parent_address': True}</attribute>
</xpath> </xpath>
</field> </field>
Loading…
Cancel
Save