Skip to content

Commit

Permalink
[IMP] l10n_fr_siret: warning for identical SIRET
Browse files Browse the repository at this point in the history
adds a warning banner on the partner form view either
- if another partner has the same SIRET,
- or if another partner has the same SIREN but different SIRET.
  • Loading branch information
vvrossem committed Jul 18, 2024
1 parent d9daa4b commit 60a4773
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 32 deletions.
8 changes: 6 additions & 2 deletions l10n_fr_siret/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ partners, but it doesn't verify its validity. This module
- 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.
- it adds a warning banner on the partner form view either

- if another partner has the same SIRET,
- or if another partner has the same SIREN but different SIRET.

|image1|

Expand Down Expand Up @@ -91,6 +93,8 @@ Contributors

- Lionel Sausin (Numérigraphe) <ls@numerigraphe.com>
- Alexis de Lattre <alexis.delattre@akretion.com>
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
-

Maintainers
-----------
Expand Down
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": "17.0.1.0.0",
"version": "17.0.1.1.0",
"category": "French Localization",
"author": "Numérigraphe,Akretion,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
Expand Down
66 changes: 46 additions & 20 deletions l10n_fr_siret/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ class Partner(models.Model):
)
same_siren_partner_id = fields.Many2one(
"res.partner",
compute="_compute_same_siren_partner_id",
compute="_compute_same_siren_siret_partner_id",
string="Partner with same SIREN",
compute_sudo=True,
)
same_siret_partner_id = fields.Many2one(
"res.partner",
compute="_compute_same_siren_siret_partner_id",
string="Partner with same SIRET",
compute_sudo=True,
)

@api.depends("siren", "nic")
def _compute_siret(self):
Expand All @@ -85,30 +91,50 @@ 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
@api.depends("siren", "siret", "company_id")
def _compute_same_siren_siret_partner_id(self):
for partner in self:
same_siren_partner_id = False
same_siret_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))
domain = partner._get_same_siren_siret_partner_id_domain("siren")
same_siren_partner = partner._find_same_siren_siret_partner(domain)
same_siren_partner_id = (
self.with_context(active_test=False).search(domain, limit=1)
).id or False
same_siren_partner.id if same_siren_partner else False
)

if partner.siret and not partner.parent_id:
domain = partner._get_same_siren_siret_partner_id_domain("siret")
same_siret_partner = partner._find_same_siren_siret_partner(domain)
same_siret_partner_id = (
same_siret_partner.id if same_siret_partner else False
)

partner.same_siren_partner_id = same_siren_partner_id
partner.same_siret_partner_id = same_siret_partner_id

def _get_same_siren_siret_partner_id_domain(self, field):
self.ensure_one()
domain = [
(field, "=", getattr(self, field)),
("parent_id", "=", False),
]
if self.company_id:
domain += [
"|",
("company_id", "=", False),
("company_id", "=", self.company_id.id),
]
# use _origin to deal with onchange()
partner_id = self._origin.id
if partner_id:
domain.append(("id", "!=", partner_id))
return domain

def _find_same_siren_siret_partner(self, domain):
self.ensure_one()
return self.with_context(active_test=False).search(domain, limit=1)

@api.constrains("siren", "nic")
def _check_siret(self):
Expand Down
2 changes: 2 additions & 0 deletions l10n_fr_siret/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Lionel Sausin (Numérigraphe) \<<ls@numerigraphe.com>\>
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
- Vincent Van Rossem \<<vincent.vanrossem@camptocamp.com>\>
-
5 changes: 3 additions & 2 deletions l10n_fr_siret/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ partners, but it doesn't verify its validity. This module
- 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.
- it adds a warning banner on the partner form view either
- if another partner has the same SIRET,
- or if another partner has the same SIREN but different SIRET.

![](static/description/partner_duplicate_warning.png)
20 changes: 14 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 (goodger@python.org)
: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 @@ -380,8 +381,11 @@ <h1 class="title">French company identity numbers SIRET/SIREN/NIC</h1>
<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>
<li>it adds a warning banner on the partner form view if another partner
has the same SIREN.</li>
<li>it adds a warning banner on the partner form view either<ul>
<li>if another partner has the same SIRET,</li>
<li>or if another partner has the same SIREN but different SIRET.</li>
</ul>
</li>
</ul>
<p><img alt="image1" src="https://raw.githubusercontent.com/OCA/l10n-france/17.0/l10n_fr_siret/static/description/partner_duplicate_warning.png" /></p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -432,12 +436,16 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Lionel Sausin (Numérigraphe) &lt;<a class="reference external" href="mailto:ls&#64;numerigraphe.com">ls&#64;numerigraphe.com</a>&gt;</li>
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
<li>Vincent Van Rossem &lt;<a class="reference external" href="mailto:vincent.vanrossem&#64;camptocamp.com">vincent.vanrossem&#64;camptocamp.com</a>&gt;</li>
<li></li>
</ul>
</div>
<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
8 changes: 8 additions & 0 deletions l10n_fr_siret/tests/test_fr_siret.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_siret(self):
self.assertEqual(partner2.siren, "555555556")
self.assertEqual(partner2.nic, "00011")
self.assertEqual(partner2.same_siren_partner_id, partner1)
self.assertEqual(partner2.same_siret_partner_id, partner1)
self.assertEqual(partner1.same_siren_partner_id, partner2)
self.assertEqual(partner1.same_siret_partner_id, partner2)
partner3 = self.env["res.partner"].create(
{
"name": "Test SIREN only",
Expand Down Expand Up @@ -105,9 +107,15 @@ def test_warn_banner_multi_company(self):
}
)
self.assertFalse(partner_company1.same_siren_partner_id)
self.assertFalse(partner_company1.same_siret_partner_id)
self.assertFalse(partner_company2.same_siren_partner_id)
self.assertFalse(partner_company2.same_siret_partner_id)
partner_company2.write({"company_id": False})
self.assertEqual(partner_company2.same_siren_partner_id, partner_company1)
self.assertFalse(partner_company2.same_siret_partner_id, partner_company1)
partner_company2.write({"nic": False})
self.assertEqual(partner_company2.same_siren_partner_id, partner_company1)
self.assertEqual(partner_company2.same_siret_partner_id, partner_company1)

def test_change_parent_id(self):
partner = self.env["res.partner"].create(
Expand Down
12 changes: 11 additions & 1 deletion l10n_fr_siret/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@
<field name="fiscal_country_codes" invisible="1" />
</xpath>
<div name="warning_tax" position="after">
<div
class="alert alert-warning"
role="alert"
name="warn_duplicate_siret"
invisible="not same_siret_partner_id"
>
Duplicate warning: partner <field
name="same_siret_partner_id"
/> has the same <b>SIRET</b>.
</div>
<div
class="alert alert-warning"
role="alert"
name="warn_duplicate_siren"
invisible="not same_siren_partner_id"
invisible="same_siret_partner_id or not same_siren_partner_id"
>
Duplicate warning: partner <field
name="same_siren_partner_id"
Expand Down

0 comments on commit 60a4773

Please sign in to comment.