mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 03:13:12 +00:00
Improvements
This commit is contained in:
parent
73e7697a3c
commit
ed60e58002
5 changed files with 61 additions and 6 deletions
|
@ -49,11 +49,10 @@ class CreateKegForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Keg
|
model = Keg
|
||||||
fields = ["name", "stockHold", "amount", "capacity"]
|
fields = ["name", "stockHold", "amount", "capacity", "deg"]
|
||||||
widgets = {'amount': forms.TextInput}
|
widgets = {'amount': forms.TextInput}
|
||||||
|
|
||||||
category = forms.ModelChoiceField(queryset=Category.objects.all(), label="Catégorie", help_text="Catégorie dans laquelle placer les produits pinte, demi (et galopin si besoin).")
|
category = forms.ModelChoiceField(queryset=Category.objects.all(), label="Catégorie", help_text="Catégorie dans laquelle placer les produits pinte, demi (et galopin si besoin).")
|
||||||
deg = forms.DecimalField(max_digits=5, decimal_places=2, label="Degré", validators=[MinValueValidator(0)])
|
|
||||||
create_galopin = forms.BooleanField(required=False, label="Créer le produit galopin ?")
|
create_galopin = forms.BooleanField(required=False, label="Créer le produit galopin ?")
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
@ -68,7 +67,7 @@ class EditKegForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Keg
|
model = Keg
|
||||||
fields = ["name", "stockHold", "amount", "capacity", "pinte", "demi", "galopin"]
|
fields = ["name", "stockHold", "amount", "capacity", "pinte", "demi", "galopin", "deg"]
|
||||||
widgets = {'amount': forms.TextInput}
|
widgets = {'amount': forms.TextInput}
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
33
gestion/migrations/0014_auto_20190912_0951.py
Normal file
33
gestion/migrations/0014_auto_20190912_0951.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# Generated by Django 2.1 on 2019-09-12 07:51
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
def update(apps, schema_editor):
|
||||||
|
Keg = apps.get_model('gestion', 'Keg')
|
||||||
|
for keg in Keg.objects.all():
|
||||||
|
keg.deg = keg.pinte.deg
|
||||||
|
keg.save()
|
||||||
|
|
||||||
|
def reverse(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('gestion', '0013_auto_20190829_1219'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='historicalkeg',
|
||||||
|
name='deg',
|
||||||
|
field=models.DecimalField(decimal_places=2, default=0, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Degré'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='keg',
|
||||||
|
name='deg',
|
||||||
|
field=models.DecimalField(decimal_places=2, default=0, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Degré'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(update, reverse)
|
||||||
|
]
|
|
@ -194,6 +194,7 @@ class Keg(models.Model):
|
||||||
"""
|
"""
|
||||||
If True, will be displayed on :func:`~gestion.views.manage` view
|
If True, will be displayed on :func:`~gestion.views.manage` view
|
||||||
"""
|
"""
|
||||||
|
deg = models.DecimalField(default=0,max_digits=5, decimal_places=2, verbose_name="Degré", validators=[MinValueValidator(0)])
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -592,7 +592,29 @@ def editKeg(request, pk):
|
||||||
keg = get_object_or_404(Keg, pk=pk)
|
keg = get_object_or_404(Keg, pk=pk)
|
||||||
form = EditKegForm(request.POST or None, instance=keg)
|
form = EditKegForm(request.POST or None, instance=keg)
|
||||||
if(form.is_valid()):
|
if(form.is_valid()):
|
||||||
form.save()
|
try:
|
||||||
|
price_profile = PriceProfile.objects.get(use_for_draft=True)
|
||||||
|
except:
|
||||||
|
messages.error(request, "Il n'y a pas de profil de prix pour les pressions")
|
||||||
|
return redirect(reverse('preferences:priceProfilesIndex'))
|
||||||
|
keg = form.save()
|
||||||
|
# Update produtcs
|
||||||
|
name = form.cleaned_data["name"][4:]
|
||||||
|
pinte_price = compute_price(keg.amount/(2*keg.capacity), price_profile.a, price_profile.b, price_profile.c, price_profile.alpha)
|
||||||
|
pinte_price = ceil(10*pinte_price)/10
|
||||||
|
keg.pinte.deg = keg.deg
|
||||||
|
keg.pinte.amount = pinte_price
|
||||||
|
keg.pinte.name = "Pinte " + name
|
||||||
|
keg.pinte.save()
|
||||||
|
keg.demi.deg = keg.deg
|
||||||
|
keg.demi.amount = ceil(5*pinte_price)/10
|
||||||
|
keg.demi.name = "Demi " + name
|
||||||
|
keg.demi.save()
|
||||||
|
if(keg.galopin):
|
||||||
|
keg.galopin.deg = deg
|
||||||
|
keg.galopin.amount = ceil(2.5 * pinte_price)/10
|
||||||
|
keg.galopin.name = "Galopin " + name
|
||||||
|
keg.galopin.save()
|
||||||
messages.success(request, "Le fût a bien été modifié")
|
messages.success(request, "Le fût a bien été modifié")
|
||||||
return redirect(reverse('gestion:kegsList'))
|
return redirect(reverse('gestion:kegsList'))
|
||||||
return render(request, "form.html", {"form": form, "form_title": "Modification d'un fût", "form_button": "Modifier", "form_button_icon": "pencil-alt"})
|
return render(request, "form.html", {"form": form, "form_title": "Modification d'un fût", "form_button": "Modifier", "form_button_icon": "pencil-alt"})
|
||||||
|
|
|
@ -274,8 +274,8 @@ def improvements_index(request):
|
||||||
"""
|
"""
|
||||||
Display all improvements
|
Display all improvements
|
||||||
"""
|
"""
|
||||||
todo_improvements = Improvement.objects.filter(done=False)
|
todo_improvements = Improvement.objects.filter(done=False).order_by('-date')
|
||||||
done_improvements = Improvement.objects.filter(done=True)
|
done_improvements = Improvement.objects.filter(done=True).order_by('-date')
|
||||||
return render(request, "preferences/improvements_index.html", {"todo_improvements": todo_improvements, "done_improvements": done_improvements})
|
return render(request, "preferences/improvements_index.html", {"todo_improvements": todo_improvements, "done_improvements": done_improvements})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue