models.py 2.32 KB
Newer Older
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
1
2
3
4
5
6
# -*- 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.contrib.auth.models import User
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
7
8
from django.db import models

Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
9
from django.utils.translation import gettext_lazy as _
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey


class Alias(models.Model):
    """
    A alias labels a Note instance, only for user and clubs
    """
    alias = models.TextField(
        "alias",
        unique = True,
        blank = False,
        null = False,
    )
    limit = models.Q(app_label="note", model="NoteUser") | models.Q(app_label="note",model="NoteClub")

    owner_id = models.PositiveIntegerField()
    owner_type = models.ForeignKey(ContentType,
                                   on_delete=models.CASCADE,
                                   limit_choices_to=limit)
    owner = GenericForeignKey('owner_type','owner_id')

class Note(models.Model):
    """
    An abstract model, use to add transactions capabilities to a user
    """

Pierre-antoine Comby's avatar
modelS    
Pierre-antoine Comby committed
37
    solde = models.IntegerField(
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
38
39
40
        verbose_name=_('solde du compte'),
        help_text=_("en centime, l' argent crédité pour cette instance")
    )
Pierre-antoine Comby's avatar
modelS    
Pierre-antoine Comby committed
41
    active = models.BooleanField(
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        default = True,
        verbose_name=_('etat du compte')
    )

    class Meta:
        abstract = True

class NoteUser(Note):
    """
    A Note associated to a User
    """
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
    )
    class Meta:
        verbose_name = _("One's Note")
        verbose_name_plural = _("Users Note")

    def __str__(self):
        return self.user.get_username()

Pierre-antoine Comby's avatar
modelS    
Pierre-antoine Comby committed
64
    aliases = models.ForeignKey(Aliases)
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
65
66
67
68
69
70
71
72
73
74
75
76



class NoteSpec(Note):
    """
    A Note for special Account, where real money enter or leave the system.
     - Cash
     - Credit Card
     - Bank Transfert
     - Bank Check
     - Refund
    """
Pierre-antoine Comby's avatar
modelS    
Pierre-antoine Comby committed
77
    account_type = models.CharField(
Pierre-antoine Comby's avatar
Pierre-antoine Comby committed
78
79
80
81
82
83
84
85
86
87
88
89
90
        max_length = 2,
        choices = (("CH","chèques"),
                   ("CB","Carte Bancaire"),
                   ("VB","Virement Bancaire"),
                   ("CA","Cash"),
                   ("RB","Remboursement")
        ),
        unique = True
    )

class NoteClub(Note):
    #to be added
    pass