Skip to content

Commit

Permalink
🗃️(dashboard) add administration and company fields to consent model
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ssorin committed Jan 23, 2025
1 parent dc41d4c commit dcf7d8c
Show file tree
Hide file tree
Showing 13 changed files with 708 additions and 2 deletions.
3 changes: 3 additions & 0 deletions env.d/dashboard
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ DJANGO_SUPERUSER_PASSWORD=admin
DJANGO_SUPERUSER_USERNAME=admin
[email protected]

# Control authority contact
DASHBOARD_CONTROL_AUTHORITY={"name": "QualiCharge", "address_1": "1 rue de test", "address_2": "", "zip_code": "75000", "city": "Paris", "represented_by": "John Doe", "email": "[email protected]"}
DASHBOARD_CONSENT_DONE_AT=Paris
1 change: 1 addition & 0 deletions src/dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to
- add consent form to manage consents of one or many entities
- add admin integration for Entity, DeliveryPoint and Consent
- add mass admin action (make revoked) for consents
- add validators for SIRET, NAF code and Zip code
- disallow mass action "delete" for consents in admin
- block the updates of all new data if a consent has the status `REVOKED`
- block the updates of all new data if a consent has the status `VALIDATED`
Expand Down
1 change: 1 addition & 0 deletions src/dashboard/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ django-environ = "==0.12.0"
django-extensions = "==3.2.3"
django-stubs = {extras = ["compatible-mypy"], version = "==5.1.2"}
gunicorn = "==23.0.0"
jsonschema = "==4.23.0"
psycopg = {extras = ["pool", "binary"], version = "==3.2.4"}
sentry-sdk = {extras = ["django"], version = "==2.20.0"}
whitenoise = "==6.8.2"
Expand Down
144 changes: 143 additions & 1 deletion src/dashboard/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Generated by Django 5.1.5 on 2025-01-22 15:24

import apps.consent.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("qcd_consent", "0003_alter_consent_managers_alter_consent_end_and_more"),
]

operations = [
migrations.AddField(
model_name="consent",
name="allows_daily_index_readings",
field=models.BooleanField(
default=False,
verbose_name="allow history of daily index readings in kWh",
),
),
migrations.AddField(
model_name="consent",
name="allows_load_curve",
field=models.BooleanField(
default=False,
verbose_name="allows history of load curve, at steps returned by Enedis",
),
),
migrations.AddField(
model_name="consent",
name="allows_max_daily_power",
field=models.BooleanField(
default=False,
verbose_name="allows historical maximum daily power in kVa or kWh ",
),
),
migrations.AddField(
model_name="consent",
name="allows_measurements",
field=models.BooleanField(
default=False, verbose_name="allows historical measurements in kWh"
),
),
migrations.AddField(
model_name="consent",
name="allows_technical_contractual_data",
field=models.BooleanField(
default=False,
verbose_name="allows the technical and contractual data available",
),
),
migrations.AddField(
model_name="consent",
name="company",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[apps.consent.validators.validate_company_schema],
verbose_name="company informations",
),
),
migrations.AddField(
model_name="consent",
name="company_representative",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[apps.consent.validators.validate_representative_schema],
verbose_name="company representative informations",
),
),
migrations.AddField(
model_name="consent",
name="control_authority",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[apps.consent.validators.validate_control_authority_schema],
verbose_name="control authority informations",
),
),
migrations.AddField(
model_name="consent",
name="done_at",
field=models.CharField(
blank=True, max_length=255, null=True, verbose_name="done at"
),
),
migrations.AddField(
model_name="consent",
name="is_authorized_signatory",
field=models.BooleanField(
default=False, verbose_name="the signatory is authorized"
),
),
migrations.AddField(
model_name="consent",
name="signed_at",
field=models.DateTimeField(
blank=True, null=True, verbose_name="signature date"
),
),
]
60 changes: 59 additions & 1 deletion src/dashboard/apps/consent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
from .exceptions import ConsentWorkflowError
from .managers import ConsentManager
from .utils import consent_end_date
from .validators import (
validate_company_schema,
validate_control_authority_schema,
validate_representative_schema,
)


class Consent(DashboardBase):
"""Represents the consent status for a given delivery point and user.
For contractual reason, a consent cannot be modified after it has the status
`VALIDATED` or `REVOKED`.
Attributes:
- AWAITING: Status indicating that the consent is awaiting validation.
- VALIDATED: Status indicating that the consent has been validated.
Expand Down Expand Up @@ -48,6 +56,56 @@ class Consent(DashboardBase):
end = models.DateTimeField(_("end date"), default=consent_end_date)
revoked_at = models.DateTimeField(_("revoked at"), null=True, blank=True)

# Contractual field of the company
company = models.JSONField(
_("company informations"),
blank=True,
null=True,
default=None,
validators=[validate_company_schema],
)

# Contractual field of the company representative
company_representative = models.JSONField(
_("company representative informations"),
blank=True,
null=True,
default=None,
validators=[validate_representative_schema],
)

# Contractual field of the control authority
control_authority = models.JSONField(
_("control authority informations"),
blank=True,
null=True,
default=None,
validators=[validate_control_authority_schema],
)

# specific authorization fields
is_authorized_signatory = models.BooleanField(
_("the signatory is authorized"), default=False
)
allows_measurements = models.BooleanField(
_("allows historical measurements in kWh"), default=False
)
allows_daily_index_readings = models.BooleanField(
_("allow history of daily index readings in kWh"), default=False
)
allows_max_daily_power = models.BooleanField(
_("allows historical maximum daily power in kVa or kWh "), default=False
)
allows_load_curve = models.BooleanField(
_("allows history of load curve, at steps returned by Enedis"), default=False
)
allows_technical_contractual_data = models.BooleanField(
_("allows the technical and contractual data available"), default=False
)

signed_at = models.DateTimeField(_("signature date"), blank=True, null=True)
done_at = models.CharField(_("done at"), max_length=255, blank=True, null=True)

# models.Manager() must be in first place to ensure django admin expectations.
objects = models.Manager()
active_objects = ConsentManager()
Expand Down Expand Up @@ -109,7 +167,7 @@ def _is_update_allowed(self) -> bool:
Workflow according to consent status:
- AWAITING:
- can be updated without restriction
- can be updated without restriction.
- VALIDATED
- if the status is updated to something other than REVOKED, an exception is
Expand Down
Loading

0 comments on commit dcf7d8c

Please sign in to comment.