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. 15
      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.db.models.functions import ExtractDay, Cast
from django.conf import settings from django.conf import settings
from django.contrib import admin, messages from django.contrib import admin, messages
from django.contrib.admin.utils import get_deleted_objects
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
@ -1169,6 +1170,18 @@ class EventoAdmin(AsciifyQParameter, CartExportReportMixin, admin.ModelAdmin):
level=messages.SUCCESS, 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): def declaracao_report(self, request, object_id):
if request.method == "POST": if request.method == "POST":
form = SelecionaModeloForm(request.POST) form = SelecionaModeloForm(request.POST)

15
sigi/apps/eventos/models.py

@ -625,7 +625,7 @@ class Evento(models.Model):
self.reserva.clean() self.reserva.clean()
def update_reserva(self): 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 # Gertiq #167321
if self.reserva is not None: if self.reserva is not None:
self.reserva.proposito = self.nome self.reserva.proposito = self.nome
@ -643,6 +643,19 @@ class Evento(models.Model):
else: else:
self.reserva.status = Reserva.STATUS_ATIVO 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): def save(self, *args, **kwargs):
# Força que a casa anfitriã de todas as visitas seja Senado # Força que a casa anfitriã de todas as visitas seja Senado
# Gertik #165751 # Gertik #165751

Loading…
Cancel
Save