Skip to content

Commit

Permalink
Merge pull request #1162 from Amsterdam/bugfix/93533-double-permits-n…
Browse files Browse the repository at this point in the history
…ot-vissible

93533
  • Loading branch information
remyvdwereld authored Sep 29, 2023
2 parents b6dff62 + dcb54ba commit d0b6683
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
51 changes: 42 additions & 9 deletions app/apps/permits/api_queries_decos_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def get_decos_entry_by_bag_id(self, bag_id, dt):
}
for v in decos_join_conf_object
]
# Initialize an empty list to hold new items
new_permits = []

response_decos_obj = self.get_decos_object_with_bag_id(bag_id)

Expand Down Expand Up @@ -327,20 +329,48 @@ def get_decos_entry_by_bag_id(self, bag_id, dt):
# Wrap datetime validation in a try-catch to prevent breaking code.
try:
# Is the current permit valid/active? => now must be between start and enddate.
is_current_permit_valid = (
current_permit_valid_from <= now
and now <= current_permit_valid_until
)
# Check if the variables are not None before comparing.
if (
current_permit_valid_from is not None
and current_permit_valid_until
is not None
):
is_current_permit_valid = (
current_permit_valid_from <= now
and now
<= current_permit_valid_until
)
else:
# Handle the case where one or both variables are None
is_current_permit_valid = False

# Is the next permit valid/active? => now must be between start and enddate.
is_next_permit_valid = (
next_permit_valid_from <= now
and now <= next_permit_valid_until
)
# Check if the variables are not None before comparing.
if (
next_permit_valid_from is not None
and next_permit_valid_until is not None
):
is_next_permit_valid = (
next_permit_valid_from <= now
and now <= next_permit_valid_until
)
else:
# Handle the case where one or both variables are None
is_next_permit_valid = False

if is_next_permit_valid:
# Next permit is valid so this is the one users would like to see. Update permit data.
d.update(permit_serializer.data)
if is_current_permit_valid:
# Both current and next permits are valid.
# Show both permits so the Toezichthouder can decide.
# Add the next permit to the new_permits list for merging later.
new_permits.append(
permit_serializer.data
)
else:
# Only the next permit is valid, update the data.
d.update(permit_serializer.data)

elif not is_current_permit_valid:
# Current permit and next permit are not valid.
if next_permit_valid_from > now:
Expand Down Expand Up @@ -378,6 +408,9 @@ def get_decos_entry_by_bag_id(self, bag_id, dt):
"Config keys: %s" % decos_join_conf_object.get_book_keys()
)

# Extend the original permits list with new items
permits.extend(new_permits)

response.update(
{
"permits": permits,
Expand Down
1 change: 1 addition & 0 deletions app/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@
"text19": "HOLDER",
"subject1": "SUBJECT",
"text6": "ADDRESS",
"document_date": "REQUEST_DATE",
}
DECOS_JOIN_BOOK_UNKNOWN_BOOK = "B1FF791EA9FA44698D5ABBB1963B94EC"
DECOS_JOIN_BOOK_KNOWN_BAG_OBJECTS = "90642DCCC2DB46469657C3D0DF0B1ED7"
Expand Down

0 comments on commit d0b6683

Please sign in to comment.