From 60a47738f169abaf32ef44157db9c2c088a997f7 Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Thu, 18 Jul 2024 15:56:15 +0200 Subject: [PATCH] [IMP] l10n_fr_siret: warning for identical SIRET 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. --- l10n_fr_siret/README.rst | 8 ++- l10n_fr_siret/__manifest__.py | 2 +- l10n_fr_siret/models/res_partner.py | 66 ++++++++++++++------- l10n_fr_siret/readme/CONTRIBUTORS.md | 2 + l10n_fr_siret/readme/DESCRIPTION.md | 5 +- l10n_fr_siret/static/description/index.html | 20 +++++-- l10n_fr_siret/tests/test_fr_siret.py | 8 +++ l10n_fr_siret/views/res_partner.xml | 12 +++- 8 files changed, 91 insertions(+), 32 deletions(-) diff --git a/l10n_fr_siret/README.rst b/l10n_fr_siret/README.rst index 1c90d08f9..b565dd179 100644 --- a/l10n_fr_siret/README.rst +++ b/l10n_fr_siret/README.rst @@ -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| @@ -91,6 +93,8 @@ Contributors - Lionel Sausin (Numérigraphe) - Alexis de Lattre +- Vincent Van Rossem +- Maintainers ----------- diff --git a/l10n_fr_siret/__manifest__.py b/l10n_fr_siret/__manifest__.py index 450fce581..2f73f4167 100644 --- a/l10n_fr_siret/__manifest__.py +++ b/l10n_fr_siret/__manifest__.py @@ -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"], diff --git a/l10n_fr_siret/models/res_partner.py b/l10n_fr_siret/models/res_partner.py index 5a095b9da..97298c65c 100644 --- a/l10n_fr_siret/models/res_partner.py +++ b/l10n_fr_siret/models/res_partner.py @@ -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): @@ -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): diff --git a/l10n_fr_siret/readme/CONTRIBUTORS.md b/l10n_fr_siret/readme/CONTRIBUTORS.md index 1a0dbeee6..1ad210f39 100644 --- a/l10n_fr_siret/readme/CONTRIBUTORS.md +++ b/l10n_fr_siret/readme/CONTRIBUTORS.md @@ -1,2 +1,4 @@ - Lionel Sausin (Numérigraphe) \<\> - Alexis de Lattre \<\> +- Vincent Van Rossem \<\> +- diff --git a/l10n_fr_siret/readme/DESCRIPTION.md b/l10n_fr_siret/readme/DESCRIPTION.md index 53af2a77b..2862c6347 100644 --- a/l10n_fr_siret/readme/DESCRIPTION.md +++ b/l10n_fr_siret/readme/DESCRIPTION.md @@ -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) diff --git a/l10n_fr_siret/static/description/index.html b/l10n_fr_siret/static/description/index.html index 6affa0c7b..fb2304f03 100644 --- a/l10n_fr_siret/static/description/index.html +++ b/l10n_fr_siret/static/description/index.html @@ -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. @@ -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 } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -380,8 +381,11 @@

French company identity numbers SIRET/SIREN/NIC

  • 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

    Table of contents

    @@ -432,12 +436,16 @@

    Contributors

    Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +Odoo Community Association +

    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.

    diff --git a/l10n_fr_siret/tests/test_fr_siret.py b/l10n_fr_siret/tests/test_fr_siret.py index 62f52bb1e..1954d9d1f 100644 --- a/l10n_fr_siret/tests/test_fr_siret.py +++ b/l10n_fr_siret/tests/test_fr_siret.py @@ -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", @@ -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( diff --git a/l10n_fr_siret/views/res_partner.xml b/l10n_fr_siret/views/res_partner.xml index cb3ec6851..05ebfed5f 100644 --- a/l10n_fr_siret/views/res_partner.xml +++ b/l10n_fr_siret/views/res_partner.xml @@ -46,11 +46,21 @@
    +