From ab9bbac34fbe37ee4e75e1b97953ef4ff0d33748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Fri, 26 Aug 2016 23:44:57 +0200 Subject: [PATCH] =?UTF-8?q?Nouvel=20article=20-=20S=C3=A9lection(et/ou=20c?= =?UTF-8?q?r=C3=A9ation)=20de=20fournisseurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/forms.py | 15 ++++++++- kfet/migrations/0037_auto_20160826_2333.py | 39 ++++++++++++++++++++++ kfet/models.py | 21 +++++++++--- kfet/static/kfet/css/history.css | 13 ++++++-- kfet/static/kfet/css/transfers_form.css | 2 +- kfet/templates/kfet/transfers.html | 10 +++--- kfet/views.py | 15 ++++++++- 7 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 kfet/migrations/0037_auto_20160826_2333.py diff --git a/kfet/forms.py b/kfet/forms.py index 6709beb1..ea12d424 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -8,7 +8,7 @@ from django.forms.models import BaseInlineFormSet from django.utils import timezone from kfet.models import (Account, Checkout, Article, OperationGroup, Operation, CheckoutStatement, ArticleCategory, Settings, AccountNegative, Transfer, - TransferGroup) + TransferGroup, Supplier) from gestioncof.models import CofProfile # ----- @@ -192,6 +192,18 @@ class ArticleForm(forms.ModelForm): queryset = ArticleCategory.objects.all(), required = False) + suppliers = forms.ModelMultipleChoiceField( + queryset = Supplier.objects.all(), + required = False) + supplier_new = forms.CharField( + max_length = 45, + required = False) + + def __init__(self, *args, **kwargs): + super(ArticleForm, self).__init__(*args, **kwargs) + if self.instance.pk: + self.initial['suppliers'] = self.instance.suppliers.values_list('pk', flat=True) + def clean(self): category = self.cleaned_data.get('category') category_new = self.cleaned_data.get('category_new') @@ -201,6 +213,7 @@ class ArticleForm(forms.ModelForm): elif not category: category, _ = ArticleCategory.objects.get_or_create(name=category_new) self.cleaned_data['category'] = category + super(ArticleForm, self).clean() class Meta: diff --git a/kfet/migrations/0037_auto_20160826_2333.py b/kfet/migrations/0037_auto_20160826_2333.py new file mode 100644 index 00000000..9f937b60 --- /dev/null +++ b/kfet/migrations/0037_auto_20160826_2333.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0036_auto_20160823_1910'), + ] + + operations = [ + migrations.AlterField( + model_name='supplierarticle', + name='TVA', + field=models.DecimalField(null=True, max_digits=4, decimal_places=2, default=None, blank=True), + ), + migrations.AlterField( + model_name='supplierarticle', + name='box_capacity', + field=models.PositiveSmallIntegerField(null=True, default=None, blank=True), + ), + migrations.AlterField( + model_name='supplierarticle', + name='box_type', + field=models.CharField(null=True, max_length=7, choices=[('caisse', 'Caisse'), ('carton', 'Carton'), ('palette', 'Palette'), ('fût', 'Fût')], default=None, blank=True), + ), + migrations.AlterField( + model_name='supplierarticle', + name='price_HT', + field=models.DecimalField(null=True, max_digits=7, decimal_places=4, default=None, blank=True), + ), + migrations.AlterField( + model_name='supplierarticle', + name='rights', + field=models.DecimalField(null=True, max_digits=7, decimal_places=4, default=None, blank=True), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index 51560d4b..47c734a3 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -376,6 +376,9 @@ class Supplier(models.Model): phone = models.CharField(max_length = 10) comment = models.TextField() + def __str__(self): + return self.name + class SupplierArticle(models.Model): supplier = models.ForeignKey( Supplier, on_delete = models.PROTECT) @@ -389,11 +392,19 @@ class SupplierArticle(models.Model): ) box_type = models.CharField( choices = BOX_TYPE_CHOICES, - max_length = choices_length(BOX_TYPE_CHOICES)) - box_capacity = models.PositiveSmallIntegerField() - price_HT = models.DecimalField(max_digits = 7, decimal_places = 4) - TVA = models.DecimalField(max_digits = 4, decimal_places = 2) - rights = models.DecimalField(max_digits = 7, decimal_places = 4) + max_length = choices_length(BOX_TYPE_CHOICES), + blank = True, null = True, default = None) + box_capacity = models.PositiveSmallIntegerField( + blank = True, null = True, default = None) + price_HT = models.DecimalField( + max_digits = 7, decimal_places = 4, + blank = True, null = True, default = None) + TVA = models.DecimalField( + max_digits = 4, decimal_places = 2, + blank = True, null = True, default = None) + rights = models.DecimalField( + max_digits = 7, decimal_places = 4, + blank = True, null = True, default = None) class Order(models.Model): supplier = models.ForeignKey( diff --git a/kfet/static/kfet/css/history.css b/kfet/static/kfet/css/history.css index e7d6858c..976f5782 100644 --- a/kfet/static/kfet/css/history.css +++ b/kfet/static/kfet/css/history.css @@ -79,17 +79,16 @@ padding-left:20px; } -#history div.general.ui-selected, #history div.general.ui-selecting, #history div.ope.ui-selected, #history div.ope.ui-selecting { background-color:rgba(200,16,46,0.6); color:#FFF; } -#history .ope.canceled { +#history .ope.canceled, #history .transfer.canceled { color:#444; } -#history .ope.canceled::before { +#history .ope.canceled::before, #history.transfer.canceled::before { position: absolute; content: ' '; width:100%; @@ -97,3 +96,11 @@ top: 12px; border-top: 1px solid rgba(200,16,46,0.5); } + +#history .transfer .amount { + width:80px; +} + +#history .transfer .from_acc { + padding-left:10px; +} diff --git a/kfet/static/kfet/css/transfers_form.css b/kfet/static/kfet/css/transfers_form.css index b2920b5d..231a0c89 100644 --- a/kfet/static/kfet/css/transfers_form.css +++ b/kfet/static/kfet/css/transfers_form.css @@ -30,7 +30,7 @@ .transfer_form td { height:50px; - vertical-align:middle; + vertical-align:middle !important; padding:0 !important; } diff --git a/kfet/templates/kfet/transfers.html b/kfet/templates/kfet/transfers.html index 5a32527b..1875a21e 100644 --- a/kfet/templates/kfet/transfers.html +++ b/kfet/templates/kfet/transfers.html @@ -30,11 +30,11 @@ {{ transfergroup.comment }} {% for transfer in transfergroup.transfers.all %} -
- {{ transfer.amount }} € - {{ transfer.from_acc.trigramme }} - --> - {{ transfer.to_acc.trigramme }} +
+ {{ transfer.amount }} € + {{ transfer.from_acc.trigramme }} + + {{ transfer.to_acc.trigramme }}
{% endfor %} {% endfor %} diff --git a/kfet/views.py b/kfet/views.py index 7a7b00f3..94e89882 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -18,7 +18,7 @@ from django.utils import timezone from django.utils.crypto import get_random_string from gestioncof.models import CofProfile, Clipper from kfet.models import (Account, Checkout, Article, Settings, AccountNegative, - CheckoutStatement, GenericTeamToken) + CheckoutStatement, GenericTeamToken, Supplier, SupplierArticle) from kfet.forms import * from collections import defaultdict from kfet import consumers @@ -548,6 +548,19 @@ class ArticleCreate(SuccessMessageMixin, CreateView): form.add_error(None, 'Permission refusée') return self.form_invalid(form) + article = form.save() + for supplier in form.cleaned_data['suppliers']: + SupplierArticle.objects.create( + article = article, supplier = supplier) + + supplier_new = form.cleaned_data['supplier_new'].strip() + if supplier_new: + supplier, created = Supplier.objects.get_or_create( + name=supplier_new) + if created: + SupplierArticle.objects.create( + article = article, supplier = supplier) + # Creating return super(ArticleCreate, self).form_valid(form)