Added vente

This commit is contained in:
Julien MALKA 2020-02-18 18:25:54 +01:00
parent db9be39f76
commit 5952ef1cbf
11 changed files with 281 additions and 126 deletions

View file

@ -1,106 +0,0 @@
#!/usr/bin/env bash
# pre-commit hook for gestioCOF project.
#
# Run formatters first, then checkers.
# Formatters which changed a file must set the flag 'formatter_updated'.
exit_code=0
formatter_updated=0
checker_dirty=0
# TODO(AD): We should check only staged changes.
# Working? -> Stash unstaged changes, run it, pop stash
STAGED_PYTHON_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".py$")
# Formatter: black
printf "> black ... "
if type black &>/dev/null; then
if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n"
else
BLACK_OUTPUT="/tmp/gc-black-output.log"
touch $BLACK_OUTPUT
if ! echo "$STAGED_PYTHON_FILES" | xargs -d'\n' black --check &>$BLACK_OUTPUT; then
echo "$STAGED_PYTHON_FILES" | xargs -d'\n' black &>$BLACK_OUTPUT
tail -1 $BLACK_OUTPUT
formatter_updated=1
else
printf "OK\n"
fi
fi
else
printf "SKIP: program not found\n"
printf "HINT: Install black with 'pip3 install black' (black requires Python>=3.6)\n"
fi
# Formatter: isort
printf "> isort ... "
if type isort &>/dev/null; then
if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n"
else
ISORT_OUTPUT="/tmp/gc-isort-output.log"
touch $ISORT_OUTPUT
if ! echo "$STAGED_PYTHON_FILES" | xargs -d'\n' isort --check-only &>$ISORT_OUTPUT; then
echo "$STAGED_PYTHON_FILES" | xargs -d'\n' isort &>$ISORT_OUTPUT
printf "Reformatted.\n"
formatter_updated=1
else
printf "OK\n"
fi
fi
else
printf "SKIP: program not found\n"
printf "HINT: Install isort with 'pip install isort'\n"
fi
# Checker: flake8
printf "> flake8 ... "
if type flake8 &>/dev/null; then
if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n"
else
FLAKE8_OUTPUT="/tmp/gc-flake8-output.log"
touch $FLAKE8_OUTPUT
if ! echo "$STAGED_PYTHON_FILES" | xargs -d'\n' flake8 &>$FLAKE8_OUTPUT; then
printf "FAIL\n"
cat $FLAKE8_OUTPUT
checker_dirty=1
else
printf "OK\n"
fi
fi
else
printf "SKIP: program not found\n"
printf "HINT: Install flake8 with 'pip install flake8'\n"
fi
# End
if [ $checker_dirty -ne 0 ]
then
printf ">>> Checker(s) detect(s) issue(s)\n"
printf " You can still commit and push :)\n"
printf " Be warned that our CI may cause you more trouble.\n"
fi
if [ $formatter_updated -ne 0 ]
then
printf ">>> Working tree updated by formatter(s)\n"
printf " Add changes to staging area and retry.\n"
exit_code=1
fi
printf "\n"
exit $exit_code

View file

@ -92,7 +92,7 @@
</ul>
</div>
<h3 class="block-title">Journal de Caisse<span class="pull-right glyphicon glyphicon-cog"></span></h3>
<h3 class="block-title">Kaisse<span class="pull-right glyphicon glyphicon-cog"></span></h3>
<div class="hm-block">
<ul>
<h4>Journaux</h4>
@ -101,12 +101,12 @@
</ul>
<ul>
<h4>Vente</h4>
{% for event in events %}
<li><a href="{% url "event.details.status" event.id %}">Événement : {{ event.title }}</a></li>
{% endfor %}
{% for survey in surveys %}
<li><a href="{% url "survey.details.status" survey.id %}">Sondage : {{ survey.title }}</a></li>
{% endfor %}
<li><a href="{% url "journaldecaisse:vente" %}">Vente Burô</a></li>
<li><a href="{% url "journaldecaisse:vente" %}">Vente BDA</a></li>
</ul>
</div>
<h3 class="block-title">Gestion tirages BdA<span class="pull-right glyphicon glyphicon-list"></span></h3>

View file

@ -1,10 +1,13 @@
from django.contrib import admin
from .models import JournalEntry
from .models import JournalEntry, Produit, ProduitStock, Option
class JournalAdmin(admin.ModelAdmin):
list_display = ('entry_text', 'cofeux_id', 'payment_type')
admin.site.register(JournalEntry, JournalAdmin)
admin.site.register(JournalEntry, JournalAdmin)
admin.site.register(Option)
admin.site.register(Produit)
admin.site.register(ProduitStock)

View file

@ -1,6 +1,7 @@
# Generated by Django 2.2.9 on 2020-02-16 17:14
# Generated by Django 2.2.10 on 2020-02-18 15:01
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
@ -15,11 +16,39 @@ class Migration(migrations.Migration):
name='JournalEntry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('entry_text', models.CharField(max_length=500)),
('entry_date', models.DateTimeField(verbose_name='date published')),
('cofeux_id', models.CharField(max_length=8)),
('entry_amount', models.FloatField()),
('payment_type', models.CharField(choices=[('cash', 'Espèces'), ('cb', 'CB'), ('check', 'Chèque')], max_length=20, verbose_name='Niveau')),
('entry_text', models.CharField(max_length=500, verbose_name='Détail entrée')),
('entry_date', models.DateTimeField(verbose_name='Date')),
('cofeux_id', models.CharField(max_length=8, verbose_name='Trigramme')),
('entry_amount', models.FloatField(verbose_name='Montant')),
('payment_type', models.CharField(choices=[('Espèces', 'Espèces'), ('CB', 'CB'), ('Chèque', 'Chèque')], max_length=20, verbose_name='Moyen de paiement')),
],
options={
'verbose_name': 'Entrée du JDC',
'verbose_name_plural': 'Entrées du JDC',
},
),
migrations.CreateModel(
name='Option',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='Nom')),
],
),
migrations.CreateModel(
name='Produit',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('Produit', models.CharField(max_length=100, verbose_name='Nom')),
('option_1_value', models.CharField(max_length=100, verbose_name='Option 1 Valeur')),
('option_1', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='journaldecaisse.Option')),
],
),
migrations.CreateModel(
name='ProduitStock',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('Amount', models.IntegerField(verbose_name='Nombre en Stock')),
('ProduitTaille', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='journaldecaisse.Produit')),
],
),
]

View file

@ -0,0 +1,67 @@
# Generated by Django 2.2.10 on 2020-02-18 15:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('journaldecaisse', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='produit',
name='option_2',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='option_2', to='journaldecaisse.Option'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_2_value',
field=models.CharField(default=0, max_length=100, verbose_name='Option 2 Valeur'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_3',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='option_3', to='journaldecaisse.Option'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_3_value',
field=models.CharField(default=0, max_length=100, verbose_name='Option 3 Valeur'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_4',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='option_4', to='journaldecaisse.Option'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_4_value',
field=models.CharField(default=0, max_length=100, verbose_name='Option 4 Valeur'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_5',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='option_5', to='journaldecaisse.Option'),
preserve_default=False,
),
migrations.AddField(
model_name='produit',
name='option_5_value',
field=models.CharField(default=0, max_length=100, verbose_name='Option 5 Valeur'),
preserve_default=False,
),
migrations.AlterField(
model_name='produit',
name='option_1',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='option_1', to='journaldecaisse.Option'),
),
]

View file

@ -0,0 +1,38 @@
# Generated by Django 2.2.10 on 2020-02-18 15:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('journaldecaisse', '0002_auto_20200218_1607'),
]
operations = [
migrations.AlterField(
model_name='produit',
name='option_1_value',
field=models.CharField(blank=True, max_length=100, verbose_name='Option 1 Valeur'),
),
migrations.AlterField(
model_name='produit',
name='option_2_value',
field=models.CharField(blank=True, max_length=100, verbose_name='Option 2 Valeur'),
),
migrations.AlterField(
model_name='produit',
name='option_3_value',
field=models.CharField(blank=True, max_length=100, verbose_name='Option 3 Valeur'),
),
migrations.AlterField(
model_name='produit',
name='option_4_value',
field=models.CharField(blank=True, max_length=100, verbose_name='Option 4 Valeur'),
),
migrations.AlterField(
model_name='produit',
name='option_5_value',
field=models.CharField(blank=True, max_length=100, verbose_name='Option 5 Valeur'),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 2.2.10 on 2020-02-18 15:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('journaldecaisse', '0003_auto_20200218_1610'),
]
operations = [
migrations.AddField(
model_name='produit',
name='price',
field=models.FloatField(default=0, verbose_name='Prix'),
preserve_default=False,
),
]

View file

@ -8,16 +8,51 @@ PAYMENTS_CHOICES = (
)
class JournalEntry(models.Model):
entry_text = models.CharField(max_length=500)
entry_text = models.CharField("Détail entrée", max_length=500)
entry_date = models.DateTimeField('Date')
cofeux_id = models.CharField("Trigramme", max_length=8)
entry_amount = models.FloatField()
entry_amount = models.FloatField("Montant")
payment_type = models.CharField(
_("Moyen de paiement"), choices=PAYMENTS_CHOICES, max_length=20
)
def __str__(self):
return self.entry_text
class Meta:
verbose_name = 'Entrée du JDC'
verbose_name_plural = 'Entrées du JDC'
class Option(models.Model):
name = models.CharField("Nom", max_length=100)
def __str__(self):
return self.name
class Produit(models.Model):
Produit = models.CharField("Nom", max_length=100)
option_1 = models.ForeignKey(Option, on_delete=models.CASCADE, related_name="option_1")
option_1_value = models.CharField("Option 1 Valeur", max_length=100, blank=True)
option_2 = models.ForeignKey(Option, on_delete=models.CASCADE, related_name="option_2")
option_2_value = models.CharField("Option 2 Valeur", max_length=100, blank=True)
option_3 = models.ForeignKey(Option, on_delete=models.CASCADE, related_name="option_3")
option_3_value = models.CharField("Option 3 Valeur", max_length=100, blank=True)
option_4 = models.ForeignKey(Option, on_delete=models.CASCADE, related_name="option_4")
option_4_value = models.CharField("Option 4 Valeur", max_length=100, blank=True)
option_5 = models.ForeignKey(Option, on_delete=models.CASCADE, related_name="option_5")
option_5_value = models.CharField("Option 5 Valeur", max_length=100, blank=True)
price = models.FloatField("Prix")
def __str__(self):
name = str(self.Produit) + " " + self.option_1_value + " " + self.option_2_value + " " + self.option_3_value + " " + self.option_4_value + " " + self.option_5_value + str(self.price) +""
return name
class ProduitStock(models.Model):
ProduitTaille = models.ForeignKey(Produit, on_delete=models.CASCADE)
Amount = models.IntegerField("Nombre en Stock")
def __str__(self):
return str(self.ProduitTaille) + " : " + str(self.Amount)

View file

@ -0,0 +1,37 @@
{% extends "petitscours/base_title.html" %}
{% load staticfiles %}
{% block realcontent %}
<h2>Vente</h2>
{% for product in product_list %}
<button id="button_option" value="Produit:{{ product }}">{{ product }}</button>
{% endfor %}
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script>
$(document).ready(function() {
$(document).on("click", "#button_option", function () {
var option_clicked = $(this).val();
console.log(option_clicked)
$.ajax({
url: 'ajax/iterate_options/',
data: {
'option': option_clicked
},
dataType: 'json',
success: function (data) {
alert(data);
}
});
});});
</script>
{% endblock %}

View file

@ -1,8 +1,13 @@
from django.urls import path
from django.conf.urls import url
from . import views
app_name = 'journaldecaisse'
urlpatterns = [
path('', views.index, name='index'),
]
path('vente.html', views.vente, name='vente'),
url(r'^ajax/iterate_options/$', views.iterate_options, name='iterate_options'),
]

View file

@ -1,8 +1,36 @@
from django.http import HttpResponse
from .models import JournalEntry
from .models import JournalEntry, Produit
from django.shortcuts import render
from django.http import JsonResponse
def index(request):
entry_list = JournalEntry.objects.order_by('entry_date')
context = {'entry_list': entry_list}
return render(request, 'journaldecaisse/index.html', context)
return render(request, 'journaldecaisse/index.html', context)
def vente(request):
product_list = Produit.objects.all().values_list()
products = []
for elem in product_list:
products.append(elem[1])
products = list(set(products))
context = {"product_list" : products}
return render(request, 'journaldecaisse/vente.html', context)
def iterate_options(request):
options_selected = request.GET.get('option', None)
options_selected = options_selected.split(":")
print(options_selected)
test = Produit.objects.filter(**{ options_selected[0] : options_selected[1] })
print(test)
data = {
'is_taken': None
}
return JsonResponse(data)