manager: allow separate arrvial/departure check for partial bookings (#80047)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-10-11 12:41:01 +02:00
parent a25a8e6ef1
commit 21cae6a31f
5 changed files with 28 additions and 9 deletions

View File

@ -18,8 +18,8 @@ class Migration(migrations.Migration):
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
('presence', models.BooleanField()),
('start_time', models.TimeField(null=True, verbose_name='Arrival')),
('end_time', models.TimeField(null=True, verbose_name='Departure')),
('start_time', models.TimeField(null=True, blank=True, verbose_name='Arrival')),
('end_time', models.TimeField(null=True, blank=True, verbose_name='Departure')),
('computed_end_time', models.TimeField(null=True)),
('computed_start_time', models.TimeField(null=True)),
('type_slug', models.CharField(blank=True, max_length=160, null=True)),

View File

@ -3006,8 +3006,8 @@ class BookingCheck(models.Model):
presence = models.BooleanField()
start_time = models.TimeField(_('Arrival'), null=True)
end_time = models.TimeField(_('Departure'), null=True)
start_time = models.TimeField(_('Arrival'), null=True, blank=True)
end_time = models.TimeField(_('Departure'), null=True, blank=True)
computed_start_time = models.TimeField(null=True)
computed_end_time = models.TimeField(null=True)

View File

@ -636,7 +636,11 @@ class PartialBookingCheckForm(forms.ModelForm):
self.fields.pop('absence_check_type', None)
def clean(self):
if self.cleaned_data['end_time'] <= self.cleaned_data['start_time']:
if (
self.cleaned_data.get('start_time')
and self.cleaned_data.get('end_time')
and self.cleaned_data['end_time'] <= self.cleaned_data['start_time']
):
raise ValidationError(_('Arrival must be before departure.'))
if self.instance.overlaps_existing_check(

View File

@ -93,8 +93,12 @@
{% endif %}
>
<strong class="sr-only">{% trans "Checked period:" %}</strong>
<time class="start-time" datetime="{{ check.start_time|time:"H:i" }}">{{ check.start_time|time:"H:i" }}</time>
<time class="end-time" datetime="{{ check.end_time|time:"H:i" }}">{{ check.end_time|time:"H:i" }}</time>
{% if check.start_time %}
<time class="start-time" datetime="{{ check.start_time|time:"H:i" }}">{{ check.start_time|time:"H:i" }}</time>
{% endif %}
{% if check.end_time %}
<time class="end-time" datetime="{{ check.end_time|time:"H:i" }}">{{ check.end_time|time:"H:i" }}</time>
{% endif %}
{% if check.type_label %}<span>{{ check.type_label }}</span>{% endif %}
</a>
{% endfor %}

View File

@ -1663,8 +1663,19 @@ class AgendaDayView(EventChecksMixin, AgendaDateView, DayArchiveView):
booking.user_check_list = list(booking.user_checks.all()) # queryset is prefetched
for check in booking.user_check_list:
check.css_class = 'present' if check.presence else 'absent'
check.css_left = get_time_ratio(check.start_time, start_time)
check.css_width = get_time_ratio(check.end_time, check.start_time)
if not check.start_time:
check.css_class += ' end-only'
check.css_left = booking.css_left
check.css_width = booking.css_width
elif not check.end_time:
check.css_class += ' start-only'
check.css_left = get_time_ratio(check.start_time, start_time)
check.css_width = 4
else:
check.css_left = get_time_ratio(check.start_time, start_time)
check.css_width = get_time_ratio(check.end_time, check.start_time)
if check.computed_start_time and check.computed_end_time:
check.computed_css_left = get_time_ratio(check.computed_start_time, start_time)
check.computed_css_width = get_time_ratio(