added real sagex hours + changed to DurationField
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
# Generated by Django 5.1.5 on 2025-02-03 17:53
|
||||
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def time_to_duration(apps, schema_editor):
|
||||
Clocking = apps.get_model("dispatcher", "Clocking")
|
||||
for clocking in Clocking.objects.all().iterator():
|
||||
if clocking.old_remote:
|
||||
remote: datetime.time = clocking.old_remote
|
||||
clocking.remote = timedelta(hours=remote.hour, minutes=remote.minute)
|
||||
else:
|
||||
clocking.remote = timedelta()
|
||||
clocking.save()
|
||||
|
||||
|
||||
def duration_to_time(apps, schema_editor):
|
||||
Clocking = apps.get_model("dispatcher", "Clocking")
|
||||
for clocking in Clocking.objects.all().iterator():
|
||||
if clocking.remote.total_seconds() != 0:
|
||||
remote: datetime.timedelta = clocking.remote
|
||||
total_seconds = remote.total_seconds()
|
||||
hours, remainder = divmod(total_seconds, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
clocking.old_remote = datetime.time(int(hours), int(minutes), int(seconds))
|
||||
else:
|
||||
clocking.old_remote = None
|
||||
clocking.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dispatcher', '0008_alter_clocking_in_am_alter_clocking_in_pm_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='clocking',
|
||||
old_name='remote',
|
||||
new_name='old_remote'
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='clocking',
|
||||
name='remote',
|
||||
field=models.DurationField(default=datetime.timedelta),
|
||||
),
|
||||
migrations.RunPython(time_to_duration, duration_to_time),
|
||||
migrations.RemoveField(
|
||||
model_name='clocking',
|
||||
name='old_remote'
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='RealSageXHours',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('hours', models.DurationField(default=datetime.timedelta)),
|
||||
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dispatcher.parent')),
|
||||
],
|
||||
),
|
||||
]
|
@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.1.5 on 2025-02-03 18:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dispatcher', '0009_alter_clocking_remote_realsagexhours'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddConstraint(
|
||||
model_name='realsagexhours',
|
||||
constraint=models.UniqueConstraint(fields=('parent', 'date'), name='unique_monthly_sagex'),
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user