Skip to content

Commit

Permalink
🗃️(dashboard) add company-related fields to the Entity model
Browse files Browse the repository at this point in the history
New fields include company_type, legal_form, trade_name, siret, naf, and address fields.
Validators for SIRET, NAF, and zip code have been integrated.
Factory methods and migrations are updated to support these additions.
  • Loading branch information
ssorin committed Jan 30, 2025
1 parent c113376 commit ce08da3
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dashboard/apps/core/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ class EntityFactory(factory.django.DjangoModelFactory):
"""Factory class for creating instances of the Entity model."""

name = factory.Faker("company")
legal_form = factory.Faker(
"random_element", elements=["SA", "SARL", "SAS", "SCOP", "EI"]
)
trade_name = factory.Faker("company")
siret = factory.Faker("numerify", text="##############")
naf = factory.Faker("bothify", text="####?", letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
address_1 = factory.Faker("street_address")
address_2 = factory.Faker("secondary_address")
address_zip_code = factory.Faker("postcode")
address_city = factory.Faker("city")

class Meta: # noqa: D106
model = Entity
Expand Down
104 changes: 104 additions & 0 deletions src/dashboard/apps/core/migrations/0004_entity_company_informations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Generated by Django 5.1.5 on 2025-01-30 09:02

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


class Migration(migrations.Migration):

dependencies = [
(
"qcd_core",
"0003_alter_deliverypoint_managers_alter_entity_proxy_for_and_more",
),
]

operations = [
migrations.AddField(
model_name="entity",
name="address_1",
field=models.CharField(
blank=True, max_length=255, null=True, verbose_name="address"
),
),
migrations.AddField(
model_name="entity",
name="address_2",
field=models.CharField(
blank=True, max_length=255, null=True, verbose_name="address complement"
),
),
migrations.AddField(
model_name="entity",
name="address_city",
field=models.CharField(
blank=True, max_length=255, null=True, verbose_name="city"
),
),
migrations.AddField(
model_name="entity",
name="address_zip_code",
field=models.CharField(
blank=True,
max_length=5,
null=True,
validators=[apps.core.validators.validate_zip_code],
verbose_name="zip code",
),
),
migrations.AddField(
model_name="entity",
name="company_type",
field=models.CharField(
choices=[
("ENTERPRISE", "Entreprise"),
("LOCAL_COLLECTIVITY", "Collectivité locale"),
("EPCI", "EPCI"),
("ASSOCIATION", "Association, copropriété, ..."),
],
default="ENTERPRISE",
max_length=50,
verbose_name="type",
),
),
migrations.AddField(
model_name="entity",
name="legal_form",
field=models.CharField(
blank=True,
help_text="SA, SARL …",
max_length=50,
null=True,
verbose_name="legal form",
),
),
migrations.AddField(
model_name="entity",
name="naf",
field=models.CharField(
blank=True,
max_length=5,
null=True,
validators=[apps.core.validators.validate_naf_code],
verbose_name="NAF code",
),
),
migrations.AddField(
model_name="entity",
name="siret",
field=models.CharField(
blank=True,
max_length=14,
null=True,
validators=[apps.core.validators.validate_siret],
verbose_name="SIRET",
),
),
migrations.AddField(
model_name="entity",
name="trade_name",
field=models.CharField(
blank=True, max_length=255, null=True, verbose_name="trade name"
),
),
]
53 changes: 53 additions & 0 deletions src/dashboard/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .abstract_models import DashboardBase
from .managers import DeliveryPointManager
from .validators import validate_naf_code, validate_siret, validate_zip_code


class Entity(DashboardBase):
Expand All @@ -22,6 +23,19 @@ class Entity(DashboardBase):
- proxy_for (ManyToManyField): self-referential relationship indicating proxies.
"""

ENTERPRISE: str = "ENTERPRISE"
LOCAL_COLLECTIVITY: str = "LOCAL_COLLECTIVITY"
EPCI: str = "EPCI"
ASSOCIATION: str = "ASSOCIATION"

# Used for the consent contract. Terms must be kept in French.
COMPANY_TYPE_CHOICE = [
(ENTERPRISE, "Entreprise"),
(LOCAL_COLLECTIVITY, "Collectivité locale"),
(EPCI, "EPCI"),
(ASSOCIATION, "Association, copropriété, ..."),
]

slug = AutoSlugField(_("slug"), populate_from="name", unique=True)
name = models.CharField(_("name"), max_length=64, unique=True)
users = models.ManyToManyField(
Expand All @@ -34,6 +48,45 @@ class Entity(DashboardBase):
symmetrical=False,
related_name="proxies",
)
company_type = models.CharField(
_("type"), max_length=50, choices=COMPANY_TYPE_CHOICE, default=ENTERPRISE
)
legal_form = models.CharField(
_("legal form"),
max_length=50,
help_text=_("SA, SARL …"),
blank=True,
null=True,
)
trade_name = models.CharField(
_("trade name"), max_length=255, blank=True, null=True
)
siret = models.CharField(
_("SIRET"),
max_length=14,
validators=[validate_siret],
blank=True,
null=True,
)
naf = models.CharField(
_("NAF code"),
validators=[validate_naf_code],
max_length=5,
blank=True,
null=True,
)
address_1 = models.CharField(_("address"), max_length=255, blank=True, null=True)
address_2 = models.CharField(
_("address complement"), max_length=255, blank=True, null=True
)
address_zip_code = models.CharField(
_("zip code"),
max_length=5,
validators=[validate_zip_code],
blank=True,
null=True,
)
address_city = models.CharField(_("city"), max_length=255, blank=True, null=True)

class Meta: # noqa: D106
verbose_name = "entity"
Expand Down

0 comments on commit ce08da3

Please sign in to comment.