From 49e7538a87e3fbd678dd52093ced516bbbf80f90 Mon Sep 17 00:00:00 2001 From: vasileios Date: Mon, 2 Dec 2024 16:02:26 +0100 Subject: [PATCH] [#3283] Removed more code related to the old appointments flow --- .../appointments/contrib/qmatic/plugin.py | 10 +-- src/openforms/appointments/core.py | 2 - .../management/commands/appointment.py | 6 +- src/openforms/appointments/tasks.py | 2 +- src/openforms/appointments/utils.py | 82 ------------------- src/openforms/submissions/admin.py | 3 +- ...3_remove_submission_previous_submission.py | 17 ++++ .../submissions/models/submission.py | 5 -- src/openforms/submissions/query.py | 1 - src/openforms/submissions/tests/factories.py | 6 -- src/openforms/submissions/utils.py | 4 - 11 files changed, 24 insertions(+), 114 deletions(-) create mode 100644 src/openforms/submissions/migrations/0013_remove_submission_previous_submission.py diff --git a/src/openforms/appointments/contrib/qmatic/plugin.py b/src/openforms/appointments/contrib/qmatic/plugin.py index 3069b232e0..e47423360c 100644 --- a/src/openforms/appointments/contrib/qmatic/plugin.py +++ b/src/openforms/appointments/contrib/qmatic/plugin.py @@ -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) @@ -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], diff --git a/src/openforms/appointments/core.py b/src/openforms/appointments/core.py index 08a6811132..4767564d2f 100644 --- a/src/openforms/appointments/core.py +++ b/src/openforms/appointments/core.py @@ -23,7 +23,6 @@ ) from .models import Appointment, AppointmentInfo from .registry import register -from .utils import cancel_previous_submission_appointment __all__ = ["book_for_submission"] @@ -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 diff --git a/src/openforms/appointments/management/commands/appointment.py b/src/openforms/appointments/management/commands/appointment.py index adab85dbd4..c602f50fbb 100644 --- a/src/openforms/appointments/management/commands/appointment.py +++ b/src/openforms/appointments/management/commands/appointment.py @@ -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 @@ -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 diff --git a/src/openforms/appointments/tasks.py b/src/openforms/appointments/tasks.py index 4cbd164f1b..2c361fd432 100644 --- a/src/openforms/appointments/tasks.py +++ b/src/openforms/appointments/tasks.py @@ -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. """ diff --git a/src/openforms/appointments/utils.py b/src/openforms/appointments/utils.py index 0b7b435d92..515a46c2db 100644 --- a/src/openforms/appointments/utils.py +++ b/src/openforms/appointments/utils.py @@ -3,8 +3,6 @@ import logging import re -from django.utils.translation import gettext_lazy as _ - import elasticapm import qrcode @@ -12,7 +10,6 @@ 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 @@ -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: """ @@ -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 diff --git a/src/openforms/submissions/admin.py b/src/openforms/submissions/admin.py index 5f67dc9800..ec0321caf0 100644 --- a/src/openforms/submissions/admin.py +++ b/src/openforms/submissions/admin.py @@ -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", diff --git a/src/openforms/submissions/migrations/0013_remove_submission_previous_submission.py b/src/openforms/submissions/migrations/0013_remove_submission_previous_submission.py new file mode 100644 index 0000000000..ac43edb7f6 --- /dev/null +++ b/src/openforms/submissions/migrations/0013_remove_submission_previous_submission.py @@ -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", + ), + ] diff --git a/src/openforms/submissions/models/submission.py b/src/openforms/submissions/models/submission.py index b24e526474..d09e6e5b21 100644 --- a/src/openforms/submissions/models/submission.py +++ b/src/openforms/submissions/models/submission.py @@ -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, diff --git a/src/openforms/submissions/query.py b/src/openforms/submissions/query.py index 6abc781138..34b7aacf02 100644 --- a/src/openforms/submissions/query.py +++ b/src/openforms/submissions/query.py @@ -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"): diff --git a/src/openforms/submissions/tests/factories.py b/src/openforms/submissions/tests/factories.py index b7c0c06fd1..8e9f8b9501 100644 --- a/src/openforms/submissions/tests/factories.py +++ b/src/openforms/submissions/tests/factories.py @@ -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", diff --git a/src/openforms/submissions/utils.py b/src/openforms/submissions/utils.py index c88100587e..5cbb13996b 100644 --- a/src/openforms/submissions/utils.py +++ b/src/openforms/submissions/utils.py @@ -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, @@ -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),