Skip to content

Commit

Permalink
Merge branch 'feat/920_rename_production_site_type' into 'dev'
Browse files Browse the repository at this point in the history
feat(sites): rename 'PRODUCTION SITE' to 'PRODUCTION BIOLIQUID'

See merge request la-fabrique-numerique/biocarburants!262
  • Loading branch information
Yohann Ulreich committed Dec 5, 2024
2 parents 95babe0 + 575cd35 commit b3c065c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
2 changes: 1 addition & 1 deletion web/entity/api/production_sites/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def add_production_site(request, entity, entity_id):
manager_email=manager_email,
date_mise_en_service=date_mise_en_service,
ges_option=ges_option,
site_type=ProductionSite.PRODUCTION_SITE,
site_type=ProductionSite.PRODUCTION_BIOLIQUID,
)

if site:
Expand Down
2 changes: 1 addition & 1 deletion web/fixtures/json/productionsites.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions web/resources/tests/tests_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,28 @@ def test_get_production_sites(self):
fr, _ = Pays.objects.update_or_create(name="France", code_pays="FR")
today = datetime.date.today()
Site.objects.update_or_create(
site_type=Site.PRODUCTION_SITE,
site_type=Site.PRODUCTION_BIOLIQUID,
name="Usine1",
created_by_id=producer.id,
country=fr,
date_mise_en_service=today,
)
Site.objects.update_or_create(
site_type=Site.PRODUCTION_SITE,
site_type=Site.PRODUCTION_BIOLIQUID,
name="Usine2",
created_by_id=producer.id,
country=fr,
date_mise_en_service=today,
)
Site.objects.update_or_create(
site_type=Site.PRODUCTION_SITE,
site_type=Site.PRODUCTION_BIOLIQUID,
name="Usine3",
created_by_id=producer.id,
country=fr,
date_mise_en_service=today,
)
Site.objects.update_or_create(
site_type=Site.PRODUCTION_SITE,
site_type=Site.PRODUCTION_BIOLIQUID,
name="Usine4",
created_by_id=other_producer.id,
country=fr,
Expand Down
38 changes: 38 additions & 0 deletions web/transactions/migrations/0008_alter_site_site_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.0.6 on 2024-12-05 09:25

from django.db import migrations, models


def update_site_type(apps, schema_editor):
Site = apps.get_model("transactions", "Site")
Site.objects.filter(site_type="PRODUCTION SITE").update(site_type="PRODUCTION BIOLIQUID")


class Migration(migrations.Migration):
dependencies = [
("transactions", "0007_depot_productionsite"),
]

operations = [
migrations.AlterField(
model_name="site",
name="site_type",
field=models.CharField(
choices=[
("OTHER", "Autre"),
("EFS", "EFS"),
("EFPE", "EFPE"),
("OIL DEPOT", "OIL DEPOT"),
("BIOFUEL DEPOT", "BIOFUEL DEPOT"),
("HEAT PLANT", "HEAT PLANT"),
("POWER PLANT", "POWER PLANT"),
("COGENERATION PLANT", "COGENERATION PLANT"),
("PRODUCTION BIOLIQUID", "PRODUCTION BIOLIQUID"),
("EFCA", "EFCA"),
],
default="OTHER",
max_length=32,
),
),
migrations.RunPython(update_site_type),
]
2 changes: 1 addition & 1 deletion web/transactions/models/production_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class ProductionSiteManager(SiteManager):
def get_queryset(self):
return super().get_queryset().filter(site_type=Site.PRODUCTION_SITE)
return super().get_queryset().filter(site_type__in=Site.PRODUCTION_SITE_TYPES)


class ProductionSite(Site):
Expand Down
13 changes: 6 additions & 7 deletions web/transactions/models/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Site(models.Model):
HEAT_PLANT = "HEAT PLANT"
POWER_PLANT = "POWER PLANT"
COGENERATION_PLANT = "COGENERATION PLANT"
PRODUCTION_SITE = "PRODUCTION SITE"
PRODUCTION_BIOLIQUID = "PRODUCTION BIOLIQUID"
EFCA = "EFCA"

SITE_TYPE = (
Expand All @@ -29,11 +29,12 @@ class Site(models.Model):
(HEAT_PLANT, "HEAT PLANT"),
(POWER_PLANT, "POWER PLANT"),
(COGENERATION_PLANT, "COGENERATION PLANT"),
(PRODUCTION_SITE, "PRODUCTION SITE"),
(PRODUCTION_BIOLIQUID, "PRODUCTION BIOLIQUID"),
(EFCA, "EFCA"),
)

DEPOT_TYPES = [OTHER, EFS, EFPE, OILDEPOT, BIOFUELDEPOT, HEAT_PLANT, POWER_PLANT, COGENERATION_PLANT, EFCA]
PRODUCTION_SITE_TYPES = [PRODUCTION_BIOLIQUID]

GES_OPTIONS = [("Default", "Valeurs par défaut"), ("Actual", "Valeurs réelles"), ("NUTS2", "Valeurs NUTS2")]

Expand Down Expand Up @@ -107,13 +108,11 @@ def clean(self):
setattr(self, field, None)

# Check if date_mise_en_service is required for production site
if self.site_type == self.PRODUCTION_SITE and not self.date_mise_en_service:
raise ValidationError(
{"date_mise_en_service": ["Ce champ est obligatoire pour les sites de type 'PRODUCTION SITE'."]}
)
if self.site_type in self.PRODUCTION_SITE_TYPES and not self.date_mise_en_service:
raise ValidationError({"date_mise_en_service": ["Ce champ est obligatoire pour les sites de production."]})

# Check if customs_id is required for depot
if self.site_type != self.PRODUCTION_SITE and not self.customs_id:
if self.site_type in self.DEPOT_TYPES and not self.customs_id:
raise ValidationError({"customs_id": ["Ce champ est obligatoire pour les dépots."]})

super().clean()
Expand Down

0 comments on commit b3c065c

Please sign in to comment.