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

[ADD] base_location_nuts addon #107

Merged
merged 1 commit into from
Oct 6, 2015

Conversation

antespi
Copy link
Contributor

@antespi antespi commented Mar 31, 2015

NUTS Regions

This module allows to import NUTS locations.

Creates two new fields in Partner object:

  • Region (res.partner.region): Classification over state, automatically
    calculated when state is selected
  • Substate (res.partner.substate): Classification above state, user must select
    one from available for selected state

You need to install another addon (one for each country) in order to use
these NUTS, for example:

  • l10n_es_location_nuts :
    • Spanish Provinces (NUTS level 4) as Partner State
    • Spanish Autonomous communities (NUTS level 3) as Partner Substate
    • Spanish Regions (NUTS level 2) as Partner Region
  • l10n_de_location_nuts :
    • German states (NUTS level 2) as Partner State
    • German regions (NUTS level 3) as Partner Substate

After installation, you must click at import wizard to populate NUTS items
in Odoo database in:
Sales > Configuration > Address Book > Import NUTS 2013

This wizard will download from Europe RAMON service the metadata to
build NUTS in Odoo. Each localization addon (l10n_es_location_nuts,
l10n_de_location_nuts, ...) will inherit this wizard and
relate each NUTS item with states. So if you install a new localization addon
you must re-build NUTS clicking this wizard again.

Only Administrator can manage NUTS list (it is not neccesary because
it is an European convention) but any registered user can read them,
in order to allow to assign them to partner object.

'demo': [],
'test': [],
'installable': True,
# 'auto_install':False,
Copy link

Choose a reason for hiding this comment

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

remove comment code

@OSguard
Copy link

OSguard commented Apr 1, 2015

overall cool stuff, not tested yet

@bealdav
Copy link
Member

bealdav commented Apr 2, 2015

Good job thanks.
May be could you consider module name convention
http://odoo-community.org/page/how-to

Maybe res.partner.nuts could also be res.partner.nut

@pedrobaeza
Copy link
Member

@bealdav, NUTS is an acronym, not a plural: http://en.wikipedia.org/wiki/Nomenclature_of_Territorial_Units_for_Statistics, so it doesn't apply to remove the 's'.

@bealdav
Copy link
Member

bealdav commented Apr 2, 2015

Oops, sorry for my lack of culture, never heard this term. It was not 🌰 then ... 😆

@OSguard
Copy link

OSguard commented Apr 7, 2015

Runbot returns:
2015-04-06 09:12:14,897 11692 ERROR 2926052-107-2e410f-all openerp.models: The column parent_id on object res.partner.nuts must be set as ondelete='cascade' or 'restrict'

@antespi
Copy link
Contributor Author

antespi commented Apr 8, 2015

@pedrobaeza I've already done in Antiun@1a3d11e

@pedrobaeza
Copy link
Member

on_delete="set null" is redundant. It's the default behaviour.

@antespi
Copy link
Contributor Author

antespi commented Apr 10, 2015

Travis and runbot are ok, any other comments from reviewers?
Thanks

@pedrobaeza
Copy link
Member

👍

@antespi
Copy link
Contributor Author

antespi commented Apr 16, 2015

any news?

@hbrunn
Copy link
Member

hbrunn commented Apr 17, 2015

One hint and a conceptual question:
hint: You could have the wizard autostart if you create an appropriate ir.actions.todo for it with state automatic
conceptual questions: From my understanding, different l10n_* modules attach different sematics to this fields. Is this really a good idea? How would I fill in a spanish customer's region with the german localization installed?

class ResPartner(models.Model):
_inherit = 'res.partner'

region = fields.Many2one(comodel_name='res.partner.nuts',
Copy link
Member

Choose a reason for hiding this comment

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

can we put domains for country_id on this fields?

Copy link
Member

Choose a reason for hiding this comment

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

This question is not asked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm testing to see if we can do what @hbrunn is asking. This configuration must be compatible with onchages defined in localizations addons (l10n_es_location_nuts, l10n_de_location_nuts, etc ...)

@antespi
Copy link
Contributor Author

antespi commented Apr 17, 2015

@hbrunn, thanks for your review:

The problem i couldn't fix is that Spanish translation sets labels according to Spanish nuts but what happens when user introduces a german address? Labels doesn't mean what data means. I don't know how to change labels/placeholder in on_change (v8 flavor) method, do you?

@hbrunn
Copy link
Member

hbrunn commented Apr 17, 2015

you could have function fields that you use as labels (so you'll have to write the html code for the label yourself in the view). Then you wouldn't really need the localization modules, if you extend res.country with fields telling what level means what in the respective country, and if they apply at all. Based on that, you can hide the fields not relavant for the country selected

@antespi
Copy link
Contributor Author

antespi commented Jun 11, 2015

@hbrunn sorry for my late answer and thanks for your review. I'm following your instructions to provide a correct label depending on partner country.

In the other hand, we need localization modules for these reasons:

  • We have to relate state_ids with NUTS items. Each localization defines an addons to add state_ids and each one use its nomenclature. Not always match with NUTS items. We can not use an extension of res.country, we need a map, look at spainsh one for example: https://github.com/Antiun/l10n-spain/blob/pr-add_l10n_es_location_nuts/l10n_es_location_nuts/wizard/nuts_import.py
  • In one country state_ids match with NUTS level 4 (spain) and other match with NUTS level 2 (germany). Locallization addon define this match and implement onchange rules (if apply)
  • Each localization team must be responsible of these relations, if they change toponyms addons must change it nuts addons properly.

@antespi
Copy link
Contributor Author

antespi commented Jun 11, 2015

@hbrunn i've just finished the fix you commented. Now when country changes, labels changed dinamically, and localization addons can change labels properly. There are specific labels for each country, and each addon can translate them to each language.

For testing, I recommend to install:

@antespi antespi force-pushed the pr-add_base_location_nuts branch from 9885d9e to fa33991 Compare July 9, 2015 17:52
@rafaelbn
Copy link
Member

👍

@rafaelbn
Copy link
Member

Hi @OSguard @bealdav @pedrobaeza @hbrunn , please could you review this PR, changes are done from June and module it's working fine in production environment. Thanks

.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

NUTS Regions
Copy link
Member

Choose a reason for hiding this comment

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

Put top line

@pedrobaeza
Copy link
Member

I re-check for new conventions on README, and few remarks. Honor that remarks and answer the question from @hbrunn, and I'll merge it.

lbl_substate = fields.Char(compute='_labels_get')

@api.one
@api.depends('country_id')
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry but I don't understand the meaning of this api.depends since your labels are computed by the translation tools.
Even if you change the country, your labels will stay the same since they depend of the language of the connected user. Maybe I miss something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lmignon each country define what 'region' and 'substate' fields mean. For example:

  • Spain:
    • substate = 'Autonomous Community'
    • region = 'Region'
  • Germany
    • substate = 'Government region'
    • region = 'District'

This depends on NUTS classification and which NUTS level is related with Odoo res.country.state. Each localization project (l10n-spain, l10n-germany, ...) creates their res.country.state objects

After this, you can translate labels, of course. For example, in spanish will be:

  • España (Spain):
    • substate = 'Comunidad autónoma'
    • region = 'Región'
  • Alemania (Germany)
    • substate = 'Región de gobierno'
    • region = 'Distrito'

Copy link
Member

Choose a reason for hiding this comment

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

But what you will get is the same label for all customers, independently of their country. Ideally, you should get the correct label for the country language. This is similar to the address layout depending on the selected country.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, you have to see these other PRs to understand this:

This is not only country dependant, but also localization dependant, that's why this is not a country config parameter

@pedrobaeza, you'll will have diferent labels in different partners if country is different. In examples:

  • Partner A: Germany country, labels 'Government region' and 'Region'
  • Partner B: Spain country, labels 'Autonomous Community' and 'Region'

Copy link
Member

Choose a reason for hiding this comment

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

Put a comment on the method then indicating that each localization module will inherit this method to add their specific labels.

@antespi
Copy link
Contributor Author

antespi commented Aug 27, 2015

@pedrobaeza, remarks and version number fixed, squash and rebase. Thanks for your review

@rafaelbn
Copy link
Member

rafaelbn commented Oct 6, 2015

This modules has been in customer's production environment for over 3 months. Tested! 👍
Any technical remarks?

pedrobaeza added a commit that referenced this pull request Oct 6, 2015
@pedrobaeza pedrobaeza merged commit 395eb93 into OCA:8.0 Oct 6, 2015
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.

7 participants