-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(backend) add start and end date on order groups model
We want to be able to define a start or an end date on the order group. Both dates can be setted as well. The enabled property defines if the order group can accept new orders when it is in relation with a course product relation. With this work, the field `is_active` has become a switch for admin user to enabled or not the group. Then, the property `is_enabled` computes the value depending on the activation of the group and the time constraints. Fix #1029
- Loading branch information
1 parent
1dcfb65
commit c867b40
Showing
13 changed files
with
929 additions
and
38 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
53 changes: 53 additions & 0 deletions
53
src/backend/joanie/core/migrations/0056_alter_ordergroup_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,53 @@ | ||
# Generated by Django 4.2.18 on 2025-02-06 10:16 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
def migrate_order_group_nb_seats_zero_to_none(apps, schema_editor): | ||
""" | ||
Update order groups where the seat number is 0 to None. | ||
""" | ||
OrderGroup = apps.get_model("core", "OrderGroup") | ||
OrderGroup.objects.filter(nb_seats=0).update(nb_seats=None) | ||
|
||
|
||
def rollback_order_group_nb_seats_none_to_zero(apps, schema_editor): | ||
""" | ||
Restore order group where number of seats is None to 0. | ||
""" | ||
OrderGroup = apps.get_model("core", "OrderGroup") | ||
OrderGroup.objects.filter(nb_seats=None).update(nb_seats=0) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0055_alter_documentimage_options_alter_ordergroup_options'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='ordergroup', | ||
name='end', | ||
field=models.DateTimeField(blank=True, help_text='Date at which the order group activation ends', null=True, verbose_name='order group end datetime'), | ||
), | ||
migrations.AddField( | ||
model_name='ordergroup', | ||
name='start', | ||
field=models.DateTimeField(blank=True, help_text='Date at which the order group activation begins', null=True, verbose_name='order group start datetime'), | ||
), | ||
migrations.AlterField( | ||
model_name='ordergroup', | ||
name='nb_seats', | ||
field=models.PositiveSmallIntegerField(blank=True, default=None, help_text='The maximum number of orders that can be validated for a given order group', null=True, verbose_name='Number of seats'), | ||
), | ||
migrations.AddConstraint( | ||
model_name='ordergroup', | ||
constraint=models.CheckConstraint(check=models.Q(('start__lte', models.F('end'))), name='check_start_before_end', violation_error_message='Start date cannot be greater than end date'), | ||
), | ||
migrations.RunPython( | ||
migrate_order_group_nb_seats_zero_to_none, | ||
rollback_order_group_nb_seats_none_to_zero, | ||
), | ||
] |
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
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
Oops, something went wrong.