Browse Source

[ADD] ffck_commons module

16.0
RemiFr82 6 months ago
parent
commit
df2bab933d
  1. 0
      ffck_commons/__init__.py
  2. 53
      ffck_commons/__manifest__.py
  3. 49
      ffck_commons/data/ffck_structure_type.xml
  4. 20
      ffck_commons/data/res_partner.xml
  5. 1
      ffck_commons/models/__init__.py
  6. 14
      ffck_commons/models/ffck_structure_type.py
  7. 131
      ffck_commons/models/res_partner.py
  8. 42
      ffck_commons/views/res_partner.xml

0
ffck_commons/__init__.py

53
ffck_commons/__manifest__.py

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "FFCK commons",
"version": "1.0.0",
"summary": "",
"description": "",
"author": "RemiFr82",
"website": "https://remifr82.me",
"license": "AGPL-3",
"category": "Technical",
"depends": [
"base",
"partner_contact_email2",
"partner_contact_phones2",
"partner_firstname",
"partner_multi_relation",
"partner_contact_age_range",
"partner_contact_birthdate",
"partner_contact_gender",
"partner_contact_nationality",
"partner_contact_personal_information_page",
],
"data": [
# Base data
"data/ffck_structure_type.xml",
"data/res_partner.xml",
# Security
# 'security/res_groups.xml',
# Views
"views/res_partner.xml",
# Wizards
# 'wizards/ir_model_wizard.xml',
# Reports
# 'reports/report_assets.xml',
],
# 'assets': {
# 'web.report_assets_common': [
# 'ffck_color_paddles/static/src/scss/report_pdf.scss',
# ],
# },
"demo": [],
"auto_install": False,
"external_dependencies": [],
"application": True,
"css": [],
"images": [],
"installable": True,
"maintainer": "RemiFr82",
"pre_init_hook": "",
"post_init_hook": "",
"uninstall_hook": "",
}

49
ffck_commons/data/ffck_structure_type.xml

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="ffck_structure_type_ffck" model="ffck.structure.type">
<field name="name">FFCK</field>
<field name="short">FFCK</field>
<field name="scale">nat</field>
</record>
<record id="ffck_structure_type_crck" model="ffck.structure.type">
<field name="name">CRCK</field>
<field name="short">CRCK</field>
<field name="scale">reg</field>
</record>
<record id="ffck_structure_type_cdck" model="ffck.structure.type">
<field name="name">CDCK</field>
<field name="short">CDCK</field>
<field name="scale">dep</field>
</record>
<record id="ffck_structure_type_club" model="ffck.structure.type">
<field name="name">Affiliate member</field>
<field name="short">CLUB</field>
<field name="scale">loc</field>
</record>
<record id="ffck_structure_type_agra" model="ffck.structure.type" forcecreate="0">
<field name="name">Type A agreed member</field>
<field name="short">AGRA</field>
<field name="scale">loc</field>
</record>
<record id="ffck_structure_type_agrb" model="ffck.structure.type" forcecreate="0">
<field name="name">Type B agreed member</field>
<field name="short">AGRB</field>
<field name="scale">loc</field>
</record>
<record id="ffck_structure_type_conv" model="ffck.structure.type" forcecreate="0">
<field name="name">Conventioned member</field>
<field name="short">CONV</field>
<field name="scale">loc</field>
</record>
</data>
</odoo>

20
ffck_commons/data/res_partner.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="res_partner_ffck" model="res.partner" forcecreate="0">
<field name="name">Fédération Française Canoë-Kayak et Sports de Pagaie</field>
<field name="is_company" eval="True" />
<field name="street"></field>
<field name="street2"></field>
<field name="zip"></field>
<field name="city"></field>
<field name="country_id" ref="base.fr" />
<field name="vat"></field>
<field name="phone"></field>
<field name="email"></field>
<field name="website"></field>
</record>
</data>
</odoo>

1
ffck_commons/models/__init__.py

@ -0,0 +1 @@
from . import res_partner

14
ffck_commons/models/ffck_structure_type.py

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from odoo import models, fields
from .res_partner import SCALES
class FfckStructureType(models.Model):
_name = "ffck.structure.type"
_description = "FFCK structure type"
name = fields.Char("Name", required=True)
short = fields.Char("Short", required=True, index=True)
scale = fields.Selection(SCALES, string="Scale", required=True)
active = fields.Boolean(string="Active", default=True)
parent_id = fields.Many2one("ffck.structure.type", string="parent")

131
ffck_commons/models/res_partner.py

@ -0,0 +1,131 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.osv.expression import OR, AND
# STRUCTURE_TYPES = [
# ('ffck', 'Federal'),
# ('crck', 'Region'),
# ('cdck', 'Department'),
# ('club', 'Affiliate'),
# ('agra', 'Agreement A'),
# ('agrb', 'Agreement B'),
# ('conv', 'Convention'),
# ('asso', 'Associated'),
# ]
SCALES = [
("nat", "National"),
("reg", "Regional"),
("dep", "Departmental"),
("loc", "Local"),
("lic", "Licensee"),
]
class ResPartner(models.Model):
_inherit = "res.partner"
@api.model
def _get_ffck_partner(self):
ffck = self.env.ref("ffck_commons.ffck_partner")
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
structure_create_date = fields.Date("Structure creation")
# FFCK fields
ffck_network = fields.Boolean(string="FFCK network")
first_membership_date = fields.Date("Structure 1st membership")
# Structure typing
partner_scale = fields.Selection(
selection=SCALES,
string="Scale",
)
ffck_type_id = fields.Many2one(
comodel_name="ffck.structure.type", string="Structure type"
)
# structure_type = fields.Selection(
# selection=STRUCTURE_TYPES,
# string="Structure",
# )
ffck_partner_id = fields.Many2one(
"res.partner",
string="FFCK partner",
default=_get_ffck_partner,
ondelete="restrict",
)
ffck_code = fields.Char(string="FFCK", default="0", readonly=True)
crck_partner_id = fields.Many2one(
"res.partner", string="CRCK partner", index=True, ondelete="restrict"
)
crck_code = fields.Char(related="crck_partner_id.partner_code", store=True)
cdck_partner_id = fields.Many2one(
"res.partner", string="CDCK partner", index=True, ondelete="restrict"
)
cdck_code = fields.Char(related="cdck_partner_id.partner_code", store=True)
partner_code = fields.Char(string="FFCK code", size=6, index=True, readonly=True)
@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
"""Allow searching by sequence code by default."""
# Do not add any domain when user just clicked on search widget
if not (name == "" and operator == "ilike"):
# The dangling | is needed to combine with the domain added by super()
args = OR(
[
[
"&",
("ffck_network", "=", True),
("partner_code", "=like", name + "%"),
],
args or [],
]
)
return super().name_search(name, args, operator, limit)
def name_get(self):
result = []
# ffck_partners = self.filtered('ffck_network')
# others = self - ffck_partners
for record in self:
if record.ffck_network:
code = record.partner_code
ref = record.ref
result.append(
(
record.id,
"{}{}{}".format(
code and code + " - " or "",
ref and record.is_company and ref + " - " or "",
super(ResPartner, record).name_get()[0][1],
),
)
)
else:
result += super(ResPartner, record).name_get()
return result
# ONCHANGES
@api.onchange("partner_code")
def onchange_partner_code(self):
if self.ffck_network and self.company_type == "individual":
code = self.partner_code
if len(code) < 6:
self.update({"partner_code": code.zfill(6)})
elif len(code) > 6:
self.update({"partner_code": code[:-6]})
@api.onchange("company_type", "partner_scale", "ffck_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_type_id:
self.update({"partner_scale": self.ffck_type_id.scale})

42
ffck_commons/views/res_partner.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_partner_form_inherit_base" model="ir.ui.view">
<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="arch" type="xml">
<field name="company_type" position="after">
<field name="ffck_network" />
<label for="ffck_network" />
</field>
<xpath expr="//notebook/page[1]" position="before">
<page name="ffck_info" string="FFCK Info" attrs="{'invisible':[('ffck_network','!=',True)]}">
<group name="ffck_main">
<group name="ffck_common">
<separator colspan="2" string="Licensee information"
attrs="{'invisible':[('company_type','!=','individual')]}" />
<separator colspan="2" string="Structure information"
attrs="{'invisible':[('company_type','!=','company')]}" />
<field name="partner_code" />
<field name="partner_scale" attrs="{'invisible': [('company_type','=','individual')]}" />
<field name="ffck_type_id" widget="selection" attrs="{'invisible': [('company_type','=','individual')]}" />
</group>
<group name="ffck_network" string="Network" attrs="{'invisible': [('partner_scale', '=', 'lic')]}">
<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'])]}" />
</group>
</group>
<group name="ffck_data">
<group string="Structure dates">
<field name="structure_create_date" />
<field name="first_membership_date" />
</group>
</group>
</page>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save