3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-23 15:33:45 +00:00

Création des models

This commit is contained in:
Yoann Pétri 2018-08-31 14:46:35 +02:00
parent 13160f14c3
commit 30d62032a9
25 changed files with 508 additions and 2 deletions

View file

@ -37,6 +37,9 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'gestion',
'users',
'preferences',
]
MIDDLEWARE = [
@ -103,9 +106,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True

0
gestion/__init__.py Normal file
View file

3
gestion/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
gestion/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class GestionConfig(AppConfig):
name = 'gestion'

View file

@ -0,0 +1,154 @@
# Generated by Django 2.1 on 2018-08-31 12:45
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import gestion.models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('preferences', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Barrel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
('stockHold', models.IntegerField(default=0)),
('barcode', models.CharField(max_length=20, unique=True)),
('amount', models.DecimalField(decimal_places=2, max_digits=5)),
('capacity', models.IntegerField(default=30)),
('active', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='ConsumptionHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField(default=0)),
('date', models.DateTimeField(auto_now_add=True)),
('amount', models.DecimalField(decimal_places=2, default=0, max_digits=7)),
('coopeman', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='consumption_selled', to=settings.AUTH_USER_MODEL)),
('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='consumption_taken', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Menu',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('amount', models.DecimalField(decimal_places=2, max_digits=5)),
('barcode', models.CharField(max_length=20, unique=True)),
('is_active', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='MenuHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField(default=0)),
('date', models.DateTimeField(auto_now_add=True)),
('amount', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
('PaymentMethod', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='preferences.PaymentMethod')),
('coopeman', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='menu_selled', to=settings.AUTH_USER_MODEL)),
('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='menu_taken', to=settings.AUTH_USER_MODEL)),
('menu', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='gestion.Menu')),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=40)),
('amount', models.DecimalField(decimal_places=2, max_digits=5)),
('stockHold', models.IntegerField(default=0)),
('stockBar', models.IntegerField(default=0)),
('barcode', models.CharField(max_length=20, unique=True)),
('category', models.CharField(choices=[('PP', 'Pinte Pression'), ('DP', 'Demi Pression'), ('GP', 'Galopin pression'), ('BT', 'Bouteille'), ('SO', 'Soft'), ('FO', 'Bouffe')], default='FO', max_length=2)),
('needQuantityButton', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('is_beer', models.BooleanField(default=False)),
('volume', models.IntegerField(default=0)),
('deg', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
],
),
migrations.CreateModel(
name='Raming',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now_add=True)),
('barrel', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='gestion.Barrel')),
('coopeman', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Refund',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now_add=True)),
('amount', models.DecimalField(decimal_places=2, max_digits=5)),
('coopeman', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='refund_realized', to=settings.AUTH_USER_MODEL)),
('cutsomer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='refund_taken', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Reload',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.DecimalField(decimal_places=2, max_digits=5)),
('date', models.DateTimeField(auto_now_add=True)),
('PaymentMethod', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='preferences.PaymentMethod')),
('coopeman', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='reload_realized', to=settings.AUTH_USER_MODEL)),
('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='reload_taken', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Stocking',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now_add=True)),
],
),
migrations.AddField(
model_name='menu',
name='articles',
field=models.ManyToManyField(to='gestion.Product'),
),
migrations.AddField(
model_name='consumptionhistory',
name='menu',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='gestion.MenuHistory'),
),
migrations.AddField(
model_name='consumptionhistory',
name='paymentMethod',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='preferences.PaymentMethod'),
),
migrations.AddField(
model_name='consumptionhistory',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='gestion.Product'),
),
migrations.AddField(
model_name='barrel',
name='demi',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='futd', to='gestion.Product', validators=[gestion.models.isDemi]),
),
migrations.AddField(
model_name='barrel',
name='galopin',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='futg', to='gestion.Product', validators=[gestion.models.isGalopin]),
),
migrations.AddField(
model_name='barrel',
name='pinte',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='futp', to='gestion.Product', validators=[gestion.models.isPinte]),
),
]

View file

143
gestion/models.py Normal file
View file

@ -0,0 +1,143 @@
from django.db import models
from django.contrib.auth.models import User
from preferences.models import PaymentMethod
class Product(models.Model):
P_PRESSION = 'PP'
D_PRESSION = 'DP'
G_PRESSION = 'GP'
BOTTLE = 'BT'
SOFT = 'SO'
FOOD = 'FO'
TYPEINPUT_CHOICES_CATEGORIE = (
(P_PRESSION, "Pinte Pression"),
(D_PRESSION, "Demi Pression"),
(G_PRESSION, "Galopin pression"),
(BOTTLE, "Bouteille"),
(SOFT, "Soft"),
(FOOD, "Bouffe"),
)
name = models.CharField(max_length=40)
amount = models.DecimalField(max_digits=5, decimal_places=2)
stockHold = models.IntegerField(default=0)
stockBar = models.IntegerField(default=0)
barcode= models.CharField(max_length=20, unique=True)
category = models.CharField(max_length=2, choices=TYPEINPUT_CHOICES_CATEGORIE, default=FOOD)
needQuantityButton = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
is_beer = models.BooleanField(default=False)
volume = models.IntegerField(default=0)
deg = models.DecimalField(default=0,max_digits=5, decimal_places=2)
def __str__(self):
return self.nom
def isPinte(id):
product = Product.objects.get(id=id)
if product.category != Product.P_PRESSION:
raise ValidationError(
('%(product)s n\'est pas une pinte'),
params={'product': product},
)
def isDemi(id):
product = Product.objects.get(id=id)
if produit.category != Product.D_PRESSION:
raise ValidationError(
('%(product)s n\'est pas un demi'),
params={'product': product},
)
def isGalopin(id):
product = Product.objects.get(id)
if product.category != Product.G_PRESSION:
raise ValidationError(
('%(product)s n\'est pas un galopin'),
params={'product': product},
)
class Barrel(models.Model):
name = models.CharField(max_length=20)
stockHold = models.IntegerField(default=0)
barcode = models.CharField(max_length=20, unique=True)
amount = models.DecimalField(max_digits=5, decimal_places=2)
capacity = models.IntegerField(default=30)
pinte = models.ForeignKey(Product, on_delete=models.PROTECT, related_name="futp", validators=[isPinte])
demi = models.ForeignKey(Product, on_delete=models.PROTECT, related_name="futd", validators=[isDemi])
galopin = models.ForeignKey(Product, on_delete=models.PROTECT, related_name="futg", validators=[isGalopin],null=True, blank=True)
active= models.BooleanField(default=False)
def __str__(self):
return self.name
class Reload(models.Model):
customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="reload_taken")
amount = models.DecimalField(max_digits=5, decimal_places=2)
PaymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="reload_realized")
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "Rechargement effectue par {0} le {1} ({2} euros, coopeman : {3})".format(self.customer, self.date, self.amount, self.coopeman)
class Raming(models.Model):
barrel = models.ForeignKey(Barrel, on_delete=models.PROTECT)
coopeman = models.ForeignKey(User, on_delete=models.PROTECT)
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "Percussion d'un {0} effectué par {1} le {2}".format(self.barrel, self.coopeman, self.date)
class Stocking(models.Model):
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "Inventaire fait le {0}".format(self.date)
class Refund(models.Model):
date = models.DateTimeField(auto_now_add=True)
cutsomer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="refund_taken")
amount = models.DecimalField(max_digits=5, decimal_places=2)
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="refund_realized")
def __str__(self):
return "{0} remboursé de {1} le {2} (effectué par {3})".format(self.customer, self.amount, self.date, self.coopeman)
class Menu(models.Model):
name = models.CharField(max_length=255)
amount = models.DecimalField(max_digits=5, decimal_places=2)
barcode = models.CharField(max_length=20, unique=True)
articles = models.ManyToManyField(Product)
is_active = models.BooleanField(default=False)
def __str__(self):
return self.name
class MenuHistory(models.Model):
customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="menu_taken")
quantity = models.PositiveIntegerField(default=0)
PaymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
date = models.DateTimeField(auto_now_add=True)
menu = models.ForeignKey(Menu, on_delete=models.PROTECT)
amount = models.DecimalField(max_digits=5, decimal_places=2, default=0)
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="menu_selled")
def __str__(self):
return "{2} a consommé {0} {1}".format(self.quantite, self.menu, self.client)
class ConsumptionHistory(models.Model):
customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_taken")
quantity = models.PositiveIntegerField(default=0)
paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
date = models.DateTimeField(auto_now_add=True)
product = models.ForeignKey(Product, on_delete=models.PROTECT)
menu = models.ForeignKey(MenuHistory, on_delete=models.CASCADE, null=True, blank=True)
amount = models.DecimalField(max_digits=7, decimal_places=2, default=0)
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_selled")
def __str__(self):
return "{0} {1} consommé par {2} le {3} (encaissé par {4})".format(self.quantity, self.product, self.customer, self.date, self.coopeman)

3
gestion/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
gestion/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
preferences/__init__.py Normal file
View file

3
preferences/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
preferences/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class PreferencesConfig(AppConfig):
name = 'preferences'

View file

@ -0,0 +1,36 @@
# Generated by Django 2.1 on 2018-08-31 12:45
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='GeneralPreferences',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_active', models.BooleanField(default=True)),
('active_message', models.TextField(blank=True)),
('global_message', models.TextField(blank=True)),
('president', models.CharField(blank=True, max_length=255)),
('vice_president', models.CharField(blank=True, max_length=255)),
('treasurer', models.CharField(blank=True, max_length=255)),
('secretary', models.CharField(blank=True, max_length=255)),
('brewer', models.CharField(blank=True, max_length=255)),
('grocer', models.CharField(blank=True, max_length=255)),
],
),
migrations.CreateModel(
name='PaymentMethod',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
]

View file

18
preferences/models.py Normal file
View file

@ -0,0 +1,18 @@
from django.db import models
class PaymentMethod(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class GeneralPreferences(models.Model):
is_active = models.BooleanField(default=True)
active_message = models.TextField(blank=True)
global_message = models.TextField(blank=True)
president = models.CharField(max_length=255, blank=True)
vice_president = models.CharField(max_length=255, blank=True)
treasurer = models.CharField(max_length=255, blank=True)
secretary = models.CharField(max_length=255, blank=True)
brewer = models.CharField(max_length=255, blank=True)
grocer = models.CharField(max_length=255, blank=True)

3
preferences/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
preferences/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
users/__init__.py Normal file
View file

3
users/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
users/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'

View file

@ -0,0 +1,55 @@
# Generated by Django 2.1 on 2018-08-31 12:45
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('preferences', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Cotisation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.DecimalField(decimal_places=2, max_digits=5)),
('paymentDate', models.DateTimeField(auto_now_add=True)),
('endDate', models.DateTimeField()),
('paymentMethod', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='preferences.PaymentMethod')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('credit', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
('debit', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
('cotisationEnd', models.DateTimeField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='School',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.AddField(
model_name='profile',
name='school',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.School'),
),
migrations.AddField(
model_name='profile',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View file

55
users/models.py Normal file
View file

@ -0,0 +1,55 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from preferences.models import PaymentMethod
class School(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Cotisation(models.Model):
user = models.ForeignKey(User, on_delete=models.PROTECT)
amount = models.DecimalField(max_digits=5, decimal_places=2)
paymentDate = models.DateTimeField(auto_now_add=True)
endDate = models.DateTimeField()
paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
credit = models.DecimalField(max_digits=5, decimal_places=2, default=0)
debit = models.DecimalField(max_digits=5, decimal_places=2, default=0)
school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True)
cotisationEnd = models.DateTimeField(blank=True, null=True)
@property
def solde(self):
return self.credit - self.debit
def soldePositif(self):
return self.solde() >= 0
@property
def classement(self):
return Compte.objects.filter(debit__gte=self.debit).count()
@property
def alcool(self):
consos = Consommation.objects.filter(client=self).select_related('produit')
alcool = 0
for conso in consos:
produit = conso.produit
alcool += conso.nombre * float(produit.deg) * produit.volume * 0.79 /10 /1000
return alcool
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()

3
users/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
users/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.