Browse Source

[IMP] ffck_commons

16.0
RemiFr82 7 months ago
parent
commit
06a8f86d2f
  1. 9
      ffck_commons/__manifest__.py
  2. 20
      ffck_commons/data/ffck_structure_type.xml
  3. 2
      ffck_commons/data/res_partner.xml
  4. 6
      ffck_commons/i18n/fr.po
  5. 12
      ffck_commons/models/ffck_structure_type.py
  6. 129
      ffck_commons/models/res_partner.py
  7. 52
      ffck_commons/views/ffck_structure_type.xml
  8. 41
      ffck_commons/views/res_partner.xml

9
ffck_commons/__manifest__.py

@ -11,16 +11,16 @@
"category": "Technical", "category": "Technical",
"depends": [ "depends": [
"base", "base",
"contacts",
"l10n_fr_association", "l10n_fr_association",
"partner_contact_email2",
"partner_contact_phones2",
"partner_firstname",
"partner_multi_relation",
"partner_contact_age_range", "partner_contact_age_range",
"partner_contact_birthdate", "partner_contact_birthdate",
"partner_contact_gender", "partner_contact_gender",
"partner_contact_email2",
"partner_contact_nationality", "partner_contact_nationality",
"partner_contact_personal_information_page", "partner_contact_personal_information_page",
"partner_contact_phones2",
"partner_firstname",
], ],
"data": [ "data": [
# Base data # Base data
@ -30,6 +30,7 @@
"security/ir.model.access.csv", "security/ir.model.access.csv",
# Views # Views
"views/res_partner.xml", "views/res_partner.xml",
"views/ffck_structure_type.xml",
# Wizards # Wizards
# 'wizards/ir_model_wizard.xml', # 'wizards/ir_model_wizard.xml',
# Reports # Reports

20
ffck_commons/data/ffck_structure_type.xml

@ -3,50 +3,50 @@
<data noupdate="1"> <data noupdate="1">
<record id="ffck_structure_type_ffck" model="ffck.structure.type"> <record id="ffck_structure_type_ffck" model="ffck.structure.type">
<field name="name">FFCK</field>
<field name="name">Fédération</field>
<field name="short">FFCK</field> <field name="short">FFCK</field>
<field name="scale">nat</field>
<field name="scale">1</field>
</record> </record>
<record id="ffck_structure_type_crck" model="ffck.structure.type"> <record id="ffck_structure_type_crck" model="ffck.structure.type">
<field name="name">CRCK</field>
<field name="name">Regional Committee</field>
<field name="short">CRCK</field> <field name="short">CRCK</field>
<field name="scale">reg</field>
<field name="scale">2</field>
<field name="parent_id" ref="ffck_structure_type_ffck" /> <field name="parent_id" ref="ffck_structure_type_ffck" />
</record> </record>
<record id="ffck_structure_type_cdck" model="ffck.structure.type"> <record id="ffck_structure_type_cdck" model="ffck.structure.type">
<field name="name">CDCK</field>
<field name="name">Departmental Committee</field>
<field name="short">CDCK</field> <field name="short">CDCK</field>
<field name="scale">dep</field>
<field name="scale">3</field>
<field name="parent_id" ref="ffck_structure_type_crck" /> <field name="parent_id" ref="ffck_structure_type_crck" />
</record> </record>
<record id="ffck_structure_type_club" model="ffck.structure.type"> <record id="ffck_structure_type_club" model="ffck.structure.type">
<field name="name">Affiliate member</field> <field name="name">Affiliate member</field>
<field name="short">CLUB</field> <field name="short">CLUB</field>
<field name="scale">loc</field>
<field name="scale">4</field>
<field name="parent_id" ref="ffck_structure_type_cdck" /> <field name="parent_id" ref="ffck_structure_type_cdck" />
</record> </record>
<record id="ffck_structure_type_agra" model="ffck.structure.type" forcecreate="0"> <record id="ffck_structure_type_agra" model="ffck.structure.type" forcecreate="0">
<field name="name">Type A agreed member</field> <field name="name">Type A agreed member</field>
<field name="short">AGRA</field> <field name="short">AGRA</field>
<field name="scale">loc</field>
<field name="scale">4</field>
<field name="parent_id" ref="ffck_structure_type_cdck" /> <field name="parent_id" ref="ffck_structure_type_cdck" />
</record> </record>
<record id="ffck_structure_type_agrb" model="ffck.structure.type" forcecreate="0"> <record id="ffck_structure_type_agrb" model="ffck.structure.type" forcecreate="0">
<field name="name">Type B agreed member</field> <field name="name">Type B agreed member</field>
<field name="short">AGRB</field> <field name="short">AGRB</field>
<field name="scale">loc</field>
<field name="scale">4</field>
<field name="parent_id" ref="ffck_structure_type_cdck" /> <field name="parent_id" ref="ffck_structure_type_cdck" />
</record> </record>
<record id="ffck_structure_type_conv" model="ffck.structure.type" forcecreate="0"> <record id="ffck_structure_type_conv" model="ffck.structure.type" forcecreate="0">
<field name="name">Conventioned member</field> <field name="name">Conventioned member</field>
<field name="short">CONV</field> <field name="short">CONV</field>
<field name="scale">loc</field>
<field name="scale">4</field>
<field name="parent_id" ref="ffck_structure_type_cdck" /> <field name="parent_id" ref="ffck_structure_type_cdck" />
</record> </record>

2
ffck_commons/data/res_partner.xml

@ -20,7 +20,7 @@
<field name="siret">78572437800050</field> <field name="siret">78572437800050</field>
<field name="ffck_network" eval="True" /> <field name="ffck_network" eval="True" />
<field name="partner_code">0</field> <field name="partner_code">0</field>
<field name="partner_scale">nat</field>
<field name="partner_scale">1</field>
<field name="ffck_structure_type_id" ref="ffck_structure_type_ffck" /> <field name="ffck_structure_type_id" ref="ffck_structure_type_ffck" />
</record> </record>

6
ffck_commons/i18n/fr.po

@ -134,6 +134,12 @@ msgstr "Informations licencié"
msgid "Local" msgid "Local"
msgstr "Locale" msgstr "Locale"
#. module: ffck_commons
#: model:ir.model.fields,field_description:ffck_commons.field_res_partner__license_partner_id
#: model:ir.model.fields,field_description:ffck_commons.field_res_users__license_partner_id
msgid "Local partner"
msgstr "Structure Locale"
#. module: ffck_commons #. 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_ffck_structure_type__name
msgid "Name" msgid "Name"

12
ffck_commons/models/ffck_structure_type.py

@ -1,13 +1,21 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from odoo import models, fields from odoo import models, fields
from .res_partner import SCALES
SCALES = [
("1", "National"),
("2", "Regional"),
("3", "Departmental"),
("4", "Local"),
("5", "Licensee"),
]
class FfckStructureType(models.Model): class FfckStructureType(models.Model):
_name = "ffck.structure.type" _name = "ffck.structure.type"
_description = "FFCK structure type" _description = "FFCK structure type"
_order = "scale, short, name, id"
name = fields.Char("Name", required=True)
name = fields.Char("Name", required=True, translate=True)
short = fields.Char("Short", required=True, index=True) short = fields.Char("Short", required=True, index=True)
scale = fields.Selection(SCALES, string="Scale", required=True) scale = fields.Selection(SCALES, string="Scale", required=True)
active = fields.Boolean(string="Active", default=True) active = fields.Boolean(string="Active", default=True)

129
ffck_commons/models/res_partner.py

@ -1,29 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from odoo import models, fields, api from odoo import models, fields, api
SCALES = [
("nat", "National"),
("reg", "Regional"),
("dep", "Departmental"),
("loc", "Local"),
("lic", "Licensee"),
]
from odoo.osv.expression import OR
from .ffck_structure_type import SCALES
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = "res.partner" _inherit = "res.partner"
@api.model
def _get_ffck_partner(self):
ffck = self.env.ref("ffck_commons.res_partner_ffck", raise_if_not_found=False)
main = self.env.ref("base.main_partner")
if main.ref == "FFCK":
if ffck.active:
ffck.write({"active": False})
return main
else:
return ffck
# Partner fields # Partner fields
ffck_network = fields.Boolean(string="FFCK network") ffck_network = fields.Boolean(string="FFCK network")
first_membership_date = fields.Date("Structure 1st membership") first_membership_date = fields.Date("Structure 1st membership")
@ -31,6 +14,8 @@ class ResPartner(models.Model):
partner_scale = fields.Selection( partner_scale = fields.Selection(
selection=SCALES, selection=SCALES,
string="Scale", string="Scale",
compute="_get_partner_scale",
store=True,
) )
ffck_structure_type_id = fields.Many2one( ffck_structure_type_id = fields.Many2one(
comodel_name="ffck.structure.type", string="Structure type" comodel_name="ffck.structure.type", string="Structure type"
@ -39,28 +24,43 @@ class ResPartner(models.Model):
# partner_code_editable = fields.Boolean(string="FFCK code editable", compute="_can_edit_partner_code") # partner_code_editable = fields.Boolean(string="FFCK code editable", compute="_can_edit_partner_code")
# FFCK # FFCK
ffck_partner_id = fields.Many2one( ffck_partner_id = fields.Many2one(
"res.partner",
comodel_name="res.partner",
string="FFCK partner", string="FFCK partner",
default=_get_ffck_partner,
ondelete="restrict", ondelete="restrict",
compute="_get_ffck_partner",
store=False,
) )
ffck_partner_code = fields.Char(string="FFCK", default="0", readonly=True) ffck_partner_code = fields.Char(string="FFCK", default="0", readonly=True)
# CRCK # CRCK
crck_partner_id = fields.Many2one( crck_partner_id = fields.Many2one(
"res.partner",
comodel_name="res.partner",
string="CRCK partner", string="CRCK partner",
index=True, index=True,
ondelete="restrict", ondelete="restrict",
compute="_get_crck_partner",
store=True,
) )
crck_partner_code = fields.Char(related="crck_partner_id.partner_code", store=True) crck_partner_code = fields.Char(related="crck_partner_id.partner_code", store=True)
# CDCK # CDCK
cdck_partner_id = fields.Many2one( cdck_partner_id = fields.Many2one(
"res.partner",
comodel_name="res.partner",
string="CDCK partner", string="CDCK partner",
index=True, index=True,
ondelete="restrict", ondelete="restrict",
compute="_get_cdck_partner",
store=True,
) )
cdck_partner_code = fields.Char(related="cdck_partner_id.partner_code", store=True) cdck_partner_code = fields.Char(related="cdck_partner_id.partner_code", store=True)
local_partner_id = fields.Many2one(
comodel_name="res.partner",
string="Local partner",
index=True,
ondelete="restrict",
domain=[("ffck_network", "=", True), ("partner_scale", "=", 4)],
)
local_partner_code = fields.Char(
related="local_partner_id.partner_code", store=True
)
@api.model @api.model
def name_search(self, name="", args=None, operator="ilike", limit=100): def name_search(self, name="", args=None, operator="ilike", limit=100):
@ -102,22 +102,85 @@ class ResPartner(models.Model):
result += super(ResPartner, record).name_get() result += super(ResPartner, record).name_get()
return result return result
# COMPUTES
@api.depends("company_type", "ffck_structure_type_id")
def _get_partner_scale(self):
for partner in self:
if partner.company_type == "individual":
partner.partner_scale = "5"
else:
partner.partner_scale = (
partner.ffck_structure_type_id
and partner.ffck_structure_type_id.scale
)
def _get_ffck_partner(self):
ffck = self.env.ref("ffck_commons.res_partner_ffck", raise_if_not_found=False)
main = self.env.ref("base.main_partner")
for partner in self:
if main.ref == "FFCK":
if ffck and ffck.active:
ffck.write({"active": False})
partner.ffck_partner_id = main
else:
partner.ffck_partner_id = ffck
@api.depends("state_id", "ffck_network", "partner_scale")
def _get_crck_partner(self):
states = self.mapped("state_id")
crck_ok = self.search(
[
("ffck_network", "=", True),
("partner_scale", "=", "2"),
("state_id", "in", states.ids),
]
)
crck_by_state = {(crck.state_id, crck) for crck in crck_ok}
states_ok = states - crck_ok.mapped("state_id")
concerned = self.filtered(
lambda rp: rp.ffck_network
and int(rp.partner_scale) >= 3
and rp.state_id in states_ok
)
for partner in concerned:
state = partner.state_id
partner.crck_partner_id = crck_by_state[state]
# treat unconcerned
for partner in self - concerned:
partner.crck_partner_id = False
@api.depends("country_department_id", "ffck_network", "partner_scale")
def _get_cdck_partner(self):
depts = self.mapped("country_department_id")
cdck_ok = self.search(
[
("ffck_network", "=", True),
("partner_scale", "=", "4"),
("country_department_id", "in", depts.ids),
]
)
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) >= 4
and rp.country_department_id in depts_ok
)
for partner in concerned:
dept = partner.country_department_id
partner.cdck_partner_id = cdck_by_dept[dept]
# treat unconcerned
for partner in self - concerned:
partner.cdck_partner_id = False
# ONCHANGES # ONCHANGES
@api.onchange("partner_code", "company_type", "ffck_network") @api.onchange("partner_code", "company_type", "ffck_network")
def onchange_partner_code(self): def onchange_partner_code(self):
if self.ffck_network and self.company_type == "individual":
if self.ffck_network and self.is_company == False:
code = self.partner_code code = self.partner_code
if len(code) < 6: if len(code) < 6:
self.update({"partner_code": code.zfill(6)}) self.update({"partner_code": code.zfill(6)})
elif len(code) > 6: elif len(code) > 6:
self.update({"partner_code": code[:-6]}) self.update({"partner_code": code[:-6]})
@api.onchange("company_type", "partner_scale", "ffck_structure_type_id")
def onchange_comp_type(self):
if self.company_type == "individual":
self.update({"partner_scale": "lic"})
elif self.partner_scale == "lic":
self.update({"partner_scale": False})
elif self.ffck_structure_type_id:
self.update({"partner_scale": self.ffck_structure_type_id.scale})

52
ffck_commons/views/ffck_structure_type.xml

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="ffck_structure_type_view_form" model="ir.ui.view">
<field name="name">ffck.structure.type.view.form</field>
<field name="model">ffck.structure.type</field>
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_title">
<field name="name" />
</div>
<group col="4">
<field name="short" />
<field name="scale" />
<field name="parent_id" colspan="4" options="{'no_create':1}" />
</group>
</sheet>
</form>
</field>
</record>
<record id="ffck_structure_type_view_tree" model="ir.ui.view">
<field name="name">ffck.structure.type.view.tree</field>
<field name="model">ffck.structure.type</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="short" />
<field name="scale" />
<field name="parent_id" colspan="4" options="{'no_create':1}" />
</tree>
</field>
</record>
<record id="ffck_structure_type_action" model="ir.actions.act_window">
<field name="name">FFCK structure types</field>
<field name="res_model">ffck.structure.type</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="context">{}</field>
</record>
<menuitem
id="ffck_structure_type_menu"
name="Structure types"
action="ffck_structure_type_action"
groups="base.group_system"
parent="ffck_contacts_config_menu"
sequence="4" />
</odoo>

41
ffck_commons/views/res_partner.xml

@ -22,7 +22,8 @@
attrs="{'invisible': [('is_company','=',True)]}" /> attrs="{'invisible': [('is_company','=',True)]}" />
<label for="partner_code" string="Structure code" <label for="partner_code" string="Structure code"
attrs="{'invisible': [('is_company','=',False)]}" /> attrs="{'invisible': [('is_company','=',False)]}" />
<field name="partner_code" nolabel="1" />
<field name="partner_code" nolabel="1" readonly="1" />
<!-- <field name="partner_code" groups="base.group_no_one" /> -->
<!-- <field name="partner_code" nolabel="1" attrs="{'readonly':[('partner_code_editable','=',False)]}" /> <!-- <field name="partner_code" nolabel="1" attrs="{'readonly':[('partner_code_editable','=',False)]}" />
<field name="partner_code_editable" invisible="1" /> --> <field name="partner_code_editable" invisible="1" /> -->
<field name="partner_scale" attrs="{'invisible': [('is_company','=',False)]}" /> <field name="partner_scale" attrs="{'invisible': [('is_company','=',False)]}" />
@ -30,10 +31,11 @@
attrs="{'invisible': [('is_company','=',False)]}" /> attrs="{'invisible': [('is_company','=',False)]}" />
</group> </group>
<group name="ffck_network" string="Network" class="o_label_nowrap" <group name="ffck_network" string="Network" class="o_label_nowrap"
attrs="{'invisible': [('partner_scale', '=', 'lic')]}">
attrs="{'invisible': [('partner_scale', '=', '5')]}">
<field name="ffck_partner_id" /> <field name="ffck_partner_id" />
<field name="crck_partner_id" attrs="{'invisible': [('partner_scale', '=', 'nat')]}" />
<field name="cdck_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['nat', 'reg'])]}" />
<field name="crck_partner_id" attrs="{'invisible': [('partner_scale', '=', '1')]}" />
<field name="cdck_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['1', '2'])]}" />
<field name="local_partner_id" attrs="{'invisible': [('partner_scale', 'in', ['1', '2', '3'])]}" />
</group> </group>
</group> </group>
<group name="ffck_membership"> <group name="ffck_membership">
@ -46,4 +48,35 @@
</field> </field>
</record> </record>
<record id="view_res_partner_filter_inherit_base" model="ir.ui.view">
<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="arch" type="xml">
<filter name="type_person" position="attributes">
<attribute name="string">Persons</attribute>
</filter>
<filter name="type_company" position="attributes">
<attribute name="string">Structures</attribute>
</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>
</field>
</record>
<menuitem
id="ffck_contacts_config_menu"
name="FFCK params"
parent="contacts.res_partner_menu_config"
sequence="4" />
<record id="partner_multi_relation.menu_res_partner_relation" model="ir.ui.menu">
<field name="parent_id" ref="contacts.res_partner_menu_config" />
<field name="sequence">4</field>
</record>
</odoo> </odoo>
Loading…
Cancel
Save