mirror of https://gitlab.crans.org/bde/nk20
Compare commits
6 Commits
7597ad859a
...
f468c2f939
Author | SHA1 | Date |
---|---|---|
Pierre-antoine Comby | f468c2f939 | |
Yohann D'ANELLO | fdf373d1d5 | |
Pierre-antoine Comby | 6d27193ac4 | |
Pierre-antoine Comby | 038ddc2ab8 | |
Pierre-antoine Comby | cc97948c24 | |
Pierre-antoine Comby | 53748cd534 |
|
@ -264,6 +264,17 @@ class SpecialTransaction(Transaction):
|
||||||
def type(self):
|
def type(self):
|
||||||
return _('Credit') if isinstance(self.source, NoteSpecial) else _("Debit")
|
return _('Credit') if isinstance(self.source, NoteSpecial) else _("Debit")
|
||||||
|
|
||||||
|
def is_credit(self):
|
||||||
|
return isinstance(self.source, NoteSpecial)
|
||||||
|
|
||||||
|
def is_debit(self):
|
||||||
|
return isinstance(self.destination, NoteSpecial)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
# SpecialTransaction are only possible with NoteSpecial object
|
||||||
|
if self.is_credit() == self.is_debit():
|
||||||
|
raise(ValidationError(_("A special transaction is only possible between a Note associated to a payment method and a User or a Club")))
|
||||||
|
|
||||||
|
|
||||||
class MembershipTransaction(Transaction):
|
class MembershipTransaction(Transaction):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -191,7 +191,7 @@ class SpecialTransactionProxy(models.Model):
|
||||||
"""
|
"""
|
||||||
In order to keep modularity, we don't that the Note app depends on the treasury app.
|
In order to keep modularity, we don't that the Note app depends on the treasury app.
|
||||||
That's why we create a proxy in this app, to link special transactions and remittances.
|
That's why we create a proxy in this app, to link special transactions and remittances.
|
||||||
If it isn't very clean, that makes what we want.
|
If it isn't very clean, it does what we want.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
transaction = models.OneToOneField(
|
transaction = models.OneToOneField(
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# 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 note.models import NoteSpecial
|
|
||||||
from treasury.models import SpecialTransactionProxy, RemittanceType
|
from treasury.models import SpecialTransactionProxy, RemittanceType
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +8,10 @@ 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 and isinstance(instance.source, NoteSpecial) \
|
|
||||||
and RemittanceType.objects.filter(note=instance.source).exists():
|
if instance.is_credit():
|
||||||
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
if created and RemittanceType.objects.filter(note=instance.source).exists():
|
||||||
|
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
||||||
|
else:
|
||||||
|
if created and RemittanceType.objects.filter(note=instance.destination).exists():
|
||||||
|
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
||||||
|
|
Loading…
Reference in New Issue