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

Proposed by Numérigraphe
Status: Needs review
Proposed branch: lp:~numerigraphe/openobject-addons/6.0-extra-city
Merge into: lp:openobject-addons/extra-6.0
Diff against target: 226 lines (+30/-129)
3 files modified
city/__openerp__.py (+3/-3)
city/city.py (+24/-116)
city/city_view.xml (+3/-10)
To merge this branch: bzr merge lp:~numerigraphe/openobject-addons/6.0-extra-city
Reviewer Review Type Date Requested Status
OpenERP Committers Pending
Jordi Esteve (www.zikzakmedia.com) Pending
Review via email: mp+83197@code.launchpad.net

Description of the change

This branch re-introduces changes I made to city in v5.0:
- usable in countries without states
- uses "related" fields
- removes duplicate "replace" from the view file

To post a comment you must log in.

Unmerged revisions

5598. By Numerigraphe - Lionel Sausin <email address hidden>

[IMP] Adapted city to countries without states. Simplified the code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'city/__openerp__.py'
2--- city/__openerp__.py 2011-02-18 20:19:26 +0000
3+++ city/__openerp__.py 2011-11-23 17:19:25 +0000
4@@ -21,13 +21,13 @@
5 #
6 ##############################################################################
7 {
8- "name" : "City-Helps to keep Homogenous address data in the Database",
9- "version" : "1.0",
10+ "name" : "City-Helps to keep Homogeneous address data in the Database",
11+ "version" : "1.1",
12 "author" : "Pablo Rocandio",
13 "category" : "Generic Modules/Base",
14 "description": """Creates a model for storing cities
15 Zip code, city, state and country fields are replaced with a location field in partner and partner contact forms.
16-This module helps to keep homogenous address data in the database.""",
17+This module helps to keep homogeneous address data in the database.""",
18 "depends" : ["base"],
19 "init_xml" : [],
20 "update_xml" : [
21
22=== modified file 'city/city.py'
23--- city/city.py 2011-04-14 12:37:55 +0000
24+++ city/city.py 2011-11-23 17:19:25 +0000
25@@ -31,10 +31,14 @@
26 if not len(ids):
27 return []
28 res = []
29- for line in self.browse(cr, uid, ids):
30- state = line.state_id.name
31- country = line.state_id.country_id.name
32- location = "%s %s, %s, %s" %(line.zipcode, line.name, state, country)
33+ for line in self.browse(cr, uid, ids, context=context):
34+ location = line.name
35+ if line.zipcode:
36+ location = "%s %s" % (line.zipcode, location)
37+ if line.state_id:
38+ location = "%s, %s" % (location, line.state_id.name)
39+ if line.country_id:
40+ location = "%s, %s" % (location, line.country_id.name)
41 res.append((line['id'], location))
42 return res
43
44@@ -53,9 +57,13 @@
45 _name = 'city.city'
46 _description = 'City'
47 _columns = {
48- 'state_id': fields.many2one('res.country.state', 'State', required=True, select=1),
49+ 'state_id': fields.many2one('res.country.state', 'State',
50+ domain="[('country_id','=',country_id)]", select=1),
51 'name': fields.char('City', size=64, required=True, select=1),
52 'zipcode': fields.char('ZIP', size=64, required=True, select=1),
53+ 'country_id': fields.many2one('res.country', 'Country', select=1),
54+ 'code': fields.char('City Code', size=64,
55+ help="The official code for the city"),
56 }
57 city()
58
59@@ -70,117 +78,17 @@
60
61 class res_partner_address(osv.osv):
62 _inherit = "res.partner.address"
63-
64- def _get_zip(self, cr, uid, ids, field_name, arg, context):
65- res={}
66- for obj in self.browse(cr,uid,ids):
67- if obj.location:
68- res[obj.id] = obj.location.zipcode
69- else:
70- res[obj.id] = ""
71- return res
72-
73- def _zip_search(self, cr, uid, obj, name, args, context):
74- if not len(args):
75- return []
76- new_args = []
77- for argument in args:
78- operator = argument[1]
79- value = argument[2]
80- ids = self.pool.get('city.city').search(cr, uid, [('zipcode',operator,value)], context=context)
81- new_args.append( ('location','in',ids) )
82- if new_args:
83- # We need to ensure that locatio is NOT NULL. Otherwise all addresses
84- # that have no location will 'match' current search pattern.
85- new_args.append( ('location','!=',False) )
86- return new_args
87-
88- def _get_city(self, cr, uid, ids, field_name, arg, context):
89- res={}
90- for obj in self.browse(cr,uid,ids):
91- if obj.location:
92- res[obj.id] = obj.location.name
93- else:
94- res[obj.id] = ""
95- return res
96-
97- def _city_search(self, cr, uid, obj, name, args, context):
98- if not len(args):
99- return []
100- new_args = []
101- for argument in args:
102- operator = argument[1]
103- value = argument[2]
104- ids = self.pool.get('city.city').search(cr, uid, [('name',operator,value)], context=context)
105- new_args.append( ('location','in',ids) )
106- if new_args:
107- # We need to ensure that locatio is NOT NULL. Otherwise all addresses
108- # that have no location will 'match' current search pattern.
109- new_args.append( ('location','!=',False) )
110- return new_args
111-
112- def _get_state(self, cr, uid, ids, field_name, arg, context):
113- res={}
114- for obj in self.browse(cr,uid,ids):
115- if obj.location:
116- res[obj.id] = [obj.location.state_id.id, obj.location.state_id.name]
117- else:
118- res[obj.id] = False
119- return res
120-
121- def _state_id_search(self, cr, uid, obj, name, args, context):
122- if not len(args):
123- return []
124- new_args = []
125- for argument in args:
126- operator = argument[1]
127- value = argument[2]
128- ids = self.pool.get('city.city').search(cr, uid, [('state_id',operator,value)], context=context)
129- new_args.append( ('location','in',ids) )
130- if new_args:
131- # We need to ensure that locatio is NOT NULL. Otherwise all addresses
132- # that have no location will 'match' current search pattern.
133- new_args.append( ('location','!=',False) )
134- return new_args
135-
136- def _get_country(self, cr, uid, ids, field_name, arg, context):
137- res={}
138- for obj in self.browse(cr,uid,ids):
139- if obj.location:
140- res[obj.id] = [obj.location.state_id.country_id.id, obj.location.state_id.country_id.name]
141- else:
142- res[obj.id] = False
143- return res
144-
145- def _country_id_search(self, cr, uid, obj, name, args, context):
146- if not len(args):
147- return []
148- new_args = []
149- for argument in args:
150- operator = argument[1]
151- value = argument[2]
152- ids = self.pool.get('res.country.state').search(cr, uid, [('country_id',operator,value)], context=context)
153- address_ids = []
154- for country in self.pool.get('res.country.state').browse(cr, uid, ids, context):
155- ids += [city.id for city in country.city_ids]
156- new_args.append( ('location','in',tuple(ids)) )
157- if new_args:
158- # We need to ensure that locatio is NOT NULL. Otherwise all addresses
159- # that have no location will 'match' current search pattern.
160- new_args.append( ('location','!=',False) )
161- return new_args
162-
163 _columns = {
164- 'location': fields.many2one('city.city', 'Location'),
165- 'zip': fields.function(_get_zip, fnct_search=_zip_search, method=True, type="char", string='Zip', size=24),
166- 'city': fields.function(_get_city, fnct_search=_city_search, method=True, type="char", string='City', size=128),
167- 'state_id': fields.function(_get_state, fnct_search=_state_id_search, obj="res.country.state", method=True, type="many2one", string='State'),
168- 'country_id': fields.function(_get_country, fnct_search=_country_id_search, obj="res.country" ,method=True, type="many2one", string='Country'),
169+ 'location': fields.many2one('city.city', 'Location', select=1),
170+ 'zip': fields.related('location', 'zipcode', type="char", string="Zip",
171+ store=False),
172+ 'city': fields.related('location', 'name', type="char", string="City",
173+ store=False),
174+ 'state_id': fields.related('location', 'state_id', type="many2one",
175+ relation="res.country.state", string="State",
176+ store=False),
177+ 'country_id': fields.related('location', 'country_id', type="many2one",
178+ relation="res.country", string="Country",
179+ store=False),
180 }
181 res_partner_address()
182-
183-
184-
185-
186-
187-
188
189=== modified file 'city/city_view.xml'
190--- city/city_view.xml 2011-02-18 20:19:26 +0000
191+++ city/city_view.xml 2011-11-23 17:19:25 +0000
192@@ -23,16 +23,6 @@
193 </field>
194 </record>
195
196- <!-- We need to city replaces to remove it -->
197- <record model="ir.ui.view" id="partners_form_del_citycity">
198- <field name="name">partners_form_del_citycity</field>
199- <field name="model">res.partner</field>
200- <field name="inherit_id" ref="base.view_partner_form"/>
201- <field name="arch" type="xml">
202- <field name="city" position="replace"/>
203- </field>
204- </record>
205-
206 <record model="ir.ui.view" id="partners_form_del_zip">
207 <field name="name">partners_form_del_zip</field>
208 <field name="model">res.partner</field>
209@@ -167,6 +157,7 @@
210 <field name="zipcode"/>
211 <field name="name"/>
212 <field name="state_id"/>
213+ <field name="country_id"/>
214 </tree>
215 </field>
216 </record>
217@@ -179,7 +170,9 @@
218 <form string="City">
219 <field name="zipcode" select="1"/>
220 <field name="name" select="1"/>
221+ <field name="country_id" />
222 <field name="state_id" select="1"/>
223+ <field name="code" select="2"/>
224 </form>
225 </field>
226 </record>