nk20/note/models/notes.py

105 lines
2.3 KiB
Python
Raw Normal View History

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.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
"""
Defines each note types
"""
class Note(models.Model):
"""
2019-07-16 11:50:05 +00:00
An model, use to add transactions capabilities
We do not use an abstract model to simplify the transfer between two notes.
2019-07-16 10:43:23 +00:00
"""
balance = models.IntegerField(
verbose_name=_('account balance'),
help_text=_('in centimes, money credited for this instance'),
)
is_active = models.BooleanField(
_('active'),
default=True,
help_text=_(
'Designates whether this note should be treated as active. '
'Unselect this instead of deleting notes.'
),
)
2019-07-16 11:50:05 +00:00
class Meta:
verbose_name = _("note")
verbose_name_plural = _("notes")
2019-07-16 10:43:23 +00:00
class NoteUser(Note):
"""
A Note associated to an User
"""
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
related_name='note',
)
class Meta:
verbose_name = _("one's note")
verbose_name_plural = _("users note")
class NoteClub(Note):
"""
A Note associated to a Club
"""
2019-07-16 12:38:52 +00:00
club = models.OneToOneField(
2019-07-16 10:43:23 +00:00
'member.Club',
on_delete=models.PROTECT,
related_name='note',
)
class Meta:
verbose_name = _("club note")
verbose_name_plural = _("clubs notes")
class NoteSpecial(Note):
"""
A Note for special account, where real money enter or leave the system
- bank check
- credit card
- bank transfer
- cash
- refund
"""
special_type = models.CharField(
verbose_name=_('type'),
max_length=255,
unique=True,
)
2019-07-16 11:50:05 +00:00
class Meta:
verbose_name = _("special note")
verbose_name_plural = _("special notes")
2019-07-16 10:43:23 +00:00
class Alias(models.Model):
"""
An alias labels a Note instance, only for user and clubs
"""
name = models.CharField(
verbose_name=_('name'),
max_length=255,
unique=True,
)
note = models.ForeignKey(
Note,
on_delete=models.PROTECT,
)
2019-07-16 11:50:05 +00:00
class Meta:
verbose_name = _("alias")
verbose_name_plural = _("aliases")