Merge lp:~numerigraphe/openobject-addons/extra-city into lp:openobject-addons/extra-trunk

Proposed by Numérigraphe
Status: Merged
Merged at revision: not available
Proposed branch: lp:~numerigraphe/openobject-addons/extra-city
Merge into: lp:openobject-addons/extra-trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~numerigraphe/openobject-addons/extra-city
Reviewer Review Type Date Requested Status
OpenERP Committers Pending
Review via email: mp+4131@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Numérigraphe (numerigraphe) wrote :

The module "city" in this branch has fewer "required" fields and is better suited to countries without federal states.
It also adds a code for cities for the official codes (such as those from the INSEE in France).
It also has search methods on city.city so as not to break existing code (partner search for example).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_contact_city/__terp__.py'
2--- base_contact_city/__terp__.py 2008-11-17 11:27:29 +0000
3+++ base_contact_city/__terp__.py 2009-02-26 15:16:19 +0000
4@@ -26,7 +26,8 @@
5 "author" : "Pablo Rocandio",
6 "category" : "Generic Modules/Base",
7 "description": """Zip code, city, state and country fields are replaced with a location field in partner form when base_contact module is installed.
8-This module helps to keep homogenous address data in our database.""",
9+This module helps to keep homogeneous address data in our database.
10+You should use this module if you are already using base_contact and city""",
11 "depends" : ["base", "base_contact", "city"],
12 "init_xml" : [],
13 "update_xml" : [
14
15=== modified file 'city/__terp__.py'
16--- city/__terp__.py 2008-11-23 21:10:14 +0000
17+++ city/__terp__.py 2009-02-26 15:16:19 +0000
18@@ -22,12 +22,12 @@
19 ##############################################################################
20 {
21 "name" : "City",
22- "version" : "1.0",
23+ "version" : "1.1",
24 "author" : "Pablo Rocandio",
25 "category" : "Generic Modules/Base",
26 "description": """Creates a model for storing cities
27 Zip code, city, state and country fields are replaced with a location field in partner and partner contact forms.
28-This module helps to keep homogenous address data in the database.""",
29+This module helps to keep homogeneous address data in the database.""",
30 "depends" : ["base"],
31 "init_xml" : [],
32 "update_xml" : [
33
34=== modified file 'city/city.py'
35--- city/city.py 2008-11-03 19:56:05 +0000
36+++ city/city.py 2009-02-27 08:52:29 +0000
37@@ -32,25 +32,36 @@
38 return []
39 res = []
40 for line in self.browse(cr, uid, ids):
41- state = line.state_id.name
42- country = line.state_id.country_id.name
43- location = "%s %s, %s, %s" %(line.zipcode, line.name, state, country)
44+ location = line.name
45+ if line.zipcode:
46+ location = "%s %s" % (line.zipcode, location)
47+ if line.state_id:
48+ location = "%s, %s" % (location, line.state_id.name)
49+ if line.country_id:
50+ location = "%s, %s" % (location, line.country_id.name)
51 res.append((line['id'], location))
52 return res
53
54- def search(self, cr, uid, args=None, offset=0, limit=80, unknow=0, context=None):
55- res = super(city, self).search(cr, uid, args, offset, limit, unknow, context)
56- if not res and args:
57- args = [('zipcode', 'ilike', args[0][2])]
58- res = super(city, self).search(cr, uid, args, offset, limit, unknow, context)
59- return res
60+ def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
61+ if not args:
62+ args = []
63+ if context is None:
64+ context = {}
65+ ids = []
66+ if name:
67+ ids = self.search(cr, user, [('name', operator, name)] + args, limit=limit, context=context)
68+ if not ids:
69+ ids = self.search(cr, user, [('zipcode', operator, name)] + args, limit=limit, context=context)
70+ return self.name_get(cr, user, ids, context)
71
72 _name = 'city.city'
73 _description = 'City'
74 _columns = {
75- 'state_id': fields.many2one('res.country.state', 'State', required=True, select=1),
76- 'name': fields.char('City', size=64, required=True, select=1),
77- 'zipcode': fields.char('ZIP', size=64, required=True, select=1),
78+ 'state_id': fields.many2one("res.country.state", 'State', domain="[('country_id','=',country_id)]", select=1),
79+ 'name': fields.char('City Name', size=64, required=True, select=1),
80+ 'zipcode': fields.char('ZIP', size=64, select=1),
81+ 'country_id': fields.many2one('res.country', 'Country', select=1),
82+ 'code': fields.char('City Code', size=64, help="The official code for the city"),
83 }
84 city()
85
86@@ -65,8 +76,8 @@
87
88 class res_partner_address(osv.osv):
89 def _get_zip(self, cr, uid, ids, field_name, arg, context):
90- res={}
91- for obj in self.browse(cr,uid,ids):
92+ res = {}
93+ for obj in self.browse(cr, uid, ids):
94 if obj.location:
95 res[obj.id] = obj.location.zipcode
96 else:
97@@ -74,8 +85,8 @@
98 return res
99
100 def _get_city(self, cr, uid, ids, field_name, arg, context):
101- res={}
102- for obj in self.browse(cr,uid,ids):
103+ res = {}
104+ for obj in self.browse(cr, uid, ids):
105 if obj.location:
106 res[obj.id] = obj.location.name
107 else:
108@@ -83,31 +94,58 @@
109 return res
110
111 def _get_state(self, cr, uid, ids, field_name, arg, context):
112- res={}
113- for obj in self.browse(cr,uid,ids):
114- if obj.location:
115+ res = {}
116+ for obj in self.browse(cr, uid, ids):
117+ if obj.location and obj.location.state_id:
118 res[obj.id] = [obj.location.state_id.id, obj.location.state_id.name]
119 else:
120 res[obj.id] = False
121 return res
122
123 def _get_country(self, cr, uid, ids, field_name, arg, context):
124- res={}
125- for obj in self.browse(cr,uid,ids):
126- if obj.location:
127- res[obj.id] = [obj.location.state_id.country_id.id, obj.location.state_id.country_id.name]
128+ res = {}
129+ for obj in self.browse(cr, uid, ids):
130+ if obj.location and obj.location.country_id:
131+ res[obj.id] = [obj.location.country_id.id, obj.location.country_id.name]
132 else:
133 res[obj.id] = False
134 return res
135
136+ # XXX The following search function could have been written with SQL...
137+ def _zip_search(self, cr, uid, obj, name, args):
138+ """Search for addresses in cities with this zip code"""
139+ cities = self.pool.get('city.city').search(cr, uid, args=[('zipcode', args[0][1], args[0][2])])
140+ ids=self.search(cr, uid, args=[('location','in',cities)])
141+ return [('id', 'in', ids)]
142+
143+ def _city_search(self, cr, uid, obj, name, args):
144+ """Search for addresses in cities with this city name"""
145+ cities = self.pool.get('city.city').search(cr, uid, args=[('name', args[0][1], args[0][2])])
146+ ids=self.search(cr, uid, args=[('location','in',cities)])
147+ return [('id', 'in', ids)]
148+
149+ def _state_search(self, cr, uid, obj, name, args):
150+ print """Search for addresses in cities in this state"""
151+ states = self.pool.get('res.country.state').search(cr, uid, args=[('name', args[0][1], args[0][2])])
152+ cities = self.pool.get('city.city').search(cr, uid, args=[('state_id', 'in', states)])
153+ ids=self.search(cr, uid, args=[('location','in',cities)])
154+ return [('id', 'in', ids)]
155+
156+ def _country_search(self, cr, uid, obj, name, args):
157+ print """Search for addresses in cities in this country"""
158+ countries = self.pool.get('res.country').search(cr, uid, args=[('name', args[0][1], args[0][2])])
159+ cities = self.pool.get('city.city').search(cr, uid, args=[('country_id', 'in', countries)])
160+ ids=self.search(cr, uid, args=[('location','in',cities)])
161+ return [('id', 'in', ids)]
162+
163 _inherit = "res.partner.address"
164 _columns = {
165- 'location': fields.many2one('city.city', 'Location'),
166- 'zip': fields.function(_get_zip, method=True, type="char", string='Zip', size=24),
167- 'city': fields.function(_get_city, method=True, type="char", string='City', size=128),
168- 'state_id': fields.function(_get_state, obj="res.country.state", method=True, type="many2one", string='State'),
169- 'country_id': fields.function(_get_country, obj="res.country" ,method=True, type="many2one", string='Country'),
170- }
171+ 'location': fields.many2one('city.city', 'Location', select=1),
172+ 'zip': fields.function(_get_zip, method=True, type="char", string='Zip', size=24, fnct_search=_zip_search),
173+ 'city': fields.function(_get_city, method=True, type="char", string='City', size=128, fnct_search=_city_search),
174+ 'state_id': fields.function(_get_state, obj="res.country.state", method=True, type="many2one", string='State', fnct_search=_state_search),
175+ 'country_id': fields.function(_get_country, obj="res.country" , method=True, type="many2one", string='Country', fnct_search=_country_search),
176+ }
177 res_partner_address()
178
179
180
181=== modified file 'city/city_view.xml'
182--- city/city_view.xml 2008-10-27 22:52:00 +0000
183+++ city/city_view.xml 2009-02-27 08:52:29 +0000
184@@ -23,16 +23,6 @@
185 </field>
186 </record>
187
188- <!-- We need to city replaces to remove it -->
189- <record model="ir.ui.view" id="partners_form_del_citycity">
190- <field name="name">partners_form_del_citycity</field>
191- <field name="model">res.partner</field>
192- <field name="inherit_id" ref="base.view_partner_form"/>
193- <field name="arch" type="xml">
194- <field name="city" position="replace"/>
195- </field>
196- </record>
197-
198 <record model="ir.ui.view" id="partners_form_del_zip">
199 <field name="name">partners_form_del_zip</field>
200 <field name="model">res.partner</field>
201@@ -167,6 +157,7 @@
202 <field name="zipcode"/>
203 <field name="name"/>
204 <field name="state_id"/>
205+ <field name="country_id"/>
206 </tree>
207 </field>
208 </record>
209@@ -177,9 +168,11 @@
210 <field name="type">form</field>
211 <field name="arch" type="xml">
212 <form string="City">
213- <field name="zipcode" select="1"/>
214- <field name="name" select="1"/>
215- <field name="state_id" select="1"/>
216+ <field name="zipcode" />
217+ <field name="name" />
218+ <field name="country_id" />
219+ <field name="state_id" />
220+ <field name="code" select="2"/>
221 </form>
222 </field>
223 </record>
224
225=== added file 'city/i18n/fr_FR.po'
226--- city/i18n/fr_FR.po 1970-01-01 00:00:00 +0000
227+++ city/i18n/fr_FR.po 2009-03-03 10:26:05 +0000
228@@ -0,0 +1,85 @@
229+# Translation of OpenERP Server.
230+# This file contains the translation of the following modules:
231+# * city
232+#
233+msgid ""
234+msgstr ""
235+"Project-Id-Version: OpenERP Server 5.0.0\n"
236+"Report-Msgid-Bugs-To: support@openerp.com\n"
237+"POT-Creation-Date: 2009-02-27 09:13:15+0000\n"
238+"PO-Revision-Date: 2009-02-27 10:22+0100\n"
239+"Last-Translator: Numerigraphe <informatique@numerigraphe.com>\n"
240+"Language-Team: \n"
241+"MIME-Version: 1.0\n"
242+"Content-Type: text/plain; charset=UTF-8\n"
243+"Content-Transfer-Encoding: \n"
244+"Plural-Forms: "
245+
246+#. module: city
247+#: view:city.city:0
248+#: model:ir.actions.act_window,name:city.action_city
249+#: model:ir.model,name:city.model_city_city
250+#: model:ir.module.module,shortdesc:city.module_meta_information
251+msgid "City"
252+msgstr "Ville"
253+
254+#. module: city
255+#: constraint:ir.ui.view:0
256+msgid "Invalid XML for View Architecture!"
257+msgstr "XML non valide pour l'architecture de la vue"
258+
259+#. module: city
260+#: constraint:ir.model:0
261+msgid "The Object name must start with x_ and not contain any special character !"
262+msgstr "Le nom de l'objet doit commencer avec x_ et ne pas contenir de charactères spéciaux !"
263+
264+#. module: city
265+#: field:city.city,zipcode:0
266+msgid "ZIP"
267+msgstr "Code postal"
268+
269+#. module: city
270+#: field:city.city,state_id:0
271+msgid "State"
272+msgstr "État"
273+
274+#. module: city
275+#: field:city.city,country_id:0
276+msgid "Country"
277+msgstr "Pays"
278+
279+#. module: city
280+#: field:city.city,code:0
281+msgid "City Code"
282+msgstr "Code de la ville"
283+
284+#. module: city
285+#: model:ir.module.module,description:city.module_meta_information
286+msgid "Creates a model for storing cities\n"
287+"Zip code, city, state and country fields are replaced with a location field in partner and partner contact forms.\n"
288+"This module helps to keep homogeneous address data in the database."
289+msgstr "Crée un modèle de données pour les villes.\n"
290+"Les champs \"code postal\", \"ville\", \"état\" et \"pays\" sont remplacés par un champ \"localisation\" dans les formulaires \"partenaire\" et \"contacts du partenaire\"."
291+"Ce module permet de conserver des données d'adresse homogènes."
292+
293+#. module: city
294+#: field:city.city,name:0
295+msgid "City Name"
296+msgstr "Nom de la ville"
297+
298+#. module: city
299+#: field:res.partner.address,location:0
300+msgid "Location"
301+msgstr "Localisation"
302+
303+#. module: city
304+#: help:city.city,code:0
305+msgid "The official code for the city"
306+msgstr "Le code officiel de la ville"
307+
308+#. module: city
309+#: model:ir.ui.menu,name:city.menu_city_partner
310+#: field:res.country.state,city_ids:0
311+msgid "Cities"
312+msgstr "Villes"
313+

Subscribers

People subscribed via source and target branches