Compare commits

...

5 commits

Author SHA1 Message Date
Julien MALKA
f4115d2868 Basic fonctionnality of Vente done 2020-02-19 18:43:42 +01:00
Julien Malka
eb5b459294 Fetch list of products 2020-02-18 22:02:46 +01:00
Julien MALKA
5952ef1cbf Added vente 2020-02-18 18:25:54 +01:00
Julien Malka
db9be39f76 Added journal 2020-02-17 11:40:58 +01:00
Julien Malka
df0dd6cedc Added Entry model 2020-02-16 18:37:16 +01:00
18 changed files with 540 additions and 106 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

@ -75,6 +75,7 @@ INSTALLED_APPS = [
"django.contrib.admindocs",
"bda",
"petitscours",
"journaldecaisse.apps.JournaldecaisseConfig",
"captcha",
"django_cas_ng",
"bootstrapform",

View file

@ -16,6 +16,8 @@ from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from gestioncof import csv_views, views as gestioncof_views
from gestioncof.autocomplete import autocomplete
from gestioncof.urls import (
@ -43,6 +45,8 @@ urlpatterns = [
path("event/", include(events_patterns)),
# Calendrier
path("calendar/", include(calendar_patterns)),
#Journal de Caisse
path('journaldecaisse/', include('journaldecaisse.urls', namespace="journaldecaisse")),
# Clubs
path("clubs/", include(clubs_patterns)),
# Authentification

View file

@ -91,6 +91,24 @@
{% endfor %}
</ul>
</div>
<h3 class="block-title">Kaisse<span class="pull-right glyphicon glyphicon-cog"></span></h3>
<div class="hm-block">
<ul>
<h4>Journaux</h4>
<li><a href="{% url "journaldecaisse:index" %}">Journal de Kaisse</a></li>
<li><a href="{% url "petits-cours-demandes-list" %}">Journal d'Emprunts</a></li>
</ul>
<ul>
<h4>Vente</h4>
<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>
<div class="hm-block">
{% if active_tirages %}

View file

13
journaldecaisse/admin.py Normal file
View file

@ -0,0 +1,13 @@
from django.contrib import admin
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(Option)
admin.site.register(Produit)
admin.site.register(ProduitStock)

6
journaldecaisse/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class JournaldecaisseConfig(AppConfig):
name = "journaldecaisse"

View file

@ -0,0 +1,54 @@
# 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):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='JournalEntry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('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

58
journaldecaisse/models.py Normal file
View file

@ -0,0 +1,58 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
PAYMENTS_CHOICES = (
("Espèces", _("Espèces")),
("CB", _("CB")),
("Chèque", _("Chèque")),
)
class JournalEntry(models.Model):
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("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
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,45 @@
{% extends "petitscours/base_title.html" %}
{% load staticfiles %}
{% block realcontent %}
<h2>Journal de Kaisse</h2>
{% if entry_list %}
<table class="table table-stripped">
<thead>
<th>Date</th>
<th>Cofeux.se</th>
<th>Objet</th>
<th>Moyen de Paiement</th>
<th>Montant</th>
</thead>
<tbody>
{% for entry in entry_list %}
<tr>
<td>{{ entry.entry_date|date:"M d, Y" }}</td>
<td>{{ entry.cofeux_id }}</td>
<td>{{ entry.entry_text }}</td>
<td> {{ entry.payment_type}}</td>
<td> {{ entry.entry_amount }}€</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if is_paginated %}
<div class="pagination">
<span class="page-links">
{% if page_obj.has_previous %}
<a href="{% url "petits-cours-demandes-list" %}?page={{ page_obj.previous_page_number }}">&lt;</a>
{% endif %}
<span class="page-current">
Page {{ page_obj.number }} sur {{ page_obj.paginator.num_pages }}
</span>
{% if page_obj.has_next %}
<a href="{% url "petits-cours-demandes-list" %}?page={{ page_obj.next_page_number }}">&gt;</a>
{% endif %}
</span>
</div>
{% endif %}
{% else %}
<p>Aucune demande :(</p>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,124 @@
{% extends "petitscours/base_title.html" %}
{% load staticfiles %}
{% block realcontent %}
<h2>Vente</h2>
<div id="lol">
{% for product in product_list %}
<button id="button_option" value="Produit:{{ product }}:1">{{ product }}</button>
{% endfor %}
</div>
<div id="ligne-jdc"></div>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script>
var data_received = null
function addButton(elem, index, option, option_int){
var r = $('<button id="button_option" value="'+option+':'+elem+':'+option_int+'">'+ elem + '</button>');
$("#lol").append(r)
}
function runAllfunction(){
display_jdc()
button_handler()
}
$(document).ready(runAllfunction);
function button_handler(){
$(document).on("click", "#button_option", function () {
$(this).css('background', 'yellow');
$("[id=button_option]").prop("disabled", true);
var option_clicked = $(this).val();
console.log(option_clicked);
$.ajax({
url: 'ajax/iterate_options/',
data: {
'option': option_clicked
},
dataType: 'json',
success: function (data) {
data_received = data
console.log(data);
var r = $('<br>');
$("#lol").append(r);
data.options.forEach(function (item, index) {
addButton(item, index, data.field, data.options_int)
});
if (data.elem_selected != null){
var r = $("<p>Produit Sélectionné : "+ data.elem_selected+"&nbsp;&nbsp;&nbsp; Prix : "+ data.price+"€ &nbsp;&nbsp; &nbsp; Stock : "+ data.stock+"</p>");
$("#lol").append(r)
var r = $('<p>Acheteur :</p> <input type="text" id="acheteur"> <br>');
$("#lol").append(r)
var r = $('<select name="pets" id="pet-select">\n' +
' <option value="0">CB</option>\n' +
' <option value="1">Espèces</option>\n' +
' <option value="2">Chèque</option>\n' +
'</select>\n');
$("#lol").append(r)
}
}
});
});}
function display_jdc() {
$(document).on('input', "#acheteur", function () {
var r = $("<div id='ligne-jdc'> <p>Ligne JDC : "+data_received.name+" - "+ data_received.elem_selected + " - "+ $("#acheteur").val() +" - "+ $("#pet-select option:selected").text()+"</p><button id='confirm'>Confirmer transaction</button></div>");
$("#ligne-jdc").replaceWith(r)
});
$(document).on('input', "#pet-select", function () {
var r = $("<div id='ligne-jdc'> <p>Ligne JDC : "+data_received.name+" - "+ data_received.elem_selected + " - "+ $("#acheteur").val() +" - "+ $("#pet-select option:selected").text()+"</p><button id='confirm'>Confirmer transaction</button></div>");
$("#ligne-jdc").replaceWith(r)
});
$(document).on('click', "#confirm", function () {
$.ajax({
url: 'ajax/submit_entry/',
data: {
'buyer': $("#acheteur").val(),
'payment': $("#pet-select option:selected").text()
},
dataType: 'json',
success: function (data) {
// Simulate an HTTP redirect:
window.location.replace("/journaldecaisse");
}
});
});
}
</script>
{% endblock %}

3
journaldecaisse/tests.py Normal file
View file

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

15
journaldecaisse/urls.py Normal file
View file

@ -0,0 +1,15 @@
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'),
url(r'^ajax/submit_entry/$', views.submit_entry, name='submit_entry'),
]

75
journaldecaisse/views.py Normal file
View file

@ -0,0 +1,75 @@
from django.http import HttpResponse
from .models import JournalEntry, Produit, ProduitStock
from django.shortcuts import render
from django.http import JsonResponse
import datetime
global_filter = None
def index(request):
entry_list = JournalEntry.objects.order_by('entry_date')
context = {'entry_list': entry_list}
return render(request, 'journaldecaisse/index.html', context)
def vente(request):
print(request.user.first_name)
global global_filter
product_list = Produit.objects.all()
global_filter = product_list
product_list = product_list.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):
global global_filter
elem_selected = None
elem_price = None
elem_stock = None
options_selected = request.GET.get('option', None)
options_selected = options_selected.split(":")
field = str(Produit._meta.get_fields()[int(options_selected[2])+3]).split(".")[-1]
elems = global_filter.filter(**{options_selected[0]: options_selected[1]})
global_filter = elems
elems = elems.values_list()
options = []
for elem in elems:
options.append(elem[int(options_selected[2])+2])
options = list(set(options))
if global_filter.count() == 1:
elem_selected = str(global_filter.first())
elem_price = global_filter.first().price
elem_stock = ProduitStock.objects.get(ProduitTaille=global_filter.first()).Amount
data = {
'options': options,
'options_int': int(options_selected[2])+2,
'field': field,
'elem_selected': elem_selected,
'price': elem_price,
'stock': elem_stock,
'name': request.user.first_name
}
return JsonResponse(data)
def submit_entry(request):
product = global_filter.first()
buyer = request.GET.get('buyer', None)
payment = request.GET.get('payment', None)
author = request.user.first_name
JournalEntry.objects.create(entry_date=datetime.datetime.now(), entry_text=str(product) + " " + buyer, cofeux_id=author, entry_amount=product.price, payment_type=payment)
return JsonResponse({"success":"True"})