-
-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.0][MIG] base_location_nuts: Migration to 11.0 #518
Conversation
0593408
to
ebdb16b
Compare
base_location_nuts/__manifest__.py
Outdated
'category': 'Localisation/Europe', | ||
'version': '11.0.1.0.0', | ||
'depends': [ | ||
'sales_team', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you can now remove this dependency. It was required for the menuitem.
ebdb16b
to
787593e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM installed on an enterprise db and no problem.
787593e
to
562d983
Compare
852b863
to
77d6cfe
Compare
pattern = re.compile(r'^.*<\?xml', re.DOTALL) | ||
content_fixed = re.sub(pattern, '<?xml', res_request.content) | ||
if not re.match(r'<\?xml', content_fixed): | ||
pattern = re.compile(r'^.*<\?xml'.encode('utf-8'), re.DOTALL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do rb'^.*<\?xml'
instead of the encode stuff.
content_fixed = re.sub(pattern, '<?xml', res_request.content) | ||
if not re.match(r'<\?xml', content_fixed): | ||
pattern = re.compile(r'^.*<\?xml'.encode('utf-8'), re.DOTALL) | ||
content_fixed = re.sub(pattern, b'<?xml', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't make much sense to manually compile a pattern that you're gonna use just once, even more when python already autocaches often-used pattern compilations.
Check explanation here: https://docs.python.org/3/library/re.html#re.compile
pattern = re.compile(r'^.*<\?xml'.encode('utf-8'), re.DOTALL) | ||
content_fixed = re.sub(pattern, b'<?xml', | ||
res_request.content) | ||
if not re.match(r'<\?xml'.encode('utf-8'), content_fixed): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, just rb'<\?xml'
@@ -190,7 +190,8 @@ def run_import(self): | |||
# All current NUTS (for available countries), | |||
# delete if not found above | |||
nuts_to_delete = nuts_model.search( | |||
[('country_id', 'in', [x.id for x in self._countries.values()])]) | |||
[('country_id', 'in', | |||
[x.id for x in list(self._countries.values())])]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for list()
here. Views are better when iterating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same about the automatism of 2to3
raise UserError(_('Downloaded file is not a valid XML file')) | ||
return content_fixed | ||
|
||
@api.model | ||
def _load_countries(self): | ||
for k in self._countries.keys(): | ||
for k in list(self._countries.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with for k in self._countries:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done automatically by 2to3
, and there are reasons for that:
self._countries
doesn't return now the keys by default- It's converted to list because they don't get if it's going to be used as an iterator. In this case
list(
can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a combination of both things, but both things are wrong in this specific case AFAICS.
Check this out, from last PyCon: https://youtu.be/V5-JH23Vk0I?t=3m17s
raise UserError(_('Downloaded file is not a valid XML file')) | ||
return content_fixed | ||
|
||
@api.model | ||
def _load_countries(self): | ||
for k in list(self._countries.keys()): | ||
for k in self._countries.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove .keys()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not finished yet... I have to take a look also to re.compile thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha OK, too quick review 😋
fc2740d
to
9e18fe6
Compare
@luismontalba @chienandalu please review this one and l10n_es_location_nuts one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It'd be nice to improve coverage anyway 🙂
@pedrobaeza I can't see any PR for l10n_es_location_nuts, do you have a link? |
Please squash the migration commits to merge. |
9e18fe6
to
2d76bf3
Compare
@yajo squash done |
Yikes I forgot to ask you to squash translation commits too, I'll do it for you. 😉 |
[MIG] Rename manifest files
This makes NUTS labels and levels to be stored in the res.country object. Now creating l10n submodules is a piece of cake! Relational fields now follow guidelines on naming. Old name attribute used for backwards compatibility wherever needed. Also some methods have been renamed, and refactored to be smarter. Most cases l10n modules will just need to fill the res.contry table, and regions and substates domains will work out of the box. In case you still need to overwrite any method, splitting in smaller methods makes it easier too. Oh! And no need for recursive dictionary updates. Return dict() to make it easier for submodules to add domains. Fix KeyError: 'substate_id_level'.
Fix linter. Fix typo.
2d76bf3
to
e014100
Compare
Rebased squashing by author & logical changeset. If bots go ✔️, merge. |
Can anyone check this out again, bots have gone green... |
cc @oihane