Skip to content

Commit

Permalink
ADD: siren/siret fields are not displayed according to a boolean comp…
Browse files Browse the repository at this point in the history
…uted field
  • Loading branch information
barkat-matthias committed Jan 21, 2025
1 parent 2635afb commit 2a5033d
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 25 deletions.
26 changes: 15 additions & 11 deletions l10n_fr_siret/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ The **l10n_fr** module from the official addons adds a *SIRET* field on
partners, but it doesn't verify its validity. This module
**l10n_fr_siret** adds several features:

- the validity of the SIRET is checked using its checksum.
- it adds **SIREN** and **NIC** fields (reminder: SIREN + NIC = SIRET).
If you enter the SIRET, these 2 fields are automatically computed
from SIRET.
- multi-site companies have a single SIREN and one SIRET per site i.e.
one NIC per site. This module allows to enter a specific NIC on child
partners.
- it adds a warning banner on the partner form view if another partner
has the same SIREN.
- the validity of the SIRET is checked using its checksum.
- it adds **SIREN** and **NIC** fields (reminder: SIREN + NIC = SIRET).
If you enter the SIRET, these 2 fields are automatically computed from
SIRET.
- multi-site companies have a single SIREN and one SIRET per site i.e.
one NIC per site. This module allows to enter a specific NIC on child
partners.
- it adds a warning banner on the partner form view if another partner
has the same SIREN.

|image1|

Expand All @@ -67,6 +67,10 @@ specific company: is in the same company or is not attached to a
specific company, - if the partner is not attached to a specific
company: is in any company or not attached to a specific company.

On the country form, users will be able to select if SIREN/SIRET fields
have to be displayed or not on the partner's form when the country is
selected.

Bug Tracker
===========

Expand All @@ -89,8 +93,8 @@ Authors
Contributors
------------

- Lionel Sausin (Numérigraphe) <[email protected]>
- Alexis de Lattre <[email protected]>
- Lionel Sausin (Numérigraphe) <[email protected]>
- Alexis de Lattre <[email protected]>

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions l10n_fr_siret/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": [
"views/res_partner.xml",
"views/res_company.xml",
"views/res_country.xml",
],
"demo": ["demo/partner_demo.xml"],
"post_init_hook": "set_siren_nic",
Expand Down
6 changes: 6 additions & 0 deletions l10n_fr_siret/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ msgstr "Partenaire avec SIREN identique"
msgid "SIREN"
msgstr "SIREN"

#. module: l10n_fr_siret
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_partner__show_siret_fields
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_users__show_siret_fields
msgid "Show siret fields"
msgstr "Afficher les champs SIRET"

#. module: l10n_fr_siret
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_company__siret
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_partner__siret
Expand Down
6 changes: 6 additions & 0 deletions l10n_fr_siret/i18n/l10n_fr_siret.pot
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ msgstr ""
msgid "SIREN"
msgstr ""

#. module: l10n_fr_siret
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_partner__show_siret_fields
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_users__show_siret_fields
msgid "Show siret fields"
msgstr ""

#. module: l10n_fr_siret
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_company__siret
#: model:ir.model.fields,field_description:l10n_fr_siret.field_res_partner__siret
Expand Down
1 change: 1 addition & 0 deletions l10n_fr_siret/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import res_partner
from . import res_company
from . import res_country
11 changes: 11 additions & 0 deletions l10n_fr_siret/models/res_country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2025 Foodles (https://www.foodles.co/).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


from odoo import fields, models


class ResCountry(models.Model):
_inherit = "res.country"

show_siret_fields = fields.Boolean(default=True)
8 changes: 8 additions & 0 deletions l10n_fr_siret/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class Partner(models.Model):
string="Partner with same SIREN",
compute_sudo=True,
)
show_siret_fields = fields.Boolean(compute="_compute_show_siret_fields")

@api.depends("country_id", "is_company", "parent_is_company")
def _compute_show_siret_fields(self):
for record in self:
record.show_siret_fields = record.country_id.show_siret_fields and (
record.is_company or record.parent_is_company
)

@api.depends("siren", "nic")
def _compute_siret(self):
Expand Down
3 changes: 3 additions & 0 deletions l10n_fr_siret/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ partner: - has the same SIREN, - if the partner is attached to a
specific company: is in the same company or is not attached to a
specific company, - if the partner is not attached to a specific
company: is in any company or not attached to a specific company.

On the country form, users will be able to select if SIREN/SIRET fields have to be displayed or not
on the partner's form when the country is selected.
18 changes: 12 additions & 6 deletions l10n_fr_siret/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -375,8 +376,8 @@ <h1 class="title">French company identity numbers SIRET/SIREN/NIC</h1>
<ul class="simple">
<li>the validity of the SIRET is checked using its checksum.</li>
<li>it adds <strong>SIREN</strong> and <strong>NIC</strong> fields (reminder: SIREN + NIC = SIRET).
If you enter the SIRET, these 2 fields are automatically computed
from SIRET.</li>
If you enter the SIRET, these 2 fields are automatically computed from
SIRET.</li>
<li>multi-site companies have a single SIREN and one SIRET per site i.e.
one NIC per site. This module allows to enter a specific NIC on child
partners.</li>
Expand Down Expand Up @@ -409,6 +410,9 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
specific company: is in the same company or is not attached to a
specific company, - if the partner is not attached to a specific
company: is in any company or not attached to a specific company.</p>
<p>On the country form, users will be able to select if SIREN/SIRET fields
have to be displayed or not on the partner’s form when the country is
selected.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
Expand Down Expand Up @@ -437,7 +441,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
21 changes: 21 additions & 0 deletions l10n_fr_siret/tests/test_fr_siret.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ def setUp(self):
.id
)

def test_show_siret_fields(self):
partner1 = self.env["res.partner"].create(
{
"name": "Test partner1",
"is_company": True,
"country_id": self.env.ref("base.fr").id,
}
)
self.assertTrue(partner1.show_siret_fields)

def test_show_siret_fields_on_not_configured_country(self):
self.env.ref("base.be").show_siret_fields = False
partner1 = self.env["res.partner"].create(
{
"name": "Test partner1",
"is_company": True,
"country_id": self.env.ref("base.be").id,
}
)
self.assertFalse(partner1.show_siret_fields)

def test_siret(self):
partner1 = self.env["res.partner"].create(
{
Expand Down
19 changes: 19 additions & 0 deletions l10n_fr_siret/views/res_country.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2022-2025 Foodles (https://www.foodles.co/).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record model="ir.ui.view" id="res_country_form_l10n_fr">
<field name="name">res.country.form.siret</field>
<field name="model">res.country</field>
<field name="inherit_id" ref="base.view_country_form" />
<field name="priority">100</field>
<field name="arch" type="xml">
<field name="vat_label" position="after">
<field name="show_siret_fields" />
</field>
</field>
</record>

</odoo>
14 changes: 6 additions & 8 deletions l10n_fr_siret/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="l10n_fr.res_partner_form_l10n_fr" />
<field name="arch" type="xml">
<field name="siret" position="before">
<field name="show_siret_fields" invisible="1" />
</field>
<field name="siret" position="attributes">
<attribute name="readonly">parent_id != False</attribute>
<attribute
name="invisible"
>'FR' not in fiscal_country_codes or (not is_company and not parent_is_company)</attribute>
<attribute name="invisible">show_siret_fields == False</attribute>
</field>
<field name="siret" position="after">
<field
name="siren"
readonly="parent_id != False"
invisible="'FR' not in fiscal_country_codes or (not is_company and not parent_is_company)"
/>
<field
name="nic"
invisible="'FR' not in fiscal_country_codes or (not is_company and not parent_is_company)"
invisible="show_siret_fields == False"
/>
<field name="nic" invisible="show_siret_fields == False" />
<field name="parent_is_company" invisible="1" />
</field>
<field name="child_ids" position="attributes">
Expand Down

0 comments on commit 2a5033d

Please sign in to comment.