mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 07:52:23 +00:00
Add remittance model
This commit is contained in:
parent
5ac10b58d5
commit
3551568de5
@ -6,6 +6,7 @@ from django.urls import reverse
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
|
from treasury.models import Remittance
|
||||||
|
|
||||||
from .notes import Note, NoteClub, NoteSpecial
|
from .notes import Note, NoteClub, NoteSpecial
|
||||||
|
|
||||||
@ -209,6 +210,13 @@ class SpecialTransaction(Transaction):
|
|||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
remittance = models.ForeignKey(
|
||||||
|
Remittance,
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
null=True,
|
||||||
|
verbose_name=_("Remittance"),
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
return _('Credit') if isinstance(self.source, NoteSpecial) else _("Debit")
|
return _('Credit') if isinstance(self.source, NoteSpecial) else _("Debit")
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
# 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 django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from note.models import NoteSpecial
|
||||||
|
|
||||||
|
|
||||||
class Invoice(models.Model):
|
class Invoice(models.Model):
|
||||||
@ -83,3 +85,37 @@ class Product(models.Model):
|
|||||||
@property
|
@property
|
||||||
def total_euros(self):
|
def total_euros(self):
|
||||||
return self.total / 100
|
return self.total / 100
|
||||||
|
|
||||||
|
|
||||||
|
class Remittance(models.Model):
|
||||||
|
date = models.DateField(
|
||||||
|
auto_now_add=True,
|
||||||
|
verbose_name=_("Date"),
|
||||||
|
)
|
||||||
|
|
||||||
|
type = models.ForeignKey(
|
||||||
|
NoteSpecial,
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
verbose_name=_("Type"),
|
||||||
|
)
|
||||||
|
|
||||||
|
comment = models.CharField(
|
||||||
|
max_length=255,
|
||||||
|
verbose_name=_("Comment"),
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self):
|
||||||
|
return self.specialtransaction_set.count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def amount(self):
|
||||||
|
return sum(transaction.total for transaction in self.specialtransaction_set.all())
|
||||||
|
|
||||||
|
def full_clean(self, exclude=None, validate_unique=True):
|
||||||
|
ret = super().full_clean(exclude, validate_unique)
|
||||||
|
|
||||||
|
if self.specialtransaction_set.filter(~Q(source=self.type)).exists():
|
||||||
|
raise ValidationError("All transactions in a remittance must have the same type")
|
||||||
|
|
||||||
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user