1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 01:48:21 +02:00

Automatically link SpecialTransactions and their proxies

This commit is contained in:
Yohann D'ANELLO
2020-03-23 21:30:57 +01:00
parent 884a7d0f08
commit cf45b08c5b
3 changed files with 45 additions and 0 deletions

View File

@ -2,9 +2,24 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig
from django.db.models.signals import post_save
from django.utils.translation import gettext_lazy as _
class TreasuryConfig(AppConfig):
name = 'treasury'
verbose_name = _('Treasury')
def ready(self):
"""
Define app internal signals to interact with other apps
"""
from . import signals
from note.models import SpecialTransaction
from treasury.models import SpecialTransactionProxy
post_save.connect(signals.save_special_transaction, sender=SpecialTransaction)
# If the treasury app was disabled, we ensure that each special transaction is linked to a proxy
for transaction in SpecialTransaction.objects.filter(specialtransactionproxy=None):
SpecialTransactionProxy.objects.create(transaction=transaction, remittance=None)