SpecialTransactionProxy are force-saved

This commit is contained in:
Yohann D'ANELLO 2020-10-23 16:55:33 +02:00
parent 6dc7604e90
commit 224a0fdd8c
2 changed files with 8 additions and 7 deletions

View File

@ -28,6 +28,8 @@ class TreasuryConfig(AppConfig):
source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)), source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)),
specialtransactionproxy=None, specialtransactionproxy=None,
): ):
SpecialTransactionProxy.objects.create(transaction=transaction, remittance=None) proxy = SpecialTransactionProxy(transaction=transaction, remittance=None)
proxy._force_save = True
proxy.save()
post_migrate.connect(setup_specialtransactions_proxies, sender=SpecialTransactionProxy) post_migrate.connect(setup_specialtransactions_proxies, sender=SpecialTransactionProxy)

View File

@ -10,9 +10,8 @@ def save_special_transaction(instance, created, **kwargs):
""" """
if not hasattr(instance, "_no_signal"): if not hasattr(instance, "_no_signal"):
if instance.is_credit(): if created and RemittanceType.objects.filter(
if created and RemittanceType.objects.filter(note=instance.source).exists(): note=instance.source if instance.is_credit() else instance.destination).exists():
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save() proxy = SpecialTransactionProxy(transaction=instance, remittance=None)
else: proxy._force_save = True
if created and RemittanceType.objects.filter(note=instance.destination).exists(): proxy.save()
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()