mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 07:52:23 +00:00
Merge branch 'app_note'
This commit is contained in:
commit
a17c11cd70
0
note/__init__.py
Normal file
0
note/__init__.py
Normal file
9
note/admin.py
Normal file
9
note/admin.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import NoteClub,NoteSpec,NoteUser
|
||||
from .models import Alias
|
||||
# Register your models here.
|
||||
admin.site.register(NoteClub)
|
||||
admin.site.register(NoteSpec)
|
||||
admin.site.register(NoteUser)
|
||||
admin.site.register(Alias)
|
5
note/apps.py
Normal file
5
note/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class NoteConfig(AppConfig):
|
||||
name = 'note'
|
63
note/migrations/0001_initial.py
Normal file
63
note/migrations/0001_initial.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Generated by Django 2.2.3 on 2019-07-08 14:08
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='NoteClub',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('solde', models.IntegerField(help_text="en centime, l' argent crédité pour cette instance", verbose_name='solde du compte')),
|
||||
('active', models.BooleanField(default=True, verbose_name='etat du compte')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='NoteSpec',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('solde', models.IntegerField(help_text="en centime, l' argent crédité pour cette instance", verbose_name='solde du compte')),
|
||||
('active', models.BooleanField(default=True, verbose_name='etat du compte')),
|
||||
('account_type', models.CharField(choices=[('CH', 'chèques'), ('CB', 'Carte Bancaire'), ('VB', 'Virement Bancaire'), ('CA', 'Cash'), ('RB', 'Remboursement')], max_length=2, unique=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='NoteUser',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('solde', models.IntegerField(help_text="en centime, l' argent crédité pour cette instance", verbose_name='solde du compte')),
|
||||
('active', models.BooleanField(default=True, verbose_name='etat du compte')),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': "One's Note",
|
||||
'verbose_name_plural': 'Users Note',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Alias',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('alias', models.TextField(unique=True, verbose_name='alias')),
|
||||
('owner_id', models.PositiveIntegerField()),
|
||||
('owner_type', models.ForeignKey(limit_choices_to=models.Q(models.Q(('app_label', 'note'), ('model', 'NoteUser')), models.Q(('app_label', 'note'), ('model', 'NoteClub')), _connector='OR'), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
||||
],
|
||||
),
|
||||
]
|
0
note/migrations/__init__.py
Normal file
0
note/migrations/__init__.py
Normal file
87
note/models.py
Normal file
87
note/models.py
Normal file
@ -0,0 +1,87 @@
|
||||
# -*- 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
|
||||
from django.db import models
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
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
|
||||
"""
|
||||
|
||||
solde = models.IntegerField(
|
||||
verbose_name=_('solde du compte'),
|
||||
help_text=_("en centime, l' argent crédité pour cette instance")
|
||||
)
|
||||
active = models.BooleanField(
|
||||
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()
|
||||
|
||||
|
||||
class NoteSpec(Note):
|
||||
"""
|
||||
A Note for special Account, where real money enter or leave the system.
|
||||
- Cash
|
||||
- Credit Card
|
||||
- Bank Transfert
|
||||
- Bank Check
|
||||
- Refund
|
||||
"""
|
||||
account_type = models.CharField(
|
||||
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
|
3
note/tests.py
Normal file
3
note/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
note/views.py
Normal file
3
note/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -47,6 +47,7 @@ INSTALLED_APPS = [
|
||||
|
||||
# Note apps
|
||||
'adherents',
|
||||
'note',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
Loading…
Reference in New Issue
Block a user