2020-03-20 23:30:49 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django.apps import AppConfig
|
2020-03-24 16:14:29 +00:00
|
|
|
from django.db.models import Q
|
2020-03-23 21:13:16 +00:00
|
|
|
from django.db.models.signals import post_save, post_migrate
|
2020-03-20 23:30:49 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
|
|
|
|
class TreasuryConfig(AppConfig):
|
|
|
|
name = 'treasury'
|
|
|
|
verbose_name = _('Treasury')
|
2020-03-23 20:30:57 +00:00
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
"""
|
|
|
|
Define app internal signals to interact with other apps
|
|
|
|
"""
|
|
|
|
|
|
|
|
from . import signals
|
2020-03-24 19:22:15 +00:00
|
|
|
from note.models import SpecialTransaction, NoteSpecial
|
2020-03-23 20:30:57 +00:00
|
|
|
from treasury.models import SpecialTransactionProxy
|
|
|
|
post_save.connect(signals.save_special_transaction, sender=SpecialTransaction)
|
|
|
|
|
2020-03-23 21:13:16 +00:00
|
|
|
def setup_specialtransactions_proxies(**kwargs):
|
2020-03-24 16:14:29 +00:00
|
|
|
# If the treasury app was disabled for any reason during a certain amount of time,
|
|
|
|
# we ensure that each special transaction is linked to a proxy
|
|
|
|
for transaction in SpecialTransaction.objects.filter(
|
|
|
|
source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)),
|
|
|
|
specialtransactionproxy=None,
|
|
|
|
):
|
2020-10-23 14:55:33 +00:00
|
|
|
proxy = SpecialTransactionProxy(transaction=transaction, remittance=None)
|
|
|
|
proxy._force_save = True
|
|
|
|
proxy.save()
|
2020-03-23 21:13:16 +00:00
|
|
|
|
|
|
|
post_migrate.connect(setup_specialtransactions_proxies, sender=SpecialTransactionProxy)
|