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
damdam-s committed Sep 25, 2024
1 parent b50587e commit 8e1535d
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 2 deletions.
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 @@ -89,6 +89,12 @@ msgstr "Partenaire avec le même SIREN"
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 @@ -85,6 +85,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 2024 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)
11 changes: 11 additions & 0 deletions l10n_fr_siret/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ def _address_fields(self):
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):
countries_show_siret = self.env["res.country"].search(
[("show_siret_fields", "=", True)]
)
for record in self:
record.show_siret_fields = record.country_id in countries_show_siret and (
record.is_company or record.parent_is_company
)

@api.depends("siren", "company_id")
def _compute_same_siren_partner_id(self):
Expand Down
3 changes: 3 additions & 0 deletions l10n_fr_siret/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ The warning banner is displayed on the partner form view if another 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.
13 changes: 13 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,19 @@ def setUp(self):
.id
)

def test_show_siret_fields(self):
partner1 = self.env["res.partner"].create(
{"name": "Test partner1", "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", "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-2024 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>
7 changes: 5 additions & 2 deletions l10n_fr_siret/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
<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="attrs"
>{'invisible': [('is_company', '=', False), ('parent_is_company', '=', False)]}</attribute>
>{'invisible': [('show_siret_fields', '=', False)]}</attribute>
</field>
<field name="siret" position="after">
<div
class="oe_edit_only"
attrs="{'invisible': [('is_company', '=', False), ('parent_is_company', '=', False)]}"
attrs="{'invisible': [('show_siret_fields', '=', False)]}"
colspan="2"
>
<label for="siren" />
Expand Down

0 comments on commit 8e1535d

Please sign in to comment.