mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-04-30 19:02:38 +02:00
Fix issue with incorrect deadline_time in order
This commit is contained in:
parent
d37b117440
commit
1aa5f985db
1 changed files with 11 additions and 2 deletions
|
@ -1,9 +1,14 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
from typing import Any, Optional, Sequence, Type, Union
|
||||||
|
|
||||||
|
import pytz
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
|
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
from django.forms.utils import to_current_timezone
|
||||||
|
from django.forms.widgets import Widget
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from la_chariotte import settings
|
from la_chariotte import settings
|
||||||
from la_chariotte.order.models import GroupedOrder, Item
|
from la_chariotte.order.models import GroupedOrder, Item
|
||||||
|
@ -56,6 +61,7 @@ class GroupedOrderForm(forms.ModelForm):
|
||||||
|
|
||||||
# When updating an existing order, reuse existing values
|
# When updating an existing order, reuse existing values
|
||||||
if kwargs["instance"]:
|
if kwargs["instance"]:
|
||||||
|
self.instance.deadline = to_current_timezone(self.instance.deadline)
|
||||||
self.initial["deadline_date"] = self.instance.deadline.date()
|
self.initial["deadline_date"] = self.instance.deadline.date()
|
||||||
self.initial["deadline_time"] = self.instance.deadline.time()
|
self.initial["deadline_time"] = self.instance.deadline.time()
|
||||||
# TODO: there is a bug here ; the time displayed in form is 2 hours earlier than the actual deadline time
|
# TODO: there is a bug here ; the time displayed in form is 2 hours earlier than the actual deadline time
|
||||||
|
@ -66,8 +72,11 @@ class GroupedOrderForm(forms.ModelForm):
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = self.cleaned_data
|
cleaned_data = self.cleaned_data
|
||||||
self.instance.deadline = datetime.datetime.combine(
|
self.instance.deadline = timezone.make_aware(
|
||||||
self.cleaned_data["deadline_date"], self.cleaned_data["deadline_time"]
|
datetime.datetime.combine(
|
||||||
|
self.cleaned_data["deadline_date"],
|
||||||
|
self.cleaned_data["deadline_time"],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue