Browse Source

[ADD] res.partner.hierarchy

16.0
RemiFr82 7 months ago
parent
commit
923459e4e1
  1. 2
      ffck_commons/data/ffck_structure_type.xml
  2. 47
      ffck_commons/i18n/fr.po
  3. 1
      ffck_commons/models/__init__.py
  4. 127
      ffck_commons/models/res_partner.py
  5. 44
      ffck_commons/models/res_partner_hierarchy.py
  6. 5
      ffck_commons/security/ir.model.access.csv
  7. 38
      ffck_commons/views/res_partner.xml

2
ffck_commons/data/ffck_structure_type.xml

@ -3,7 +3,7 @@
<data noupdate="1">
<record id="ffck_structure_type_ffck" model="ffck.structure.type">
<field name="name">Fédération</field>
<field name="name">Federation</field>
<field name="short">FFCK</field>
<field name="scale">1</field>
</record>

47
ffck_commons/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 23:35+0000\n"
"PO-Revision-Date: 2024-05-26 23:35+0000\n"
"POT-Creation-Date: 2024-05-27 16:36+0000\n"
"PO-Revision-Date: 2024-05-27 16:36+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@ -63,6 +63,12 @@ msgstr "Créé le"
msgid "Departmental"
msgstr "Départementale"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__cdck_partner_ids
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__cdck_partner_ids
msgid "Departmental Comittees"
msgstr "Comités départementaux"
#. module: ffck_commons
#: model:ffck.structure.type,name:ffck_commons.ffck_structure_type_cdck
msgid "Departmental Committee"
@ -70,6 +76,7 @@ msgstr "Comité Départemental"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_ffck_structure_type__display_name
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner_hierarchy__display_name
msgid "Display Name"
msgstr "Nom d'affichage"
@ -84,7 +91,7 @@ msgstr ""
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__cdck_partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__crck_partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__local_partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__cdck_partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__crck_partner_code
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__local_partner_code
@ -130,13 +137,26 @@ msgstr "Types de structures"
msgid "Federation"
msgstr "Fédération"
#. module: ffck_commons
#: model_terms:ir.ui.view,arch_db:ffck_commons.view_res_partner_filter_inherit_base
msgid "Hierarchy"
msgstr "Hiérarchie"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__hierarchy_id
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__hierarchy_id
msgid "Hierarchy element"
msgstr "Hiérarchie"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_ffck_structure_type__id
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner_hierarchy__id
msgid "ID"
msgstr ""
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_ffck_structure_type____last_update
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner_hierarchy____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"
@ -178,8 +198,15 @@ msgstr "Locale"
msgid "Local partner"
msgstr "Structure locale"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__local_partner_ids
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__local_partner_ids
msgid "Local structures"
msgstr "Structures locales"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_ffck_structure_type__name
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner_hierarchy__name
msgid "Name"
msgstr "Nom"
@ -196,6 +223,7 @@ msgstr "Réseau fédéral"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_ffck_structure_type__parent_id
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner_hierarchy__parent_id
msgid "Parent"
msgstr ""
@ -204,6 +232,11 @@ msgstr ""
msgid "Partner scale"
msgstr "Échelle"
#. module: ffck_commons
#: model:ir.model,name:ffck_commons.model_res_partner_hierarchy
msgid "Partners hierarchy"
msgstr "Hiérarchie des partenaires"
#. module: ffck_commons
#: model_terms:ir.ui.view,arch_db:ffck_commons.view_res_partner_filter_inherit_base
msgid "Persons"
@ -215,6 +248,12 @@ msgstr "Personnes"
msgid "Regional"
msgstr "Régionale"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__crck_partner_ids
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__crck_partner_ids
msgid "Regional Comittees"
msgstr "Comités régionaux"
#. module: ffck_commons
#: model:ffck.structure.type,name:ffck_commons.ffck_structure_type_crck
msgid "Regional Committee"
@ -268,7 +307,7 @@ msgstr "Types de structure"
#. module: ffck_commons
#: model_terms:ir.ui.view,arch_db:ffck_commons.view_res_partner_filter_inherit_base
msgid "Structures"
msgstr "Structures"
msgstr ""
#. module: ffck_commons
#: model:ffck.structure.type,name:ffck_commons.ffck_structure_type_agra

1
ffck_commons/models/__init__.py

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import res_partner_hierarchy
from . import ffck_structure_type
from . import res_partner

127
ffck_commons/models/res_partner.py

@ -29,7 +29,7 @@ class ResPartner(models.Model):
string="FFCK partner",
ondelete="restrict",
compute="_get_ffck_partner",
store=False,
store=True,
)
ffck_partner_code = fields.Char(string="FFCK", default="0", readonly=True)
# CRCK
@ -62,6 +62,42 @@ class ResPartner(models.Model):
local_partner_code = fields.Char(
related="local_partner_id.partner_code", store=True
)
crck_partner_ids = fields.One2many(
comodel_name="res.partner",
inverse_name="ffck_partner_id",
domain=[("partner_scale", "=", "2")],
string="Regional Comittees",
)
cdck_partner_ids = fields.One2many(
comodel_name="res.partner",
inverse_name="crck_partner_id",
domain=[("partner_scale", "=", "3")],
string="Departmental Comittees",
)
local_partner_ids = fields.One2many(
comodel_name="res.partner",
inverse_name="cdck_partner_id",
domain=[("partner_scale", "=", "4")],
string="Local structures",
)
# Compute hierarchy for searchpanel
hierarchy_id = fields.Many2one(
comodel_name="res.partner.hierarchy",
string="Hierarchy element",
compute="_compute_partner_hierarchy",
store=True,
)
@api.depends("ffck_network", "partner_scale", "partner_code")
def _compute_partner_hierarchy(self):
for partner in self:
partner.hierarchy_id = (
partner.id
if partner.ffck_network
and int(partner.partner_scale) in range(1, 5)
and partner.partner_code
else False
)
@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
@ -81,6 +117,7 @@ class ResPartner(models.Model):
)
return super().name_search(name, args, operator, limit)
@api.depends("name", "ref", "partner_code")
def name_get(self):
result = []
ffck_partners = self.filtered("ffck_network")
@ -125,7 +162,7 @@ class ResPartner(models.Model):
@api.depends("state_id", "ffck_network", "partner_scale")
def _get_crck_partner(self):
states = self.mapped("state_id")
crck_ok = self.search(
crck_ok = self.with_context(active_test=False).search(
[
("ffck_network", "=", True),
("partner_scale", "=", "2"),
@ -146,30 +183,86 @@ class ResPartner(models.Model):
for partner in self - concerned:
partner.crck_partner_id = False
@api.depends("country_department_id", "ffck_network", "partner_scale")
@api.depends(
"is_company",
"ffck_network",
"partner_code",
"partner_scale",
"local_partner_id",
"local_partner_id.partner_code",
"country_department_id",
"country_department_id.code",
)
def _get_cdck_partner(self):
depts = self.mapped("country_department_id")
cdck_ok = self.search(
structures = self.filtered(
lambda rp: rp.is_company
and rp.ffck_network
and rp.partner_code
and len(rp.partner_code) >= 2
and int(rp.partner_scale) in (3, 4)
)
licensees = self.filtered(
lambda rp: not rp.is_company
and rp.ffck_network
and int(rp.partner_scale) == 5
and (
rp.local_partner_id
and rp.local_partner_id.cdck_partner_id
or rp.country_department_id
)
)
dept_codes = self.mapped(
lambda rp: rp.partner_code
and len(rp.partner_code) >= 2
and int(rp.partner_scale) in (3, 4)
and rp.partner_code[:2]
)
cdck_ok = self.with_context(active_test=False).search(
[
("ffck_network", "=", True),
("partner_scale", "=", "3"),
("country_department_id", "in", depts.ids),
("partner_code", "in", ["{}00".format(code) for code in dept_codes]),
]
)
cdck_by_dept = {cdck.country_department_id: cdck for cdck in cdck_ok}
depts_ok = depts & cdck_ok.mapped("country_department_id")
concerned = self.filtered(
lambda rp: rp.ffck_network
and int(rp.partner_scale) >= 3
and rp.country_department_id in depts_ok
)
for partner in concerned:
cdck_by_code = {cdck.partner_code[:2]: cdck for cdck in cdck_ok}
# Treat structures
for partner in structures:
partner.cdck_partner_id = cdck_by_code[partner.partner_code[:2]]
# Treat licensees
for partner in licensees:
dept = partner.country_department_id
partner.cdck_partner_id = cdck_by_dept[dept]
# treat unconcerned
for partner in self - concerned:
local = partner.local_partner_id
local_cd = local.cdck_partner_id
partner.cdck_partner_id = (
local_cd if local and local_cd else cdck_by_code[dept.code]
)
# treat others
for partner in self - (structures | licensees):
partner.cdck_partner_id = False
@api.depends(
"ffck_network",
"partner_scale",
"ffck_partner_id",
"crck_partner_id",
"cdck_partner_id",
"local_partner_id",
)
def _get_ffck_parent(self):
field_by_scale = {
"2": "ffck_partner_id",
"3": "crck_partner_id",
"4": "cdck_partner_id",
"5": "local_partner_id",
}
for partner in self:
if partner.ffck_network and int(partner.partner_scale) in range(2, 6):
partner.ffck_parent_id = getattr(
partner, field_by_scale[partner.partner_scale]
)
else:
partner.ffck_parent_id = False
# ONCHANGES
@api.onchange("partner_code", "company_type", "ffck_network")

44
ffck_commons/models/res_partner_hierarchy.py

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, tools
class ResPartnerRoot(models.Model):
_name = "res.partner.hierarchy"
_description = "Partners hierarchy"
_auto = False
name = fields.Char()
active = fields.Boolean()
parent_id = fields.Many2one("res.partner.hierarchy")
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute(
"""
CREATE OR REPLACE VIEW %s AS (
SELECT DISTINCT id AS id,
active as active,
CONCAT(partner_code, ' - ', ref) AS name,
NULL::int AS parent_id
FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '1' AND (ref IS NOT NULL OR name IS NOT NULL)
UNION ALL
SELECT DISTINCT id AS id,
active as active,
CONCAT(partner_code, ' - ', ref) AS name,
ffck_partner_id AS parent_id
FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '2' AND (ref IS NOT NULL OR name IS NOT NULL)
UNION ALL
SELECT DISTINCT id AS id,
active as active,
CONCAT(partner_code, ' - ', ref) AS name,
crck_partner_id AS parent_id
FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '3' AND (ref IS NOT NULL OR name IS NOT NULL)
UNION ALL
SELECT DISTINCT id AS id,
active as active,
CONCAT(partner_code, ' - ', ref) AS name,
cdck_partner_id AS parent_id
FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '4' AND (ref IS NOT NULL OR name IS NOT NULL)
)"""
% (self._table,)
)

5
ffck_commons/security/ir.model.access.csv

@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_ir_model_all,All ffck.structure.type,ffck_commons.model_ffck_structure_type,,1,0,0,0
access_ir_model_group_partner_manager,Partner manager ffck.structure.type,ffck_commons.model_ffck_structure_type,base.group_partner_manager,1,1,1,0
access_ffck_structure_type_all,All ffck.structure.type,ffck_commons.model_ffck_structure_type,,1,0,0,0
access_ffck_structure_type_group_partner_manager,Partner manager ffck.structure.type,ffck_commons.model_ffck_structure_type,base.group_partner_manager,1,1,1,0
access_res_partner_hierarchy_all,All res.partner.hierarchy,ffck_commons.model_res_partner_hierarchy,,1,0,0,0

38
ffck_commons/views/res_partner.xml

@ -5,6 +5,7 @@
<field name="name">res.partner.view.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority">30</field>
<field name="arch" type="xml">
<h1 position="after">
<field name="ffck_network" />
@ -12,7 +13,7 @@
</h1>
<xpath expr="//notebook/page[1]" position="after">
<page name="ffck" string="FFCK" attrs="{'invisible':[('ffck_network','!=',True)]}">
<group name="ffck_main">
<group name="ffck_main" col="3">
<group name="ffck_common" class="o_label_nowrap">
<separator colspan="2" string="Licensee information"
attrs="{'invisible':[('is_company','=',True)]}" />
@ -29,18 +30,24 @@
<field name="partner_scale" attrs="{'invisible': [('is_company','=',False)]}" />
<field name="ffck_structure_type_id" widget="selection"
attrs="{'invisible': [('is_company','=',False)]}" />
<separator string="Structure dates" colspan="2" />
<field name="first_membership_date" />
</group>
<group name="ffck_network" string="Network" class="o_label_nowrap"
<group name="ffck_network" colspan="2" string="Network" class="o_label_nowrap"
attrs="{'invisible': [('partner_scale', '=', '5')]}">
<field name="ffck_partner_id" />
<field name="crck_partner_id" attrs="{'invisible': [('partner_scale', '=', ['1', '2'])]}" />
<field name="cdck_partner_id" attrs="{'invisible': [('partner_scale', 'not in', ['4', '5'])]}" />
<field name="local_partner_id" attrs="{'invisible': [('partner_scale', '!=', '5')]}" />
</group>
</group>
<group name="ffck_membership">
<group string="Structure dates">
<field name="first_membership_date" />
<field name="ffck_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['1'])]}" />
<label for="crck_partner_ids" attrs="{'invisible': [('partner_scale', '!=', '1')]}" colspan="2" />
<field name="crck_partner_ids" attrs="{'invisible': [('partner_scale', '!=', '1')]}" mode="kanban"
nolabel="1" colspan="2" readonly="1" />
<field name="crck_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['1', '2'])]}" />
<label for="cdck_partner_ids" attrs="{'invisible': [('partner_scale', '!=', '2')]}" colspan="2" />
<field name="cdck_partner_ids" attrs="{'invisible': [('partner_scale', '!=', '2')]}" mode="kanban"
nolabel="1" colspan="2" readonly="1" />
<field name="cdck_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['1', '2', '3'])]}" />
<label for="local_partner_ids" attrs="{'invisible': [('partner_scale', '!=', '3')]}" colspan="2" />
<field name="local_partner_ids" attrs="{'invisible': [('partner_scale', '!=', '3')]}" mode="kanban"
nolabel="1" colspan="2" readonly="1" />
<field name="local_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['1', '2', '3', '4'])]}" />
</group>
</group>
</page>
@ -52,6 +59,7 @@
<field name="name">res.partner.view.search.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="priority">30</field>
<field name="arch" type="xml">
<filter name="type_person" position="attributes">
<attribute name="string">Persons</attribute>
@ -59,12 +67,20 @@
<filter name="type_company" position="attributes">
<attribute name="string">Structures</attribute>
</filter>
<filter name="inactive" position="after">
<filter name="active" string="Active" domain="[('active','=',True)]" />
</filter>
<group name="group_by" position="inside">
<separator />
<filter name="partner_scale" string="Partner scale" domain="[]" context="{'group_by' : 'partner_scale'}" />
<filter name="ffck_structure_type" string="Structure type"
context="{'group_by' : 'ffck_structure_type_id'}" />
</group>
<search position="inside">
<searchpanel>
<field name="hierarchy_id" string="Hierarchy" icon="fa-sitemap" enable_counters="1" expand="1" limit="0" />
</searchpanel>
</search>
</field>
</record>

Loading…
Cancel
Save