Browse Source

Deletar reserva se evento vinculado for deletado.

pull/169/head
Sesóstris Vieira 1 year ago
parent
commit
e6aaf94109
  1. 13
      sigi/apps/eventos/admin.py
  2. 13
      sigi/apps/eventos/models.py

13
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)

13
sigi/apps/eventos/models.py

@ -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

Loading…
Cancel
Save