From d223a5638974e7bd2b803c0505bfab57b79e39db Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Mon, 27 May 2024 18:41:10 +0200 Subject: [PATCH] [ADD] is_french on partners and countries + views priority --- l10n_fr_association/__init__.py | 1 + l10n_fr_association/__manifest__.py | 3 +- l10n_fr_association/hooks.py | 40 +++++++++++++++++++ l10n_fr_association/i18n/fr.po | 39 +++++++++++++++++- l10n_fr_association/models/__init__.py | 1 + l10n_fr_association/models/res_country.py | 10 +++++ l10n_fr_association/models/res_partner.py | 16 ++------ l10n_fr_association/views/res_country.xml | 30 ++++++++++++++ l10n_fr_association/views/res_partner.xml | 5 +++ .../views/res_partner_relation_type.xml | 2 + 10 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 l10n_fr_association/hooks.py create mode 100644 l10n_fr_association/models/res_country.py create mode 100644 l10n_fr_association/views/res_country.xml diff --git a/l10n_fr_association/__init__.py b/l10n_fr_association/__init__.py index a0fdc10..ab4d630 100644 --- a/l10n_fr_association/__init__.py +++ b/l10n_fr_association/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- from . import models +from .hooks import post_init_hook diff --git a/l10n_fr_association/__manifest__.py b/l10n_fr_association/__manifest__.py index 8f997a8..a67fd6f 100644 --- a/l10n_fr_association/__manifest__.py +++ b/l10n_fr_association/__manifest__.py @@ -27,6 +27,7 @@ # Security "security/ir.model.access.csv", # Views + "views/res_country.xml", "views/res_partner.xml", "views/res_partner_relation_instance.xml", "views/res_partner_relation_type.xml", @@ -41,6 +42,6 @@ "installable": True, "maintainer": "RemiFr82", "pre_init_hook": "", - "post_init_hook": "", + "post_init_hook": "post_init_hook", "uninstall_hook": "", } diff --git a/l10n_fr_association/hooks.py b/l10n_fr_association/hooks.py new file mode 100644 index 0000000..4d366c5 --- /dev/null +++ b/l10n_fr_association/hooks.py @@ -0,0 +1,40 @@ +import logging + +from odoo.api import Environment, SUPERUSER_ID + +_logger = logging.getLogger(__name__) + + +# def pre_init_hook(cr, registry): +# env = Environment(cr, SUPERUSER_ID, {}) +# _logger.info("Pre init hook") + + +def post_init_hook(cr, registry): + env = Environment(cr, SUPERUSER_ID, {}) + env["res.country"].search( + [ + ( + "code", + "in", + ( + "FR", + "GP", + "MQ", + "GF", + "RE", + "YT", + ), + ) + ] + ).write( + { + "is_french": True, + } + ) + _logger.info("\n#####\nPost init hook for french associations passed...\n#####\n") + + +# def uninstall_hook(cr, registry): +# env = Environment(cr, SUPERUSER_ID, {}) +# _logger.info("Uninstall hook") diff --git a/l10n_fr_association/i18n/fr.po b/l10n_fr_association/i18n/fr.po index 8e11bc3..e7ed65b 100644 --- a/l10n_fr_association/i18n/fr.po +++ b/l10n_fr_association/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 16.0-20230613\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-05-26 22:57+0000\n" -"PO-Revision-Date: 2024-05-26 22:57+0000\n" +"POT-Creation-Date: 2024-05-27 16:13+0000\n" +"PO-Revision-Date: 2024-05-27 16:13+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -96,6 +96,16 @@ msgstr "C.A." msgid "Councile" msgstr "Conseil d'Administration" +#. module: l10n_fr_association +#: model:ir.model,name:l10n_fr_association.model_res_country +msgid "Country" +msgstr "Pays" + +#. module: l10n_fr_association +#: model_terms:ir.ui.view,arch_db:l10n_fr_association.res_country_view_search +msgid "Country Group" +msgstr "Groupe de pays" + #. module: l10n_fr_association #: model:ir.model.fields,field_description:l10n_fr_association.field_res_partner_relation_instance__create_uid msgid "Created by" @@ -139,11 +149,31 @@ msgstr "Employé" msgid "Error ! You cannot create recursive instances." msgstr "Erreur ! vous ne pouvez pas créer des instances recursives." +#. module: l10n_fr_association +#: model_terms:ir.ui.view,arch_db:l10n_fr_association.res_country_view_search +msgid "Europe" +msgstr "" + #. module: l10n_fr_association #: model_terms:ir.ui.view,arch_db:l10n_fr_association.view_partner_form_inherit_base msgid "Foundation" msgstr "Fondation" +#. module: l10n_fr_association +#: model_terms:ir.ui.view,arch_db:l10n_fr_association.view_res_partner_filter_inherit_base +msgid "France" +msgstr "" + +#. module: l10n_fr_association +#: model_terms:ir.ui.view,arch_db:l10n_fr_association.res_country_view_search +msgid "French" +msgstr "Français" + +#. module: l10n_fr_association +#: model:ir.model.fields,field_description:l10n_fr_association.field_res_country__is_french +msgid "French country" +msgstr "Pays français" + #. module: l10n_fr_association #: model:ir.model.fields,field_description:l10n_fr_association.field_res_partner__is_french #: model:ir.model.fields,field_description:l10n_fr_association.field_res_users__is_french @@ -155,6 +185,11 @@ msgstr "Partenaire français" msgid "General Assembly" msgstr "Asemblée Ganérale" +#. module: l10n_fr_association +#: model_terms:ir.ui.view,arch_db:l10n_fr_association.view_res_partner_filter_inherit_base +msgid "Hexagon" +msgstr "Hexagone" + #. module: l10n_fr_association #: model:ir.model.fields,field_description:l10n_fr_association.field_res_partner_relation_instance__id msgid "ID" diff --git a/l10n_fr_association/models/__init__.py b/l10n_fr_association/models/__init__.py index b8b5ea8..cdf6926 100644 --- a/l10n_fr_association/models/__init__.py +++ b/l10n_fr_association/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from . import res_country from . import res_partner_relation_instance from . import res_partner_relation_type from . import res_partner diff --git a/l10n_fr_association/models/res_country.py b/l10n_fr_association/models/res_country.py new file mode 100644 index 0000000..eeee798 --- /dev/null +++ b/l10n_fr_association/models/res_country.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, api + + +class ResCountry(models.Model): + _inherit = "res.country" + + is_french = fields.Boolean( + string="French country", + ) diff --git a/l10n_fr_association/models/res_partner.py b/l10n_fr_association/models/res_partner.py index 654c559..66a9dff 100644 --- a/l10n_fr_association/models/res_partner.py +++ b/l10n_fr_association/models/res_partner.py @@ -7,7 +7,9 @@ class ResPartner(models.Model): association = fields.Boolean(string="Is an association") is_french = fields.Boolean( - string="French partner", compute="partner_is_french", store=True + string="French partner", + related="country_id.is_french", + store=True, ) constituent_ga_date = fields.Date( string="Consitutent GA", @@ -75,18 +77,6 @@ class ResPartner(models.Model): asso_project_filename = fields.Char("Assocation project filename", tracking="83") asso_project_update_date = fields.Date("Project update", tracking="83") - @api.depends("country_id") - def partner_is_french(self): - for partner in self: - partner.is_french = partner.country_id and partner.country_id.code in ( - "FR", - "GP", - "MQ", - "GF", - "RE", - "YT", - ) - @api.onchange("is_company", "country_id") def onchange_asso_is_french_company(self): if self.association and (not self.is_company or not self.is_french): diff --git a/l10n_fr_association/views/res_country.xml b/l10n_fr_association/views/res_country.xml new file mode 100644 index 0000000..6cd656e --- /dev/null +++ b/l10n_fr_association/views/res_country.xml @@ -0,0 +1,30 @@ + + + + + res.country.view.form.inherit + res.country + + 30 + + + + + + + + + res.country.view.search + res.country + + + + + + + + + + + + \ No newline at end of file diff --git a/l10n_fr_association/views/res_partner.xml b/l10n_fr_association/views/res_partner.xml index 2ff10ab..5784d7b 100644 --- a/l10n_fr_association/views/res_partner.xml +++ b/l10n_fr_association/views/res_partner.xml @@ -63,6 +63,7 @@ res.partner.view.form.inherit res.partner + 20 {'invisible': ['|',('is_company','=',False),('association','=',True)]} @@ -77,9 +78,13 @@ res.partner.view.search.inherit res.partner + 20 + + + diff --git a/l10n_fr_association/views/res_partner_relation_type.xml b/l10n_fr_association/views/res_partner_relation_type.xml index d06c582..652c2f3 100644 --- a/l10n_fr_association/views/res_partner_relation_type.xml +++ b/l10n_fr_association/views/res_partner_relation_type.xml @@ -5,6 +5,7 @@ res.partner.relation.type.view.form.inherit res.partner.relation.type + 20 @@ -26,6 +27,7 @@ res.partner.relation.type.view.tree.inherit res.partner.relation.type + 20