From 53748cd5346e88ede168c72c2b2d78a0541a77e9 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 18 Apr 2020 15:57:11 +0200 Subject: [PATCH 1/4] frenglish -> english --- apps/treasury/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/treasury/models.py b/apps/treasury/models.py index ca1da3a4..9d7ee848 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -189,7 +189,7 @@ class SpecialTransactionProxy(models.Model): """ 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. - 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( From cc97948c244cb5513829259bdee3705573406ccb Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 18 Apr 2020 15:59:06 +0200 Subject: [PATCH 2/4] clean specialTransaction --- apps/note/models/transactions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 83f8f914..80b22b59 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -252,6 +252,17 @@ class SpecialTransaction(Transaction): def type(self): 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): """ From 038ddc2ab87ab384d85948a7fafa1b403bafab47 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 18 Apr 2020 15:59:59 +0200 Subject: [PATCH 3/4] remittance need preciser check (bug during import) --- apps/treasury/signals.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/treasury/signals.py b/apps/treasury/signals.py index 54c19c09..b7038ab6 100644 --- a/apps/treasury/signals.py +++ b/apps/treasury/signals.py @@ -8,5 +8,10 @@ def save_special_transaction(instance, created, **kwargs): """ When a special transaction is created, we create its linked proxy """ - if created and RemittanceType.objects.filter(note=instance.source).exists(): - SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save() + + if instance.is_credit(): + 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() From 6d27193ac476a1d9bebaba4a06389f6456b023e3 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 18 Apr 2020 16:07:45 +0200 Subject: [PATCH 4/4] update import script --- apps/scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/scripts b/apps/scripts index b9fdced3..b9db26fa 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit b9fdced3c2ce34168b8f0d6004a20a69ca16e0de +Subproject commit b9db26fa494870b02fc1b4b463a2322395a278a1