Skip to content

Commit

Permalink
Merge pull request #1391 from open-zaak/issue/zaak-einddatum-tz
Browse files Browse the repository at this point in the history
fix when zaak.einddatum is earlier then zaak.startdatum
  • Loading branch information
annashamray committed Jun 26, 2023
2 parents 482827d + 07cde9c commit 6638b72
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/openzaak/components/zaken/api/serializers/zaken.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.conf import settings
from django.db import transaction
from django.utils.dateparse import parse_datetime
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -556,7 +557,16 @@ def create(self, validated_data):
# 1. zaak.einddatum, which may be relevant for archiving purposes
# 2. zaak.archiefactiedatum, if not explicitly filled in
if is_eindstatus:
zaak.einddatum = validated_data["datum_status_gezet"].date()
# zaak.einddatum is date, but status.datum_status_gezet is a datetime with tz support
# durin validation step 'datum_status_gezet' was already converted to the
# default timezone (UTC).
# We want to take into consideration the client timezone before saving 'zaak.einddatum',
# therefore we convert 'datum_status_gezet' back to the client timezone before taking its
# date part.
local_datum_status_gezet = parse_datetime(
self.initial_data["datum_status_gezet"]
)
zaak.einddatum = local_datum_status_gezet.date()
else:
zaak.einddatum = None
_zaak_fields_changed.append("einddatum")
Expand Down
41 changes: 39 additions & 2 deletions src/openzaak/components/zaken/tests/test_zaken.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2019 - 2020 Dimpact
from copy import copy
from datetime import date
from datetime import date, datetime

from django.contrib.gis.geos import Point
from django.test import override_settings, tag
Expand Down Expand Up @@ -41,7 +41,7 @@
from ..constants import BetalingsIndicatie
from ..models import Medewerker, NatuurlijkPersoon, OrganisatorischeEenheid, Zaak
from .constants import POLYGON_AMSTERDAM_CENTRUM
from .factories import RolFactory, StatusFactory, ZaakFactory
from .factories import ResultaatFactory, RolFactory, StatusFactory, ZaakFactory
from .utils import (
ZAAK_READ_KWARGS,
ZAAK_WRITE_KWARGS,
Expand Down Expand Up @@ -172,6 +172,43 @@ def test_zaak_afsluiten(self):
zaak.archiefactiedatum, zaak.einddatum + relativedelta(years=10)
)

def test_close_zaak_not_in_utc(self):
"""
imagine that the client timezone is +2:00 and we create and close
zaak at ~2023-01-01T00:00:00+2:00
freeze_gun is not used here, because it doesn't seem to work correctly
with timezones
"""
zaaktype = ZaakTypeFactory.create(concept=False)
zaak = ZaakFactory.create(zaaktype=zaaktype, startdatum="2023-01-01")
zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid})
statustype = StatusTypeFactory.create(zaaktype=zaaktype)
resultaattype = ResultaatTypeFactory.create(
zaaktype=zaaktype,
archiefactietermijn=relativedelta(years=10),
archiefnominatie=Archiefnominatie.blijvend_bewaren,
brondatum_archiefprocedure_afleidingswijze=BrondatumArchiefprocedureAfleidingswijze.afgehandeld,
)
ResultaatFactory(zaak=zaak, resultaattype=resultaattype)
statustype_url = reverse(statustype)
status_list_url = reverse("status-list")

response = self.client.post(
status_list_url,
{
"zaak": zaak_url,
"statustype": f"http://testserver{statustype_url}",
"datumStatusGezet": datetime.fromisoformat("2023-01-01 00:00:00+02:00"),
},
)

self.assertEqual(
response.status_code, status.HTTP_201_CREATED, response.content
)

zaak.refresh_from_db()
self.assertEqual(zaak.einddatum, date(2023, 1, 1))


class ZakenTests(JWTAuthMixin, APITestCase):

Expand Down

0 comments on commit 6638b72

Please sign in to comment.