Skip to content

Commit

Permalink
[#3283] Removed more code related to the old appointments flow
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Dec 2, 2024
1 parent 8a360e0 commit 49e7538
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 114 deletions.
10 changes: 1 addition & 9 deletions src/openforms/appointments/contrib/qmatic/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,6 @@ def create_appointment(
remarks: str = "",
) -> str:
assert products, "Can't book for empty products"
customer = _CustomerDetails(
details={
CustomerFields.last_name: client.last_name,
CustomerFields.birthday: client.birthdate.isoformat(),
CustomerFields.first_name: client.initials or "",
CustomerFields.phone_number: client.phonenumber or "",
}
)

product_names = ", ".join(sorted({product.name for product in products}))
unique_product_ids, num_customers = self._count_products(products)
Expand All @@ -308,7 +300,7 @@ def create_appointment(
# we repeat the same customer information for every customer, as we currently
# don't support getting the contact details for each individual customer
"customers": [
{choice: value for choice, value in customer.details.items() if value}
{choice: value for choice, value in client.details.items() if value}
]
* num_customers,
"services": [{"publicId": product_id} for product_id in unique_product_ids],
Expand Down
2 changes: 0 additions & 2 deletions src/openforms/appointments/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
)
from .models import Appointment, AppointmentInfo
from .registry import register
from .utils import cancel_previous_submission_appointment

__all__ = ["book_for_submission"]

Expand Down Expand Up @@ -116,5 +115,4 @@ def book_for_submission(submission: Submission) -> str:
logevent.appointment_register_failure(appointment_info, plugin, e)
raise AppointmentRegistrationFailed("Unable to create appointment") from e

cancel_previous_submission_appointment(submission)
return appointment_id
6 changes: 4 additions & 2 deletions src/openforms/appointments/management/commands/appointment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from openforms.submissions.models import Submission

from ...base import Customer
from ...base import CustomerDetails
from ...core import book_for_submission
from ...registry import register
from ...utils import get_plugin
Expand Down Expand Up @@ -122,7 +122,9 @@ def create_booking(self):

# Customer

customer = Customer(last_name="Doe", birthdate=date(1970, 1, 1))
customer = CustomerDetails(
details={"lastName": "Doe", "birthdate": date(1970, 1, 1)}
)

# Book

Expand Down
2 changes: 1 addition & 1 deletion src/openforms/appointments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def register_appointment(submission_id: int) -> None | str:
If the submission is for a form which is configured to create appointments,
ensure that the appointment is registered in the configured backend.
This can either not be needed, be successful or fail. Either way, the result should
This can either be successful or fail. Either way, the result should
be stored in the database. If appointment registration fails, this feedback
should find its way back to the end-user.
"""
Expand Down
82 changes: 0 additions & 82 deletions src/openforms/appointments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import logging
import re

from django.utils.translation import gettext_lazy as _

import elasticapm
import qrcode

from openforms.logging import logevent
from openforms.submissions.models import Submission

from .base import BasePlugin
from .constants import AppointmentDetailsStatus
from .exceptions import AppointmentDeleteFailed
from .models import Appointment, AppointmentInfo, AppointmentsConfig
from .registry import register
Expand Down Expand Up @@ -42,56 +39,6 @@ def get_formatted_phone_number(phone_number: str | None) -> str | None:
return phone_number[:16]


@elasticapm.capture_span(span_type="app.appointments.cancel")
def cancel_previous_submission_appointment(submission: Submission) -> None:
"""
Given a submission, check if there's a previous appointment to cancel.
"""
if not (previous_submission := submission.previous_submission):
logger.debug(
"Submission %s has no known previous appointment to cancel", submission.uuid
)
return

# check if there's anything to cancel at all
try:
appointment_info = previous_submission.appointment_info
except AppointmentInfo.DoesNotExist:
logger.debug(
"Submission %s has no known previous appointment to cancel", submission.uuid
)
return

if (
appointment_info.status != AppointmentDetailsStatus.success
or not appointment_info.appointment_id
):
logger.debug(
"Submission %s has no known previous appointment to cancel", submission.uuid
)
return

# check for new-style appointments
appointment = Appointment.objects.filter(submission=previous_submission).first()
plugin = get_plugin(plugin=appointment.plugin if appointment else "")

logger.debug(
"Attempting to cancel appointment %s of submission %s",
appointment_info.appointment_id,
submission.uuid,
)
logevent.appointment_cancel_start(appointment_info, plugin)

try:
delete_appointment_for_submission(previous_submission, plugin=plugin)
except AppointmentDeleteFailed:
logger.warning(
"Deleting the appointment %s of submission %s failed",
appointment_info.appointment_id,
submission.uuid,
)


@elasticapm.capture_span(span_type="app.appointments.delete")
def delete_appointment_for_submission(submission: Submission, plugin=None) -> None:
"""
Expand Down Expand Up @@ -129,35 +76,6 @@ def create_base64_qrcode(text):
return base64.b64encode(buffer.read()).decode("ascii")


def get_confirmation_mail_suffix(submission: Submission) -> str:
"""
Determine the suffix, if appropriate for the subject of the confirmation mail.
If this submission is related to an appointment and previous submission,
append an "updated" marker to the subject (see #680).
"""
# if there's no related previous submission, it cannot be an update
if not submission.previous_submission_id:
return ""

# if there's no appointment info attached to the previous submission, it cannot be
# an update
try:
appointment_info = submission.previous_submission.appointment_info
except AppointmentInfo.DoesNotExist:
return ""

# if the previous appointment was not cancelled, it cannot be an update
# TODO: what to do when we did succesfully create a new appointment, but the old
# one deletion failed? there are now two appointments open.
# submission.appointment_info.status == AppointmentDetailsStatus.success and
# submission.previous_submission.appointment_info.status == AppointmentDetailsStatus.success
if appointment_info.status != AppointmentDetailsStatus.cancelled:
return ""

return _("(updated)")


def get_appointment(submission: Submission) -> Appointment | None:
if not submission.form.is_appointment:
return None
Expand Down
3 changes: 1 addition & 2 deletions src/openforms/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,13 @@ class SubmissionAdmin(admin.ModelAdmin):
"privacy_policy_accepted",
"statement_of_truth_accepted",
"_is_cleaned",
"previous_submission",
"initial_data_reference",
),
"classes": ("collapse",),
},
),
)
raw_id_fields = ("form", "previous_submission")
raw_id_fields = ("form",)
actions = [
"export_csv",
"export_json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.16 on 2024-12-02 11:15

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("submissions", "0012_alter_submission_price"),
]

operations = [
migrations.RemoveField(
model_name="submission",
name="previous_submission",
),
]
5 changes: 0 additions & 5 deletions src/openforms/submissions/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,6 @@ class Submission(models.Model):
),
)

# relation to earlier submission which is altered after processing
previous_submission = models.ForeignKey(
"submissions.Submission", on_delete=models.SET_NULL, null=True, blank=True
)

language_code = models.CharField(
_("language code"),
max_length=2,
Expand Down
1 change: 0 additions & 1 deletion src/openforms/submissions/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def copy(
from .models import SubmissionStep

new_instance = self.create(
previous_submission=original, # store the reference from where it was copied
**{field: getattr(original, field) for field in fields},
)
if hasattr(original, "auth_info"):
Expand Down
6 changes: 0 additions & 6 deletions src/openforms/submissions/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ class Params:
registration_status=RegistrationStatuses.in_progress,
pre_registration_completed=True,
)
has_previous_submission = factory.Trait(
previous_submission=factory.SubFactory(
"openforms.submissions.tests.factories.SubmissionFactory",
form=factory.SelfAttribute("..form"),
)
)
with_report = factory.Trait(
report=factory.RelatedFactory(
"openforms.submissions.tests.factories.SubmissionReportFactory",
Expand Down
4 changes: 0 additions & 4 deletions src/openforms/submissions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from rest_framework.request import Request
from rest_framework.reverse import reverse

from openforms.appointments.utils import get_confirmation_mail_suffix
from openforms.emails.confirmation_emails import (
get_confirmation_email_context_data,
get_confirmation_email_templates,
Expand Down Expand Up @@ -189,9 +188,6 @@ def send_confirmation_email(submission: Submission) -> None:
subject_template, context, rendering_text=True, disable_autoescape=True
).strip()

if subject_suffix := get_confirmation_mail_suffix(submission):
subject = f"{subject} {subject_suffix}"

html_content = render_email_template(content_template, context)
text_content = strip_tags_plus(
render_email_template(content_template, context, rendering_text=True),
Expand Down

0 comments on commit 49e7538

Please sign in to comment.