Skip to content

Commit 7aa50f5

Browse files
committed
🗃️(dashboard) add administration and company fields to consent model
Introduced new fields in the Consent model to handle company and administration information, including validation for SIRET, NAF code, and zip code. Updated settings with configurable default values for these fields. Added core validators for ensuring data integrity in relevant fields.
1 parent dc41d4c commit 7aa50f5

File tree

12 files changed

+709
-2
lines changed

12 files changed

+709
-2
lines changed

src/dashboard/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to
2020
- add consent form to manage consents of one or many entities
2121
- add admin integration for Entity, DeliveryPoint and Consent
2222
- add mass admin action (make revoked) for consents
23+
- add validators for SIRET, NAF code and Zip code
2324
- disallow mass action "delete" for consents in admin
2425
- block the updates of all new data if a consent has the status `REVOKED`
2526
- block the updates of all new data if a consent has the status `VALIDATED`

src/dashboard/Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ django-environ = "==0.12.0"
1010
django-extensions = "==3.2.3"
1111
django-stubs = {extras = ["compatible-mypy"], version = "==5.1.2"}
1212
gunicorn = "==23.0.0"
13+
jsonschema = "==4.23.0"
1314
psycopg = {extras = ["pool", "binary"], version = "==3.2.4"}
1415
sentry-sdk = {extras = ["django"], version = "==2.20.0"}
1516
whitenoise = "==6.8.2"

src/dashboard/Pipfile.lock

Lines changed: 143 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Generated by Django 5.1.5 on 2025-01-22 15:24
2+
3+
import apps.consent.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("qcd_consent", "0003_alter_consent_managers_alter_consent_end_and_more"),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name="consent",
16+
name="allows_daily_index_readings",
17+
field=models.BooleanField(
18+
default=False,
19+
verbose_name="allow history of daily index readings in kWh",
20+
),
21+
),
22+
migrations.AddField(
23+
model_name="consent",
24+
name="allows_load_curve",
25+
field=models.BooleanField(
26+
default=False,
27+
verbose_name="allows history of load curve, at steps returned by Enedis",
28+
),
29+
),
30+
migrations.AddField(
31+
model_name="consent",
32+
name="allows_max_daily_power",
33+
field=models.BooleanField(
34+
default=False,
35+
verbose_name="allows historical maximum daily power in kVa or kWh ",
36+
),
37+
),
38+
migrations.AddField(
39+
model_name="consent",
40+
name="allows_measurements",
41+
field=models.BooleanField(
42+
default=False, verbose_name="allows historical measurements in kWh"
43+
),
44+
),
45+
migrations.AddField(
46+
model_name="consent",
47+
name="allows_technical_contractual_data",
48+
field=models.BooleanField(
49+
default=False,
50+
verbose_name="allows the technical and contractual data available",
51+
),
52+
),
53+
migrations.AddField(
54+
model_name="consent",
55+
name="company",
56+
field=models.JSONField(
57+
blank=True,
58+
null=True,
59+
validators=[apps.consent.validators.validate_company_schema],
60+
verbose_name="company informations",
61+
),
62+
),
63+
migrations.AddField(
64+
model_name="consent",
65+
name="company_representative",
66+
field=models.JSONField(
67+
blank=True,
68+
null=True,
69+
validators=[apps.consent.validators.validate_representative_schema],
70+
verbose_name="company representative",
71+
),
72+
),
73+
migrations.AddField(
74+
model_name="consent",
75+
name="control_authority",
76+
field=models.JSONField(
77+
blank=True,
78+
null=True,
79+
validators=[apps.consent.validators.validate_control_authority_schema],
80+
verbose_name="company representative",
81+
),
82+
),
83+
migrations.AddField(
84+
model_name="consent",
85+
name="done_at",
86+
field=models.CharField(
87+
blank=True, max_length=255, null=True, verbose_name="done at"
88+
),
89+
),
90+
migrations.AddField(
91+
model_name="consent",
92+
name="is_authorized_signatory",
93+
field=models.BooleanField(
94+
default=False, verbose_name="the signatory is authorized"
95+
),
96+
),
97+
migrations.AddField(
98+
model_name="consent",
99+
name="signed_at",
100+
field=models.DateTimeField(
101+
blank=True, null=True, verbose_name="signature date"
102+
),
103+
),
104+
]

src/dashboard/apps/consent/models.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
from .exceptions import ConsentWorkflowError
1111
from .managers import ConsentManager
1212
from .utils import consent_end_date
13+
from .validators import (
14+
validate_company_schema,
15+
validate_control_authority_schema,
16+
validate_representative_schema,
17+
)
1318

1419

1520
class Consent(DashboardBase):
1621
"""Represents the consent status for a given delivery point and user.
1722
23+
For contractual reason, a consent cannot be modified after it has the status
24+
`VALIDATED` or `REVOKED`.
25+
1826
Attributes:
1927
- AWAITING: Status indicating that the consent is awaiting validation.
2028
- VALIDATED: Status indicating that the consent has been validated.
@@ -48,6 +56,55 @@ class Consent(DashboardBase):
4856
end = models.DateTimeField(_("end date"), default=consent_end_date)
4957
revoked_at = models.DateTimeField(_("revoked at"), null=True, blank=True)
5058

59+
# Contractual field of the company
60+
# These fields are populated with data from the linked entity.
61+
company = models.JSONField(
62+
_("company informations"),
63+
blank=True,
64+
null=True,
65+
validators=[validate_company_schema],
66+
)
67+
68+
# Contractual field of the company representative
69+
# These fields are populated with the current user data.
70+
company_representative = models.JSONField(
71+
_("company representative"),
72+
blank=True,
73+
null=True,
74+
validators=[validate_representative_schema],
75+
)
76+
77+
# Contractual field of the control authority
78+
# These fields are populated via `settings.CONSENT_ADMINISTRATION_FIELDS`.
79+
control_authority = models.JSONField(
80+
_("company representative"),
81+
blank=True,
82+
null=True,
83+
validators=[validate_control_authority_schema],
84+
)
85+
86+
# Fields populated via the consent form
87+
is_authorized_signatory = models.BooleanField(
88+
_("the signatory is authorized"), default=False
89+
)
90+
allows_measurements = models.BooleanField(
91+
_("allows historical measurements in kWh"), default=False
92+
)
93+
allows_daily_index_readings = models.BooleanField(
94+
_("allow history of daily index readings in kWh"), default=False
95+
)
96+
allows_max_daily_power = models.BooleanField(
97+
_("allows historical maximum daily power in kVa or kWh "), default=False
98+
)
99+
allows_load_curve = models.BooleanField(
100+
_("allows history of load curve, at steps returned by Enedis"), default=False
101+
)
102+
allows_technical_contractual_data = models.BooleanField(
103+
_("allows the technical and contractual data available"), default=False
104+
)
105+
signed_at = models.DateTimeField(_("signature date"), blank=True, null=True)
106+
done_at = models.CharField(_("done at"), max_length=255, blank=True, null=True)
107+
51108
# models.Manager() must be in first place to ensure django admin expectations.
52109
objects = models.Manager()
53110
active_objects = ConsentManager()
@@ -109,7 +166,7 @@ def _is_update_allowed(self) -> bool:
109166
110167
Workflow according to consent status:
111168
- AWAITING:
112-
- can be updated without restriction
169+
- can be updated without restriction.
113170
114171
- VALIDATED
115172
- if the status is updated to something other than REVOKED, an exception is

0 commit comments

Comments
 (0)