Skip to content
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

Merged
merged 9 commits into from
Jan 23, 2018

Conversation

agaldona
Copy link

@agaldona agaldona commented Nov 14, 2017

cc @oihane

@agaldona agaldona force-pushed the 11.0-mig-base_location_nuts branch 3 times, most recently from 0593408 to ebdb16b Compare November 14, 2017 13:23
'category': 'Localisation/Europe',
'version': '11.0.1.0.0',
'depends': [
'sales_team',
Copy link
Contributor

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.

@agaldona agaldona force-pushed the 11.0-mig-base_location_nuts branch from ebdb16b to 787593e Compare November 14, 2017 16:42
Copy link
Contributor

@oihane oihane left a 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.

@agaldona agaldona force-pushed the 11.0-mig-base_location_nuts branch from 787593e to 562d983 Compare November 14, 2017 16:46
@pedrobaeza pedrobaeza added this to the 11.0 milestone Nov 14, 2017
@oihane oihane force-pushed the 11.0-mig-base_location_nuts branch 2 times, most recently from 852b863 to 77d6cfe Compare November 15, 2017 15:15
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)
Copy link
Member

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',
Copy link
Member

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):
Copy link
Member

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())])])
Copy link
Member

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.

Copy link
Member

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()):
Copy link
Member

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:

Copy link
Member

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.

Copy link
Member

@yajo yajo Nov 16, 2017

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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove .keys()

Copy link
Contributor

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.

Copy link
Member

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 😋

@oihane oihane force-pushed the 11.0-mig-base_location_nuts branch from fc2740d to 9e18fe6 Compare November 16, 2017 13:59
@pedrobaeza pedrobaeza mentioned this pull request Nov 21, 2017
53 tasks
@pedrobaeza
Copy link
Member

@luismontalba @chienandalu please review this one and l10n_es_location_nuts one.

Copy link
Member

@chienandalu chienandalu left a 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 🙂

@chienandalu
Copy link
Member

@pedrobaeza I can't see any PR for l10n_es_location_nuts, do you have a link?

@pedrobaeza
Copy link
Member

OCA/l10n-spain#691

@yajo
Copy link
Member

yajo commented Nov 30, 2017

Please squash the migration commits to merge.

@oihane oihane force-pushed the 11.0-mig-base_location_nuts branch from 9e18fe6 to 2d76bf3 Compare December 4, 2017 09:15
@oihane
Copy link
Contributor

oihane commented Dec 4, 2017

@yajo squash done

@yajo
Copy link
Member

yajo commented Dec 5, 2017

Yikes I forgot to ask you to squash translation commits too, I'll do it for you. 😉

Antonio Espinosa and others added 4 commits December 5, 2017 09:51
[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'.
@yajo yajo force-pushed the 11.0-mig-base_location_nuts branch from 2d76bf3 to e014100 Compare December 5, 2017 08:52
@yajo
Copy link
Member

yajo commented Dec 5, 2017

Rebased squashing by author & logical changeset. If bots go ✔️, merge.

@oihane
Copy link
Contributor

oihane commented Jan 23, 2018

Can anyone check this out again, bots have gone green...

@pedrobaeza pedrobaeza merged commit 7eb6c73 into OCA:11.0 Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants