From 1c14ff1e32150a05037f0314999f6c70c7154006 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 May 2013 14:33:04 +0200 Subject: [PATCH] [IMP] porting city addons into better diff: More complexe name get and name search. Completion of country when changing state. Zip object is added on company. One2many from state to zip Security is CSV --- better_zip/__init__.py | 6 +++- better_zip/__openerp__.py | 15 +++++--- better_zip/better_zip.py | 48 ++++++++++++++++--------- better_zip/better_zip_view.xml | 14 ++------ better_zip/company.py | 44 +++++++++++++++++++++++ better_zip/company_view.xml | 19 ++++++++++ better_zip/partner.py | 39 ++++++++++++++++++++ better_zip/partner_view.xml | 17 +++++++++ better_zip/security/ir.model.access.csv | 3 ++ better_zip/security/security.xml | 13 ------- better_zip/state.py | 28 +++++++++++++++ better_zip/state_view.xml | 26 ++++++++++++++ 12 files changed, 226 insertions(+), 46 deletions(-) create mode 100644 better_zip/company.py create mode 100644 better_zip/company_view.xml create mode 100644 better_zip/partner.py create mode 100644 better_zip/partner_view.xml create mode 100644 better_zip/security/ir.model.access.csv delete mode 100644 better_zip/security/security.xml create mode 100644 better_zip/state.py create mode 100644 better_zip/state_view.xml diff --git a/better_zip/__init__.py b/better_zip/__init__.py index b2a606fbd..3433372dc 100644 --- a/better_zip/__init__.py +++ b/better_zip/__init__.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Author Nicolas Bessi. Copyright Camptocamp SA +# Author: Nicolas Bessi. Copyright Camptocamp SA +# Contributor: Pedro Manuel Baeza # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -18,3 +19,6 @@ # ############################################################################## from . import better_zip +from . import partner +from . import state +from . import company \ No newline at end of file diff --git a/better_zip/__openerp__.py b/better_zip/__openerp__.py index 678b030dc..2383a61f5 100644 --- a/better_zip/__openerp__.py +++ b/better_zip/__openerp__.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Author Nicolas Bessi. Copyright Camptocamp SA +# Author: Nicolas Bessi. Copyright Camptocamp SA +# Contributor: Pedro Manuel Baeza # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,11 +20,17 @@ ############################################################################## {'name': 'Better zip management', 'version': '0.3', - 'depends': ['base',], + 'depends': ['base'], 'author': 'Camptocamp', - 'description': """Introduce a better zip/npa management system. Enable partner completion""", + 'description': """ +Introduces a better zip/npa management system. +It enables zip/city auto-completion on partners""", 'website': 'http://www.camptocamp.com', - 'data': ['security/security.xml', 'better_zip_view.xml'], + 'data': ['better_zip_view.xml', + 'state_view.xml', + 'company_view.xml', + 'partner_view.xml', + 'security/ir.model.access.csv'], 'installable': True, 'active': False, } diff --git a/better_zip/better_zip.py b/better_zip/better_zip.py index d23344808..5289513fd 100644 --- a/better_zip/better_zip.py +++ b/better_zip/better_zip.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Author Nicolas Bessi. Copyright Camptocamp SA +# Author: Nicolas Bessi. Copyright Camptocamp SA +# Contributor: Pedro Manuel Baeza # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -17,11 +18,11 @@ # along with this program. If not, see . # ############################################################################## -from openerp.osv.orm import Model, fields +from openerp.osv import orm, fields -class BetterZip(Model): - " Zip/NPA object" +class BetterZip(orm.Model): + " Zip/NPA completion object" _name = "res.better.zip" _description = __doc__ @@ -32,6 +33,8 @@ class BetterZip(Model): '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} @@ -39,19 +42,30 @@ class BetterZip(Model): def name_get(self, cursor, uid, ids, context=None): res = [] for bzip in self.browse(cursor, uid, ids): - res.append((bzip.id, u"%s %s" % (bzip.name, bzip.city))) + name = [bzip.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={}): + 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 -class Partner(Model): - _inherit = "res.partner" - _columns = {'zip_id': fields.many2one('res.better.zip', 'ZIP/PN')} - - def onchange_zip_id(self, cursor, uid, ids, zip_id, context=None): - if not zip_id: - return {} - if isinstance(zip_id, list): - zip_id = zip_id[0] - bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id, context=context) - return {'value': {'zip': bzip.name, 'city': bzip.city, - 'country_id': bzip.country_id.id, 'state_id': bzip.state_id.id}} + 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) diff --git a/better_zip/better_zip_view.xml b/better_zip/better_zip_view.xml index 0bf23ca0e..fdd4d0dac 100644 --- a/better_zip/better_zip_view.xml +++ b/better_zip/better_zip_view.xml @@ -1,16 +1,6 @@ - - res.partner.zip_id.2 - res.partner - - - - - - - res.better.zip.form @@ -19,9 +9,10 @@
+ - +
@@ -34,6 +25,7 @@ + diff --git a/better_zip/company.py b/better_zip/company.py new file mode 100644 index 000000000..274fac615 --- /dev/null +++ b/better_zip/company.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Nicolas Bessi. Copyright Camptocamp SA +# Contributor: Pedro Manuel Baeza +# +# 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 . +# +############################################################################## +from openerp.osv import orm, fields + + +class ResCompany(orm.Model): + + _inherit = 'res.company' + + def on_change_city(self, cursor, uid, ids, zip_id): + result = {} + if zip_id: + bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id) + result = {'value': {'zip': bzip.name, + 'country_id': bzip.country_id.id if bzip.country_id else False, + 'city': bzip.city, + 'state_id': bzip.state_id.id if bzip.state_id else False + } + } + return result + + _columns = { + 'better_zip_id': fields.many2one('res.better.zip', 'Location', select=1, + help=('Use the city name or the zip code' + ' to search the location')), + } diff --git a/better_zip/company_view.xml b/better_zip/company_view.xml new file mode 100644 index 000000000..40ee445d6 --- /dev/null +++ b/better_zip/company_view.xml @@ -0,0 +1,19 @@ + + + + + + res.company.form.city + res.company + + + + + + + + + diff --git a/better_zip/partner.py b/better_zip/partner.py new file mode 100644 index 000000000..458e5fd34 --- /dev/null +++ b/better_zip/partner.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Nicolas Bessi. Copyright Camptocamp SA +# Contributor: Pedro Manuel Baeza +# +# 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 . +# +############################################################################## +from openerp.osv import orm, fields + + +class ResPartner(orm.Model): + _inherit = "res.partner" + _columns = {'zip_id': fields.many2one('res.better.zip', 'ZIP/PN')} + + def onchange_zip_id(self, cursor, uid, ids, zip_id, context=None): + if not zip_id: + return {} + if isinstance(zip_id, list): + zip_id = zip_id[0] + bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id, context=context) + return {'value': {'zip': bzip.name, + 'city': bzip.city, + 'country_id': bzip.country_id.id if bzip.country_id else False, + 'state_id': bzip.state_id.id if bzip.state_id else False, + } + } diff --git a/better_zip/partner_view.xml b/better_zip/partner_view.xml new file mode 100644 index 000000000..a442169e5 --- /dev/null +++ b/better_zip/partner_view.xml @@ -0,0 +1,17 @@ + + + + + res.partner.zip_id.2 + res.partner + + + + + + + + + diff --git a/better_zip/security/ir.model.access.csv b/better_zip/security/ir.model.access.csv new file mode 100644 index 000000000..c6562df1b --- /dev/null +++ b/better_zip/security/ir.model.access.csv @@ -0,0 +1,3 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"ir_model_access_betterzip0","res_better_zip group_user_all","model_res_better_zip",base.group_user,1,0,0,0 +"ir_model_access_betterzip1","res_better_zip group_user","model_res_better_zip","base.group_partner_manager",1,1,1,1 \ No newline at end of file diff --git a/better_zip/security/security.xml b/better_zip/security/security.xml deleted file mode 100644 index 3b6fc5a7f..000000000 --- a/better_zip/security/security.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/better_zip/state.py b/better_zip/state.py new file mode 100644 index 000000000..072111e2d --- /dev/null +++ b/better_zip/state.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Nicolas Bessi. Copyright Camptocamp SA +# Contributor: Pedro Manuel Baeza +# +# 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 . +# +############################################################################## +from openerp.osv import orm, fields + + +class ResCountryState(orm.Model): + + _inherit = 'res.country.state' + + _columns = {'better_zip_ids': fields.one2many('res.better.zip', 'state_id', 'Cities')} diff --git a/better_zip/state_view.xml b/better_zip/state_view.xml new file mode 100644 index 000000000..96497c9e5 --- /dev/null +++ b/better_zip/state_view.xml @@ -0,0 +1,26 @@ + + + + + + view_country_state_form2 + res.country.state + + + + + + + + + + + + + + + +