-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: https://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
========================== | ||
Romania - Address Extended | ||
========================== | ||
|
||
This module extends address field with staircase. | ||
Update country street format with the following: | ||
%(street_name)s Bl. %(street_number)s Sc. %(street_staircase)s Ap. %(street_number2)s | ||
|
||
|
||
Installation | ||
============ | ||
|
||
To install this module, you need to: | ||
|
||
* clone the branch 11.0 of the repository https://github.com/OCA/l10n-romania | ||
* add the path to this repository in your configuration (addons-path) | ||
* update the module list | ||
* search for "Romania - Address Extended" in your addons | ||
* install the module | ||
|
||
Usage | ||
===== | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/177/11.0 | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-romania/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Fekete Mihai <feketemihai@gmail.com> | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://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 https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2018 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
'name': 'Romania - Extended Addresses', | ||
'summary': 'Romania - Extended Addresses', | ||
'version': '11.0.1.0.0', | ||
'category': 'Localization', | ||
'author': 'Forest and Biomass Romania, ' | ||
'Odoo Community Association (OCA)', | ||
'website': 'https://www.forbiom.eu', | ||
'license': 'AGPL-3', | ||
'installable': True, | ||
'depends': ['base_address_extended'], | ||
'data': [ | ||
'views/res_company_view.xml', | ||
'views/res_partner_view.xml', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import res_company | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2018 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class Company(models.Model): | ||
_inherit = 'res.company' | ||
|
||
street_staircase = fields.Char('Staircase Number', | ||
compute='_compute_address', | ||
inverse='_inverse_street_staircase') | ||
|
||
def _get_company_address_fields(self, partner): | ||
address_fields = super( | ||
Company, self)._get_company_address_fields(partner) | ||
address_fields.update({ | ||
'street_staircase': partner.street_staircase, | ||
}) | ||
return address_fields | ||
|
||
def _inverse_street_staircase(self): | ||
for company in self: | ||
company.partner_id.street_staircase = company.street_staircase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Copyright 2018 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import re | ||
|
||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import UserError | ||
|
||
STREET_FIELDS = ('street_staircase',) | ||
|
||
|
||
class Partner(models.Model): | ||
_inherit = ['res.partner'] | ||
_name = 'res.partner' | ||
|
||
street_staircase = fields.Char('Staircase Number', | ||
compute='_split_street', | ||
inverse='_set_street', store=True) | ||
|
||
def get_street_fields(self): | ||
"""Returns the fields that can be used in a street format. | ||
Overwrite this function if you want to add your own fields.""" | ||
return super(Partner, self).get_street_fields() + STREET_FIELDS | ||
|
||
@api.multi | ||
def _set_street(self): | ||
"""Updates the street field. Writes the `street` field on the | ||
partners when one of the sub-fields in STREET_FIELDS | ||
has been touched""" | ||
street_fields = self.get_street_fields() | ||
for partner in self: | ||
street_format = ( | ||
partner.country_id.street_format or | ||
'%(street_number)s %(street_staircase)s %(street_number2)s ' + | ||
' %(street_name)s') | ||
previous_field = None | ||
previous_pos = 0 | ||
street_value = "" | ||
separator = "" | ||
# iter on fields in street_format, detected as '%(<field_name>)s' | ||
for re_match in re.finditer(r'%\(\w+\)s', street_format): | ||
# [2:-2] is used to remove the extra chars '%(' and ')s' | ||
field_name = re_match.group()[2:-2] | ||
field_pos = re_match.start() | ||
if field_name not in street_fields: | ||
raise UserError( | ||
_("Unrecognized field %s in street format.") % | ||
field_name) | ||
if not previous_field: | ||
# first iteration: add heading chars in street_format | ||
if partner[field_name]: | ||
street_value += \ | ||
street_format[0:field_pos] + partner[field_name] | ||
else: | ||
# get the substring between 2 fields, | ||
# to be used as separator | ||
separator = street_format[previous_pos:field_pos] | ||
if street_value and partner[field_name]: | ||
street_value += separator | ||
if partner[field_name]: | ||
street_value += partner[field_name] | ||
previous_field = field_name | ||
previous_pos = re_match.end() | ||
|
||
# add trailing chars in street_format | ||
street_value += street_format[previous_pos:] | ||
|
||
# /!\ Note that we must use a sql query to bypass the orm as | ||
# it would call _split_street() | ||
# that would try to set the fields we just modified. | ||
self._cr.execute('UPDATE res_partner SET street = %s ' | ||
'WHERE ID = %s', (street_value, partner.id)) | ||
# invalidate the cache for the field we manually set | ||
self.invalidate_cache(['street'], [partner.id]) | ||
|
||
@api.multi | ||
@api.depends('street') | ||
def _split_street(self): | ||
"""Splits street value into sub-fields. Recomputes the fields of | ||
STREET_FIELDS when `street` of a partner is updated""" | ||
street_fields = self.get_street_fields() | ||
for partner in self: | ||
if not partner.street: | ||
for field in street_fields: | ||
partner[field] = None | ||
continue | ||
|
||
street_format = ( | ||
partner.country_id.street_format or | ||
'%(street_number)s %(street_staircase)s %(street_number2)s ' + | ||
' %(street_name)s') | ||
vals = {} | ||
previous_pos = 0 | ||
street_raw = partner.street | ||
field_name = None | ||
# iter on fields in street_format, detected as '%(<field_name>)s' | ||
for re_match in re.finditer(r'%\(\w+\)s', street_format): | ||
field_pos = re_match.start() | ||
if not field_name: | ||
# first iteration: remove the heading chars | ||
street_raw = street_raw[field_pos:] | ||
|
||
# get the substring between 2 fields, to be used as separator | ||
separator = street_format[previous_pos:field_pos] | ||
field_value = None | ||
if separator and field_name: | ||
# maxsplit set to 1 to unpack only the first element | ||
# and let the rest untouched | ||
tmp = street_raw.split(separator, 1) | ||
if len(tmp) == 2: | ||
field_value, street_raw = tmp | ||
vals[field_name] = field_value | ||
if field_value or not field_name: | ||
# select next field to find (first pass OR field found) | ||
# [2:-2] is used to remove the extra chars '%(' and ')s' | ||
field_name = re_match.group()[2:-2] | ||
else: | ||
# value not found: keep looking for the same field | ||
pass | ||
if field_name not in street_fields: | ||
raise UserError( | ||
_("Unrecognized field %s in street format.") % | ||
field_name) | ||
previous_pos = re_match.end() | ||
|
||
# last field value is what remains in street_raw minus | ||
# trailing chars in street_format | ||
trailing_chars = street_format[previous_pos:] | ||
if trailing_chars and street_raw.endswith(trailing_chars): | ||
vals[field_name] = street_raw[:-len(trailing_chars)] | ||
else: | ||
vals[field_name] = street_raw | ||
# assign the values to the fields | ||
# /!\ Note that a write(vals) would cause a recursion since | ||
# it would bypass the cache | ||
for k, v in vals.items(): | ||
partner[k] = v |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="view_res_company_extended_form" model="ir.ui.view"> | ||
<field name="name">view_res_company_extended_form</field> | ||
<field name="model">res.company</field> | ||
<field name="inherit_id" ref="base_address_extended.view_res_company_extended_form"/> | ||
<field name="arch" type="xml"> | ||
<label for="street_number" position="replace"/> | ||
<label for="street_number2" position="replace"/> | ||
<field name="street_number" position="replace"> | ||
<field name="street_number" placeholder="Home Number"/> | ||
</field> | ||
<field name="street_number2" position="replace"> | ||
<field name="street_number2" placeholder="Door Number"/> | ||
</field> | ||
<xpath expr="//field[@name='street_number']" position="after"> | ||
<field name="street_staircase" placeholder="Staircase Number"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="view_partner_structured_form" model="ir.ui.view"> | ||
<field name="name">view_partner_structured_form</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base_address_extended.view_partner_structured_form"/> | ||
<field name="arch" type="xml"> | ||
<label for="street_number" position="replace"/> | ||
<label for="street_number2" position="replace"/> | ||
<field name="street_number" position="replace"> | ||
<field name="street_number" placeholder="Home Number"/> | ||
</field> | ||
<field name="street_number2" position="replace"> | ||
<field name="street_number2" placeholder="Door Number"/> | ||
</field> | ||
<xpath expr="//field[@name='street_number']" position="after"> | ||
<field name="street_staircase" placeholder="Staircase Number" attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_partner_address_structured_form" model="ir.ui.view"> | ||
<field name="name">view_partner_address_structured_form</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base_address_extended.view_partner_address_structured_form"/> | ||
<field name="arch" type="xml"> | ||
<label for="street_number" position="replace"/> | ||
<label for="street_number2" position="replace"/> | ||
<field name="street_number" position="replace"> | ||
<field name="street_number" placeholder="Home Number"/> | ||
</field> | ||
<field name="street_number2" position="replace"> | ||
<field name="street_number2" placeholder="Door Number"/> | ||
</field> | ||
<xpath expr="//field[@name='street_number']" position="after"> | ||
<field name="street_staircase" placeholder="Staircase Number" attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |