From 78105ec59062d8aa78664a089fcff405b97a562e Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Tue, 11 Feb 2014 18:31:33 -0500 Subject: [PATCH] [FIX] Add context propagation to base_location --- base_location/__init__.py | 1 + base_location/better_zip.py | 21 ++++++++++++++------- base_location/company.py | 26 ++++++++++++++------------ base_location/partner.py | 20 +++++++++++--------- base_location/state.py | 7 ++++--- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/base_location/__init__.py b/base_location/__init__.py index ba9aeedea..878769646 100644 --- a/base_location/__init__.py +++ b/base_location/__init__.py @@ -19,6 +19,7 @@ # along with this program. If not, see . # ############################################################################## + from . import better_zip from . import partner from . import state diff --git a/base_location/better_zip.py b/base_location/better_zip.py index 562a842e3..c51644a12 100644 --- a/base_location/better_zip.py +++ b/base_location/better_zip.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## +# # # Author: Nicolas Bessi. Copyright Camptocamp SA # Contributor: Pedro Manuel Baeza @@ -18,11 +18,12 @@ # 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 BetterZip(orm.Model): + " City/locations completion object" _name = "res.better.zip" @@ -42,7 +43,7 @@ class BetterZip(orm.Model): def name_get(self, cursor, uid, ids, context=None): res = [] - for bzip in self.browse(cursor, uid, ids): + for bzip in self.browse(cursor, uid, ids, context=context): if bzip.name: name = [bzip.name, bzip.city] else: @@ -57,19 +58,25 @@ class BetterZip(orm.Model): 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) + 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): + 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) + 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) + ids = self.search( + cr, uid, [('city', operator, name)] + args, limit=limit) return self.name_get(cr, uid, ids, context=context) diff --git a/base_location/company.py b/base_location/company.py index 6f52c7bd0..35ef3d856 100644 --- a/base_location/company.py +++ b/base_location/company.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## +# # # Author: Nicolas Bessi. Copyright Camptocamp SA # Contributor: Pedro Manuel Baeza @@ -18,7 +18,7 @@ # 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 @@ -31,17 +31,19 @@ class ResCompany(orm.Model): if context is None: context = {} if zip_id: - bzip = self.pool['res.better.zip'].browse(cr, uid, zip_id, context=context) - 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 - } - } + bzip = self.pool['res.better.zip'].browse( + cr, uid, zip_id, context=context) + 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')), + '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/base_location/partner.py b/base_location/partner.py index b6db7bc8b..76218ecd5 100644 --- a/base_location/partner.py +++ b/base_location/partner.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## +# # # Author: Nicolas Bessi. Copyright Camptocamp SA # Contributor: Pedro Manuel Baeza @@ -18,7 +18,7 @@ # 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 @@ -31,10 +31,12 @@ class ResPartner(orm.Model): 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, - } - } + 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/base_location/state.py b/base_location/state.py index 4312384af..24cc81e20 100644 --- a/base_location/state.py +++ b/base_location/state.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## +# # # Author: Nicolas Bessi. Copyright Camptocamp SA # Contributor: Pedro Manuel Baeza @@ -18,7 +18,7 @@ # 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 @@ -26,4 +26,5 @@ class ResCountryState(orm.Model): _inherit = 'res.country.state' - _columns = {'better_zip_ids': fields.one2many('res.better.zip', 'state_id', 'Cities')} + _columns = {'better_zip_ids': fields.one2many( + 'res.better.zip', 'state_id', 'Cities')}