Browse Source
[IMP] base_location: Updated to v8 syntax and uses. Added filters in some views. Added two columns in respective tree views.
pull/638/head
[IMP] base_location: Updated to v8 syntax and uses. Added filters in some views. Added two columns in respective tree views.
pull/638/head
Alejandro Santana
10 years ago
committed by
Pedro M. Baeza
18 changed files with 321 additions and 285 deletions
-
20base_location/README.rst
-
6base_location/__init__.py
-
33base_location/__openerp__.py
-
82base_location/better_zip.py
-
63base_location/better_zip_view.xml
-
20base_location/company_view.xml
-
10base_location/models/__init__.py
-
67base_location/models/better_zip.py
-
39base_location/models/company.py
-
31base_location/models/partner.py
-
8base_location/models/state.py
-
30base_location/partner_view.xml
-
26base_location/state_view.xml
-
70base_location/views/better_zip_view.xml
-
21base_location/views/company_view.xml
-
27base_location/views/partner_view.xml
-
17base_location/views/res_country_view.xml
-
26base_location/views/state_view.xml
@ -0,0 +1,20 @@ |
|||||
|
Enhanced ZIP management |
||||
|
======================= |
||||
|
|
||||
|
This module introduces a better zip/npa management system. |
||||
|
|
||||
|
It enables zip, city, state and country auto-completion on partners and companies. |
||||
|
|
||||
|
Also allows different search filters. |
||||
|
|
||||
|
|
||||
|
Author |
||||
|
------ |
||||
|
|
||||
|
- Nicolas Bessi. (Copyright Camptocamp SA) |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
- Ignacio Ibeas (Acysos S.L.) |
||||
|
- Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
- Alejandro Santana <alejandrosantana@anubia.es> |
@ -1,82 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# |
|
||||
# |
|
||||
# Author: Nicolas Bessi. Copyright Camptocamp SA |
|
||||
# Contributor: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com> |
|
||||
# Ignacio Ibeas <ignacio@acysos.com> |
|
||||
# |
|
||||
# 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 openerp.osv import orm, fields |
|
||||
|
|
||||
|
|
||||
class BetterZip(orm.Model): |
|
||||
|
|
||||
" City/locations completion object" |
|
||||
|
|
||||
_name = "res.better.zip" |
|
||||
_description = __doc__ |
|
||||
_order = "priority" |
|
||||
|
|
||||
_columns = {'priority': fields.integer('Priority', deprecated=True), |
|
||||
'name': fields.char('ZIP'), |
|
||||
'city': fields.char('City', required=True), |
|
||||
'state_id': fields.many2one('res.country.state', 'State'), |
|
||||
'country_id': fields.many2one('res.country', 'Country'), |
|
||||
'code': fields.char('City Code', size=64, |
|
||||
help="The official code for the city"), |
|
||||
} |
|
||||
|
|
||||
_defaults = {'priority': 100} |
|
||||
|
|
||||
def name_get(self, cursor, uid, ids, context=None): |
|
||||
res = [] |
|
||||
for bzip in self.browse(cursor, uid, ids, context=context): |
|
||||
if bzip.name: |
|
||||
name = [bzip.name, bzip.city] |
|
||||
else: |
|
||||
name = [bzip.city] |
|
||||
if bzip.state_id: |
|
||||
name.append(bzip.state_id.name) |
|
||||
if bzip.country_id: |
|
||||
name.append(bzip.country_id.name) |
|
||||
res.append((bzip.id, ", ".join(name))) |
|
||||
return res |
|
||||
|
|
||||
def onchange_state_id(self, cr, uid, ids, state_id=False, context=None): |
|
||||
result = {} |
|
||||
if state_id: |
|
||||
state = self.pool['res.country.state'].browse( |
|
||||
cr, uid, state_id, context=context) |
|
||||
if state: |
|
||||
result['value'] = {'country_id': state.country_id.id} |
|
||||
return result |
|
||||
|
|
||||
def name_search( |
|
||||
self, cr, uid, name, args=None, operator='ilike', context=None, |
|
||||
limit=100 |
|
||||
): |
|
||||
if args is None: |
|
||||
args = [] |
|
||||
if context is None: |
|
||||
context = {} |
|
||||
ids = [] |
|
||||
if name: |
|
||||
ids = self.search( |
|
||||
cr, uid, [('name', 'ilike', name)] + args, limit=limit) |
|
||||
if not ids: |
|
||||
ids = self.search( |
|
||||
cr, uid, [('city', operator, name)] + args, limit=limit) |
|
||||
return self.name_get(cr, uid, ids, context=context) |
|
@ -1,63 +0,0 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
|
|
||||
<record model="ir.ui.view" id="better_zip_form"> |
|
||||
<field name="name">res.better.zip.form</field> |
|
||||
<field name="model">res.better.zip</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<form string="ZIP" version="7.0"> |
|
||||
<group col="4"> |
|
||||
<field name="name"/> |
|
||||
<field name="code"/> |
|
||||
<field name="city"/> |
|
||||
<field name="priority"/> |
|
||||
<field name="state_id" on_change="onchange_state_id(state_id)"/> |
|
||||
<field name="country_id"/> |
|
||||
</group> |
|
||||
</form> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record model="ir.ui.view" id="better_zip_tree"> |
|
||||
<field name="name">res.better.zip.tree</field> |
|
||||
<field name="model">res.better.zip</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<tree string="ZIP"> |
|
||||
<field name="name"/> |
|
||||
<field name="code"/> |
|
||||
<field name="city"/> |
|
||||
<field name="country_id"/> |
|
||||
<field name="priority"/> |
|
||||
</tree> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="view_better_zip_filter" model="ir.ui.view"> |
|
||||
<field name="name">res.better.zip.select</field> |
|
||||
<field name="model">res.better.zip</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<search string="Search city"> |
|
||||
<field name="name"/> |
|
||||
<field name="city"/> |
|
||||
</search> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="action_zip_tree" model="ir.actions.act_window"> |
|
||||
<field name="name">Cites/locations Management</field> |
|
||||
<field name="res_model">res.better.zip</field> |
|
||||
<field name="view_type">form</field> |
|
||||
<field name="view_mode">tree,form</field> |
|
||||
<field ref="better_zip_tree" name="view_id"/> |
|
||||
<field name="search_view_id" ref="view_better_zip_filter"/> |
|
||||
</record> |
|
||||
|
|
||||
<menuitem |
|
||||
name="Cities/Locations Management" |
|
||||
id="zip_base" |
|
||||
parent="base.menu_localisation" |
|
||||
action="action_zip_tree" |
|
||||
/> |
|
||||
</data> |
|
||||
</openerp> |
|
@ -1,20 +0,0 @@ |
|||||
<?xml version="1.0"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
<!-- Add cities to the company form --> |
|
||||
<record id="view_company_form_city" model="ir.ui.view"> |
|
||||
<field name="name">res.company.form.city</field> |
|
||||
<field name="model">res.company</field> |
|
||||
<field name="inherit_id" ref="base.view_company_form"/> |
|
||||
<field name="arch" type="xml"> |
|
||||
<field name="street2" position="after"> |
|
||||
<field name="better_zip_id" |
|
||||
options="{'create_name_field': 'city'}" |
|
||||
colspan="4" |
|
||||
on_change="on_change_city(better_zip_id)" |
|
||||
placeholder="City completion" /> |
|
||||
</field> |
|
||||
</field> |
|
||||
</record> |
|
||||
</data> |
|
||||
</openerp> |
|
@ -0,0 +1,10 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# |
||||
|
# License, author and contributors information in: |
||||
|
# __openerp__.py file at the root folder of this module. |
||||
|
# |
||||
|
|
||||
|
from . import better_zip |
||||
|
from . import partner |
||||
|
from . import state |
||||
|
from . import company |
@ -0,0 +1,67 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# |
||||
|
# |
||||
|
# Author: Nicolas Bessi. Copyright Camptocamp SA |
||||
|
# Contributor: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
# Ignacio Ibeas <ignacio@acysos.com> |
||||
|
# Alejandro Santana <alejandrosantana@anubia.es> |
||||
|
# |
||||
|
# 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 openerp import models, fields, api |
||||
|
|
||||
|
|
||||
|
class BetterZip(models.Model): |
||||
|
'''City/locations completion object''' |
||||
|
|
||||
|
_name = "res.better.zip" |
||||
|
_description = __doc__ |
||||
|
_order = "name asc" |
||||
|
|
||||
|
name = fields.Char('ZIP') |
||||
|
code = fields.Char('City Code', size=64, |
||||
|
help="The official code for the city") |
||||
|
city = fields.Char('City', required=True) |
||||
|
state_id = fields.Many2one('res.country.state', 'State') |
||||
|
country_id = fields.Many2one('res.country', 'Country') |
||||
|
|
||||
|
@api.multi |
||||
|
def name_get(self): |
||||
|
res = [] |
||||
|
for bzip in self: |
||||
|
if bzip.name: |
||||
|
name = [bzip.name, bzip.city] |
||||
|
else: |
||||
|
name = [bzip.city] |
||||
|
if bzip.state_id: |
||||
|
name.append(bzip.state_id.name) |
||||
|
if bzip.country_id: |
||||
|
name.append(bzip.country_id.name) |
||||
|
res.append((bzip.id, ", ".join(name))) |
||||
|
return res |
||||
|
|
||||
|
@api.onchange('state_id') |
||||
|
def onchange_state_id(self): |
||||
|
if self.state_id: |
||||
|
self.country_id = self.state_id.country_id |
||||
|
|
||||
|
@api.model |
||||
|
def name_search(self, name, args=None, operator='ilike', limit=100): |
||||
|
args = args or [] |
||||
|
recs = self.browse() |
||||
|
if name: |
||||
|
recs = self.search([('name', 'ilike', name)] + args, limit=limit) |
||||
|
if not recs: |
||||
|
recs = self.search([('city', operator, name)] + args, limit=limit) |
||||
|
return recs.name_get() |
@ -1,30 +0,0 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
<record id="view_partner_form" model="ir.ui.view"> |
|
||||
<field name="name">res.partner.zip_id.2</field> |
|
||||
<field name="model">res.partner</field> |
|
||||
<field name="inherit_id" ref="base.view_partner_form"/> |
|
||||
<field name="arch" type="xml"> |
|
||||
<div class="address_format" position="before"> |
|
||||
<field name="zip_id" |
|
||||
options="{'create_name_field': 'city'}" |
|
||||
on_change="onchange_zip_id(zip_id)" |
|
||||
placeholder="City completion" |
|
||||
attrs="{'invisible': [('use_parent_address','=',True)]}" |
|
||||
class="oe_edit_only" |
|
||||
/> |
|
||||
</div> |
|
||||
<xpath expr="//field[@name='child_ids']/form//div[@class='address_format']" position="before"> |
|
||||
<field name="zip_id" |
|
||||
options="{'create_name_field': 'city'}" |
|
||||
on_change="onchange_zip_id(zip_id)" |
|
||||
placeholder="City completion" |
|
||||
attrs="{'invisible': [('use_parent_address','=',True)]}" |
|
||||
class="oe_edit_only" |
|
||||
/> |
|
||||
</xpath> |
|
||||
</field> |
|
||||
</record> |
|
||||
</data> |
|
||||
</openerp> |
|
@ -1,26 +0,0 @@ |
|||||
<?xml version="1.0"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
<!-- Add cities to the State form --> |
|
||||
<record model="ir.ui.view" id="view_country_state_form2"> |
|
||||
<field name="name">view_country_state_form2</field> |
|
||||
<field name="model">res.country.state</field> |
|
||||
<field name="inherit_id" ref="base.view_country_state_form"/> |
|
||||
<field name="arch" type="xml"> |
|
||||
<field name="country_id" position="after"> |
|
||||
<field name="better_zip_ids" |
|
||||
context="{'country_id': country_id}" |
|
||||
colspan="4" |
|
||||
nolabel="1"> |
|
||||
<tree editable="top"> |
|
||||
<field name="name"/> |
|
||||
<field name="code"/> |
|
||||
<field name="city"/> |
|
||||
<field name="country_id"/> |
|
||||
</tree> |
|
||||
</field> |
|
||||
</field> |
|
||||
</field> |
|
||||
</record> |
|
||||
</data> |
|
||||
</openerp> |
|
@ -0,0 +1,70 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record model="ir.ui.view" id="better_zip_form"> |
||||
|
<field name="name">res.better.zip.form</field> |
||||
|
<field name="model">res.better.zip</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="ZIP" version="7.0"> |
||||
|
<group col="4"> |
||||
|
<field name="name"/> |
||||
|
<field name="code"/> |
||||
|
<field name="city"/> |
||||
|
<field name="state_id"/> |
||||
|
<field name="country_id"/> |
||||
|
</group> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record model="ir.ui.view" id="better_zip_tree"> |
||||
|
<field name="name">res.better.zip.tree</field> |
||||
|
<field name="model">res.better.zip</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree string="ZIP"> |
||||
|
<field name="name"/> |
||||
|
<field name="code"/> |
||||
|
<field name="city"/> |
||||
|
<field name="state_id"/> |
||||
|
<field name="country_id"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="view_better_zip_filter" model="ir.ui.view"> |
||||
|
<field name="name">res.better.zip.select</field> |
||||
|
<field name="model">res.better.zip</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<search string="Search city"> |
||||
|
<field name="name"/> |
||||
|
<field name="code"/> |
||||
|
<field name="city"/> |
||||
|
<field name="state_id"/> |
||||
|
<field name="country_id"/> |
||||
|
<group expand="0" string="Group By"> |
||||
|
<filter string="State" domain="[]" context="{'group_by':'state_id'}"/> |
||||
|
<filter string="Country" domain="[]" context="{'group_by':'country_id'}"/> |
||||
|
</group> |
||||
|
</search> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="action_zip_tree" model="ir.actions.act_window"> |
||||
|
<field name="name">Cites/locations Management</field> |
||||
|
<field name="res_model">res.better.zip</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">tree,form</field> |
||||
|
<field ref="better_zip_tree" name="view_id"/> |
||||
|
<field name="search_view_id" ref="view_better_zip_filter"/> |
||||
|
</record> |
||||
|
|
||||
|
<menuitem |
||||
|
name="Cities/Locations Management" |
||||
|
id="zip_base" |
||||
|
parent="base.menu_localisation" |
||||
|
action="action_zip_tree" |
||||
|
/> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,21 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<!-- Add cities to the company form --> |
||||
|
<record id="view_company_form_city" model="ir.ui.view"> |
||||
|
<field name="name">res.company.form.city</field> |
||||
|
<field name="model">res.company</field> |
||||
|
<field name="inherit_id" ref="base.view_company_form" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="street2" position="after"> |
||||
|
<field name="better_zip_id" |
||||
|
options="{'create_name_field': 'city'}" |
||||
|
colspan="4" |
||||
|
placeholder="City completion" /> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,27 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record id="view_partner_form" model="ir.ui.view"> |
||||
|
<field name="name">res.partner.zip_id.2</field> |
||||
|
<field name="model">res.partner</field> |
||||
|
<field name="inherit_id" ref="base.view_partner_form" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<div class="address_format" position="before"> |
||||
|
<field name="zip_id" |
||||
|
options="{'create_name_field': 'city'}" |
||||
|
placeholder="City completion" |
||||
|
attrs="{'invisible': [('use_parent_address','=',True)]}" |
||||
|
class="oe_edit_only" /> |
||||
|
</div> |
||||
|
<xpath expr="//field[@name='child_ids']/form//div[@class='address_format']" position="before"> |
||||
|
<field name="zip_id" options="{'create_name_field': 'city'}" |
||||
|
placeholder="City completion" |
||||
|
attrs="{'invisible': [('use_parent_address','=',True)]}" |
||||
|
class="oe_edit_only" /> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record id="view_country_search" model="ir.ui.view"> |
||||
|
<field name="name">res.country.search</field> |
||||
|
<field name="model">res.country</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<search string="Country"> |
||||
|
<field name="name"/> |
||||
|
<field name="code"/> |
||||
|
</search> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,26 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<!-- Add cities to the State form --> |
||||
|
<record model="ir.ui.view" id="view_country_state_form2"> |
||||
|
<field name="name">view_country_state_form2</field> |
||||
|
<field name="model">res.country.state</field> |
||||
|
<field name="inherit_id" ref="base.view_country_state_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="country_id" position="after"> |
||||
|
<field name="better_zip_ids" |
||||
|
context="{'country_id': country_id}" |
||||
|
colspan="4" |
||||
|
nolabel="1"> |
||||
|
<tree editable="top"> |
||||
|
<field name="name"/> |
||||
|
<field name="code"/> |
||||
|
<field name="city"/> |
||||
|
<field name="country_id"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue