diff --git a/sigi/apps/eventos/admin.py b/sigi/apps/eventos/admin.py index 016d703..b2ae247 100644 --- a/sigi/apps/eventos/admin.py +++ b/sigi/apps/eventos/admin.py @@ -21,6 +21,7 @@ from django.db.models import ( from django.db.models.functions import ExtractDay, Cast from django.conf import settings from django.contrib import admin, messages +from django.contrib.admin.utils import get_deleted_objects from django.core.exceptions import ValidationError from django.http import HttpResponse from django.shortcuts import get_object_or_404, render, redirect @@ -1169,6 +1170,18 @@ class EventoAdmin(AsciifyQParameter, CartExportReportMixin, admin.ModelAdmin): level=messages.SUCCESS, ) + def get_deleted_objects(self, objs, request): + deleted_objects = super().get_deleted_objects(objs, request) + dr = get_deleted_objects( + [o.reserva for o in objs if hasattr(o, "reserva")], + request, + self.admin_site, + ) + deleted_objects[0].extend(dr[0]) + deleted_objects[1].update(dr[1]) + deleted_objects[2].update(dr[2]) + return deleted_objects + def declaracao_report(self, request, object_id): if request.method == "POST": form = SelecionaModeloForm(request.POST) diff --git a/sigi/apps/eventos/models.py b/sigi/apps/eventos/models.py index eef3194..2d8e09d 100644 --- a/sigi/apps/eventos/models.py +++ b/sigi/apps/eventos/models.py @@ -625,7 +625,7 @@ class Evento(models.Model): self.reserva.clean() def update_reserva(self): - # Prepara e valida a reserva de espaço para ser salva + # Prepara e valida a reserva de espaço para ser salva # Gertiq #167321 if self.reserva is not None: self.reserva.proposito = self.nome @@ -643,6 +643,19 @@ class Evento(models.Model): else: self.reserva.status = Reserva.STATUS_ATIVO + def delete(self, *args, **kwargs): + result = super().delete(*args, **kwargs) + if self.reserva: + rr = self.reserva.delete() + result = tuple( + map( + lambda a, b: a + b if isinstance(a, int) else a | b, + result, + rr, + ) + ) + return result + def save(self, *args, **kwargs): # Força que a casa anfitriã de todas as visitas seja Senado # Gertik #165751