mirror of https://gitlab.crans.org/bde/nk20
We don't need to create proxies for special transactions that don't require a remittance
This commit is contained in:
parent
4cf1047faa
commit
093e585b79
|
@ -2,8 +2,10 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db.models import Q
|
||||||
from django.db.models.signals import post_save, post_migrate
|
from django.db.models.signals import post_save, post_migrate
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from note.models import NoteSpecial
|
||||||
|
|
||||||
|
|
||||||
class TreasuryConfig(AppConfig):
|
class TreasuryConfig(AppConfig):
|
||||||
|
@ -21,8 +23,12 @@ class TreasuryConfig(AppConfig):
|
||||||
post_save.connect(signals.save_special_transaction, sender=SpecialTransaction)
|
post_save.connect(signals.save_special_transaction, sender=SpecialTransaction)
|
||||||
|
|
||||||
def setup_specialtransactions_proxies(**kwargs):
|
def setup_specialtransactions_proxies(**kwargs):
|
||||||
# If the treasury app was disabled, we ensure that each special transaction is linked to a proxy
|
# If the treasury app was disabled for any reason during a certain amount of time,
|
||||||
for transaction in SpecialTransaction.objects.filter(specialtransactionproxy=None):
|
# 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,
|
||||||
|
):
|
||||||
SpecialTransactionProxy.objects.create(transaction=transaction, remittance=None)
|
SpecialTransactionProxy.objects.create(transaction=transaction, remittance=None)
|
||||||
|
|
||||||
post_migrate.connect(setup_specialtransactions_proxies, sender=SpecialTransactionProxy)
|
post_migrate.connect(setup_specialtransactions_proxies, sender=SpecialTransactionProxy)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from treasury.models import SpecialTransactionProxy
|
from treasury.models import SpecialTransactionProxy, RemittanceType
|
||||||
|
|
||||||
|
|
||||||
def save_special_transaction(instance, created, **kwargs):
|
def save_special_transaction(instance, created, **kwargs):
|
||||||
"""
|
"""
|
||||||
When a special transaction is created, we create its linked proxy
|
When a special transaction is created, we create its linked proxy
|
||||||
"""
|
"""
|
||||||
if created:
|
if created and RemittanceType.objects.filter(note=instance.source).exists():
|
||||||
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
||||||
|
|
Loading…
Reference in New Issue