2019-07-16 10:43:23 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from .notes import Note
|
|
|
|
|
|
|
|
"""
|
|
|
|
Defines transactions
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class TransactionTemplate(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
verbose_name=_('name'),
|
|
|
|
max_length=255,
|
|
|
|
)
|
|
|
|
destination = models.ForeignKey(
|
|
|
|
Note,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name='+', # no reverse
|
|
|
|
verbose_name=_('destination'),
|
|
|
|
)
|
|
|
|
amount = models.PositiveIntegerField(
|
|
|
|
verbose_name=_('amount'),
|
2019-07-17 09:17:50 +00:00
|
|
|
help_text=_('in centimes'),
|
2019-07-16 10:43:23 +00:00
|
|
|
)
|
|
|
|
template_type = models.CharField(
|
|
|
|
verbose_name=_('type'),
|
|
|
|
max_length=31
|
|
|
|
)
|
|
|
|
|
2019-07-16 11:50:05 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("transaction template")
|
|
|
|
verbose_name_plural = _("transaction templates")
|
|
|
|
|
2019-07-16 10:43:23 +00:00
|
|
|
|
|
|
|
class Transaction(models.Model):
|
|
|
|
source = models.ForeignKey(
|
|
|
|
Note,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name='+',
|
|
|
|
verbose_name=_('source'),
|
|
|
|
)
|
|
|
|
destination = models.ForeignKey(
|
|
|
|
Note,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name='+',
|
|
|
|
verbose_name=_('destination'),
|
|
|
|
)
|
2019-07-17 10:48:03 +00:00
|
|
|
created_at = models.DateTimeField(
|
|
|
|
verbose_name=_('created at'),
|
2019-07-16 10:43:23 +00:00
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
quantity = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_('quantity'),
|
|
|
|
)
|
|
|
|
amount = models.PositiveIntegerField(
|
|
|
|
verbose_name=_('amount'),
|
|
|
|
)
|
|
|
|
transaction_type = models.CharField(
|
|
|
|
verbose_name=_('type'),
|
|
|
|
max_length=31,
|
|
|
|
)
|
|
|
|
description = models.TextField(
|
|
|
|
verbose_name=_('description'),
|
|
|
|
)
|
|
|
|
valid = models.NullBooleanField(
|
|
|
|
verbose_name=_('valid'),
|
|
|
|
)
|
|
|
|
|
2019-07-16 11:50:05 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("transaction")
|
|
|
|
verbose_name_plural = _("transactions")
|
|
|
|
|
2019-07-16 10:43:23 +00:00
|
|
|
|
|
|
|
class MembershipTransaction(Transaction):
|
|
|
|
membership = models.OneToOneField(
|
|
|
|
'member.Membership',
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name='transaction',
|
|
|
|
)
|
2019-07-16 11:50:05 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("membership transaction")
|
|
|
|
verbose_name_plural = _("membership transactions")
|