Manage unknown subdivision type
issue11128 review397091002
This commit is contained in:
1 parent
94b7951753
commit
430adf2e51
4 files changed
+22
-4
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Manage unknown subdivision type
|
||||
* Add support for Python 3.10
|
||||
* Remove support for Python 3.6
|
||||
|
||||
|
||||
+7
-1
@@ -94,6 +94,7 @@ class Subdivision(DeactivableMixin, ModelSQL, ModelView):
|
||||
code = fields.Char('Code', required=True, select=True,
|
||||
help="The ISO code of the subdivision.")
|
||||
type = fields.Selection([
|
||||
(None, ""),
|
||||
('administration', 'Administration'),
|
||||
('administrative area', 'Administrative area'),
|
||||
('administrative atoll', 'Administrative atoll'),
|
||||
@@ -198,7 +199,7 @@ class Subdivision(DeactivableMixin, ModelSQL, ModelView):
|
||||
('unitary authority (england)', 'Unitary authority (england)'),
|
||||
('unitary authority (wales)', 'Unitary authority (wales)'),
|
||||
('zone', 'zone'),
|
||||
], 'Type', required=True)
|
||||
], "Type")
|
||||
parent = fields.Many2One('country.subdivision', 'Parent',
|
||||
domain=[
|
||||
('country', '=', Eval('country', -1)),
|
||||
@@ -220,10 +221,15 @@ class Subdivision(DeactivableMixin, ModelSQL, ModelView):
|
||||
|
||||
super().__register__(module_name)
|
||||
|
||||
table_h = cls.__table_handler__(module_name)
|
||||
|
||||
# Migration from 5.2: remove country data
|
||||
cursor.execute(*data.delete(where=(data.module == 'country')
|
||||
& (data.model == cls.__name__)))
|
||||
|
||||
# Migration from 6.2: remove type required
|
||||
table_h.not_null_action('type', action='remove')
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
return ['OR',
|
||||
|
||||
@@ -96,6 +96,8 @@ def update_subdivisions(countries, subdivisions):
|
||||
print("Update subdivisions", file=sys.stderr)
|
||||
Subdivision = Model.get('country.subdivision')
|
||||
|
||||
types = dict(Subdivision._fields['type']['selection'])
|
||||
unknown_types = set()
|
||||
records = []
|
||||
for subdivision in _progress(pycountry.subdivisions):
|
||||
code = subdivision.code
|
||||
@@ -105,7 +107,16 @@ def update_subdivisions(countries, subdivisions):
|
||||
else:
|
||||
record = Subdivision(code=code, country=countries[country_code])
|
||||
record.name = _remove_forbidden_chars(subdivision.name)
|
||||
record.type = subdivision.type.lower()
|
||||
type_ = subdivision.type.lower()
|
||||
if type_ in types:
|
||||
record.type = subdivision.type.lower()
|
||||
else:
|
||||
record.type = None
|
||||
if type_ not in unknown_types:
|
||||
print(
|
||||
"Unknown subdivision type: %s" % subdivision.type,
|
||||
file=sys.stderr)
|
||||
unknown_types.add(type_)
|
||||
records.append(record)
|
||||
|
||||
Subdivision.save(records)
|
||||
|
||||
@@ -67,7 +67,7 @@ for dep in info.get('depends', []):
|
||||
requires.append(get_require_version('trytond_%s' % dep))
|
||||
requires.append(get_require_version('trytond'))
|
||||
|
||||
tests_require = [get_require_version('proteus'), 'pycountry<=20.7.3']
|
||||
tests_require = [get_require_version('proteus'), 'pycountry']
|
||||
dependency_links = []
|
||||
if minor_version % 2:
|
||||
dependency_links.append(
|
||||
@@ -143,7 +143,7 @@ setup(name=name,
|
||||
python_requires='>=3.7',
|
||||
install_requires=requires,
|
||||
extras_require={
|
||||
'data': ['pycountry<=20.7.3', get_require_version('proteus')],
|
||||
'data': ['pycountry', get_require_version('proteus')],
|
||||
'GeoNames': [get_require_version('proteus')],
|
||||
},
|
||||
dependency_links=dependency_links,
|
||||
|
||||
Reference in new issue
Block a user