Skip to content

Commit

Permalink
[MIG] l10n_fr_siret to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Dec 29, 2023
1 parent 1bf0b0e commit 2ce3310
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 104 deletions.
2 changes: 1 addition & 1 deletion l10n_fr_siret/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "French company identity numbers SIRET/SIREN/NIC",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "French Localization",
"author": "Numérigraphe,Akretion,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
Expand Down
12 changes: 9 additions & 3 deletions l10n_fr_siret/demo/partner_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
-->
<odoo noupdate="1">

<record id="base.res_partner_12" model="res.partner"> <!-- C2C -->
<record id="c2c_france" model="res.partner">
<field name="name">Camptocamp France SAS</field>
<field name="is_company" eval="True" />
<field name="street">18 rue du Lac Saint André</field>
<field name="zip">73370</field>
<field name="city">Le Bourget-du-Lac</field>
<field name="country_id" ref="base.fr" />
<field name="website">https://www.camptocamp.com/</field>
<field name="siren">433698578</field>
<field name="nic">00039</field>
<field name="company_registry">Chambery</field>
<field name="nic">00054</field>
</record>

</odoo>
7 changes: 0 additions & 7 deletions l10n_fr_siret/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,3 @@ class ResCompany(models.Model):
nic = fields.Char(
string="NIC", related="partner_id.nic", store=True, readonly=False
)
# company_registry field is definied in base module on res.company
company_registry = fields.Char(
string="Company Registry",
related="partner_id.company_registry",
store=True,
readonly=False,
)
145 changes: 73 additions & 72 deletions l10n_fr_siret/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,56 @@


class Partner(models.Model):
"""Add the French official company identity numbers SIREN, NIC and SIRET"""

_inherit = "res.partner"

siren = fields.Char(
string="SIREN",
size=9,
tracking=50,
help="The SIREN number is the official identity "
"number of the company in France. It composes "
"the first 9 digits of the SIRET number.",
)
nic = fields.Char(
string="NIC",
size=5,
tracking=51,
help="The NIC number is the official rank number "
"of this office in the company in France. It "
"composes the last 5 digits of the SIRET "
"number.",
)
# the original SIRET field is definied in l10n_fr
# We add an inverse method to make it easier to copy/paste a SIRET
# from an external source to the partner form view of Odoo
siret = fields.Char(
compute="_compute_siret",
inverse="_inverse_siret",
store=True,
precompute=True,
readonly=False,
help="The SIRET number is the official identity number of this "
"company's office in France. It is composed of the 9 digits "
"of the SIREN number and the 5 digits of the NIC number, ie. "
"14 digits.",
)
# company_registry is native since v16, cf
# https://github.com/OCA/l10n-france/issues/501
# Should we rename it... or stop using it ?
# company_registry = fields.Char(
# help="The name of official registry where this company was declared.",
# )

parent_is_company = fields.Boolean(
related="parent_id.is_company", string="Parent is a Company"
)
same_siren_partner_id = fields.Many2one(
"res.partner",
compute="_compute_same_siren_partner_id",
string="Partner with same SIREN",
compute_sudo=True,
)

@api.depends("siren", "nic")
def _compute_siret(self):
"""Concatenate the SIREN and NIC to form the SIRET"""
Expand All @@ -39,6 +85,31 @@ def _inverse_siret(self):
else:
rec.write({"siren": False, "nic": False})

@api.depends("siren", "company_id")
def _compute_same_siren_partner_id(self):
# Inspired by same_vat_partner_id from 'base' module
for partner in self:
same_siren_partner_id = False
if partner.siren and not partner.parent_id:
domain = [
("siren", "=", partner.siren),
("parent_id", "=", False),
]
if partner.company_id:
domain += [
"|",
("company_id", "=", False),
("company_id", "=", partner.company_id.id),
]
# use _origin to deal with onchange()
partner_id = partner._origin.id
if partner_id:
domain.append(("id", "!=", partner_id))
same_siren_partner_id = (
self.with_context(active_test=False).search(domain, limit=1)
).id or False
partner.same_siren_partner_id = same_siren_partner_id

@api.constrains("siren", "nic")
def _check_siret(self):
"""Check the SIREN's and NIC's keys (last digits)"""
Expand Down Expand Up @@ -94,73 +165,3 @@ def _address_fields(self):
res = super()._address_fields()
res.append("nic")
return res

siren = fields.Char(
string="SIREN",
size=9,
tracking=50,
help="The SIREN number is the official identity "
"number of the company in France. It composes "
"the first 9 digits of the SIRET number.",
)
nic = fields.Char(
string="NIC",
size=5,
tracking=51,
help="The NIC number is the official rank number "
"of this office in the company in France. It "
"composes the last 5 digits of the SIRET "
"number.",
)
# the original SIRET field is definied in l10n_fr
# We add an inverse method to make it easier to copy/paste a SIRET
# from an external source to the partner form view of Odoo
siret = fields.Char(
compute="_compute_siret",
inverse="_inverse_siret",
store=True,
precompute=True,
readonly=False,
help="The SIRET number is the official identity number of this "
"company's office in France. It is composed of the 9 digits "
"of the SIREN number and the 5 digits of the NIC number, ie. "
"14 digits.",
)
company_registry = fields.Char(
help="The name of official registry where this company was declared.",
)

parent_is_company = fields.Boolean(
related="parent_id.is_company", string="Parent is a Company"
)
same_siren_partner_id = fields.Many2one(
"res.partner",
compute="_compute_same_siren_partner_id",
string="Partner with same SIREN",
compute_sudo=True,
)

@api.depends("siren", "company_id")
def _compute_same_siren_partner_id(self):
# Inspired by same_vat_partner_id from 'base' module
for partner in self:
same_siren_partner_id = False
if partner.siren and not partner.parent_id:
domain = [
("siren", "=", partner.siren),
("parent_id", "=", False),
]
if partner.company_id:
domain += [
"|",
("company_id", "=", False),
("company_id", "=", partner.company_id.id),
]
# use _origin to deal with onchange()
partner_id = partner._origin.id
if partner_id:
domain.append(("id", "!=", partner_id))
same_siren_partner_id = (
self.with_context(active_test=False).search(domain, limit=1)
).id or False
partner.same_siren_partner_id = same_siren_partner_id
5 changes: 1 addition & 4 deletions l10n_fr_siret/post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

from stdnum.fr.siret import is_valid

from odoo import SUPERUSER_ID, api

logger = logging.getLogger(__name__)


def set_siren_nic(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
def set_siren_nic(env):
partners = (
env["res.partner"]
.with_context(active_test=False)
Expand Down
29 changes: 12 additions & 17 deletions l10n_fr_siret/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@
<field name="inherit_id" ref="l10n_fr.res_partner_form_l10n_fr" />
<field name="arch" type="xml">
<field name="siret" position="attributes">
<attribute name="readonly">parent_id != False</attribute>
<attribute
name="attrs"
operation="update"
>{'readonly': [('parent_id', '!=', False)], 'invisible': [('is_company', '=', False), ('parent_is_company', '=', False)]}</attribute>
name="invisible"
>'FR' not in fiscal_country_codes or (not is_company and not parent_is_company)</attribute>
</field>
<field name="siret" position="after">
<field
name="siren"
attrs="{'readonly': [('parent_id', '!=', False)], 'invisible': [('is_company', '=', False), ('parent_is_company', '=', False)]}"
readonly="parent_id != False"
invisible="'FR' not in fiscal_country_codes or (not is_company and not parent_is_company)"
/>
<field
name="nic"
attrs="{'invisible': [('is_company', '=', False), ('parent_is_company', '=', False)]}"
invisible="'FR' not in fiscal_country_codes or (not is_company and not parent_is_company)"
/>
<field name="parent_is_company" invisible="1" />
</field>
<field name="company_registry" position="attributes">
<attribute name="attrs" operation="update">
{'readonly': [('parent_id', '!=', False)], 'invisible': [('is_company', '=', False), ('parent_is_company', '=', False)]}
</attribute>
</field>
<field name="child_ids" position="attributes">
<attribute name="context" operation="update">
{'default_nic': nic}
Expand All @@ -40,22 +36,21 @@
>
<field
name="nic"
attrs="{'invisible': [('type','in', ('contact', 'private'))]}"
invisible="'FR' not in fiscal_country_codes or type in ('contact', 'private')"
/>
<field
name="siret"
attrs="{'invisible': [('type','in', ('contact', 'private'))]}"
invisible="'FR' not in fiscal_country_codes or type in ('contact', 'private')"
readonly="1"
/>
<field name="fiscal_country_codes" invisible="1" />
</xpath>
<div
attrs="{'invisible': [('same_vat_partner_id', '=', False)]}"
position="after"
>
<div name="warning_tax" position="after">
<div
class="alert alert-warning"
role="alert"
attrs="{'invisible': [('same_siren_partner_id', '=', False)]}"
name="warn_duplicate_siren"
invisible="not same_siren_partner_id"
>
Duplicate warning: partner <field
name="same_siren_partner_id"
Expand Down

0 comments on commit 2ce3310

Please sign in to comment.