-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove ADS.owner_siret and ADS.owner_license_number, move these fields to ADSUser * add constraints
- Loading branch information
Showing
20 changed files
with
749 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
mesads/app/management/commands/fix_ads_user_and_used_by_owner.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 09:46 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0072_alter_ads_owner_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="adsuser", | ||
name="status", | ||
field=models.CharField( | ||
blank=True, | ||
choices=[ | ||
( | ||
"titulaire_exploitant", | ||
"Le titulaire de l'ADS (personne physique)", | ||
), | ||
( | ||
"legal_representative", | ||
"Le représentant légal de la société titulaire de l'ADS (gérant ou président non salarié)", | ||
), | ||
("salarie", "Salarié du titulaire de l'ADS"), | ||
("cooperateur", "Le locataire-coopérateur de l'ADS"), | ||
("locataire_gerant", "Le locataire-gérant de l'ADS"), | ||
("autre", "Autre"), | ||
], | ||
max_length=255, | ||
verbose_name="Modalité d'exploitation de l'ADS", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 10:43 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def upgrade(apps, schema_editor): | ||
"""Fix ADSUser data, see https://trello.com/c/dG9fG0wC""" | ||
|
||
ADS = apps.get_model("app", "ADS") | ||
ADSUser = apps.get_model("app", "ADSUser") | ||
|
||
for ads in ADS.objects.filter(used_by_owner=True): | ||
ads_user = ADSUser( | ||
ads=ads, | ||
status="titulaire_exploitant", | ||
license_number=ads.owner_license_number, | ||
name="", | ||
siret="", | ||
) | ||
ads_user.save() | ||
|
||
for ads in ADS.objects.filter(used_by_owner=False): | ||
for ads_user in ads.adsuser_set.all(): | ||
if ads_user.status in ("titulaire_exploitant", "autre"): | ||
ads_user.status = "legal_representative" | ||
ads_user.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0073_alter_adsuser_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(upgrade), | ||
] |
50 changes: 50 additions & 0 deletions
50
mesads/app/migrations/0075_remove_ads_used_by_owner_null_for_new_ads_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 10:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0074_fix_adsuser"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveConstraint( | ||
model_name="ads", | ||
name="used_by_owner_null_for_new_ads", | ||
), | ||
migrations.RemoveConstraint( | ||
model_name="ads", | ||
name="owner_license_number_empty_if_not_used_by_owner", | ||
), | ||
migrations.RemoveField( | ||
model_name="ads", | ||
name="owner_license_number", | ||
), | ||
migrations.RemoveField( | ||
model_name="ads", | ||
name="used_by_owner", | ||
), | ||
migrations.AlterField( | ||
model_name="adsuser", | ||
name="status", | ||
field=models.CharField( | ||
blank=True, | ||
choices=[ | ||
( | ||
"titulaire_exploitant", | ||
"Le titulaire de l'ADS (personne physique)", | ||
), | ||
( | ||
"legal_representative", | ||
"Le représentant légal de la société titulaire de l'ADS (gérant ou président non salarié)", | ||
), | ||
("salarie", "Salarié du titulaire de l'ADS"), | ||
("cooperateur", "Le locataire-coopérateur de l'ADS"), | ||
("locataire_gerant", "Le locataire-gérant de l'ADS"), | ||
], | ||
max_length=255, | ||
verbose_name="Modalité d'exploitation de l'ADS", | ||
), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
mesads/app/migrations/0076_adsuser_only_one_titulaire_exploitant.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 11:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0075_remove_ads_used_by_owner_null_for_new_ads_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name="adsuser", | ||
constraint=models.UniqueConstraint( | ||
condition=models.Q( | ||
("deleted_at__isnull", True), ("status", "titulaire_exploitant") | ||
), | ||
fields=("ads", "status"), | ||
name="only_one_titulaire_exploitant", | ||
violation_error_message="Il ne peut y avoir qu'un seul titulaire par ADS.", | ||
), | ||
), | ||
] |
38 changes: 38 additions & 0 deletions
38
mesads/app/migrations/0077_adsuser_name_empty_for_titulaire_exploitant_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 14:58 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0076_adsuser_only_one_titulaire_exploitant"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name="adsuser", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
("deleted_at__isnull", False), | ||
models.Q(("name", ""), ("status", "titulaire_exploitant")), | ||
models.Q(("status", "titulaire_exploitant"), _negated=True), | ||
_connector="OR", | ||
), | ||
name="name_empty_for_titulaire_exploitant", | ||
violation_error_message="Le nom du conducteur ne peut être renseigné que s'il ne s'agit pas du titulaire de l'ADS.", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="adsuser", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
("deleted_at__isnull", False), | ||
models.Q(("siret", ""), ("status", "titulaire_exploitant")), | ||
models.Q(("status", "titulaire_exploitant"), _negated=True), | ||
_connector="OR", | ||
), | ||
name="siret_empty_for_titulaire_exploitant", | ||
violation_error_message="Le SIRET du conducteur ne peut être renseigné que s'il ne s'agit pas du titulaire de l'ADS.", | ||
), | ||
), | ||
] |
40 changes: 40 additions & 0 deletions
40
mesads/app/migrations/0078_fix_adsuser_legal_representative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 15:01 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def upgrade(apps, schema_editor): | ||
"""Fix ADSUser data, see https://trello.com/c/dG9fG0wC""" | ||
ADSUser = apps.get_model("app", "ADSUser") | ||
|
||
for ads_user in ADSUser.objects.filter(status="legal_representative").all(): | ||
if ads_user.siret == "": | ||
continue | ||
|
||
# ADSUser siret and ADS siret are similar, remove the siret from ADSUser | ||
if ads_user.ads.owner_siret == ads_user.siret: | ||
ads_user.siret = "" | ||
ads_user.save() | ||
continue | ||
|
||
# Values are different. Discard the SIRET from ADSUser, assuming it is wrong | ||
if ads_user.ads.owner_siret != "": | ||
ads_user.siret = "" | ||
ads_user.save() | ||
continue | ||
|
||
# ADS.owner_siret is empty, let's use the one from ADSUser | ||
ads_user.ads.owner_siret = ads_user.siret | ||
ads_user.ads.save() | ||
ads_user.siret = "" | ||
ads_user.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0077_adsuser_name_empty_for_titulaire_exploitant_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(upgrade), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 4.1.9 on 2024-03-11 15:27 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def upgrade(apps, schema_editor): | ||
"""Fix ADSUser data, see https://trello.com/c/dG9fG0wC""" | ||
ADSUser = apps.get_model("app", "ADSUser") | ||
|
||
for ads_user in ADSUser.objects.filter(status="salarie").exclude(siret="").all(): | ||
ads_user.siret = "" | ||
ads_user.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app", "0078_fix_adsuser_legal_representative"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(upgrade), | ||
] |
Oops, something went wrong.