Nouvel article - Sélection(et/ou création) de fournisseurs

This commit is contained in:
Aurélien Delobelle 2016-08-26 23:44:57 +02:00
parent be8243c4ce
commit ab9bbac34f
7 changed files with 99 additions and 16 deletions

View file

@ -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:

View file

@ -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),
),
]

View file

@ -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(

View file

@ -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;
}

View file

@ -30,7 +30,7 @@
.transfer_form td {
height:50px;
vertical-align:middle;
vertical-align:middle !important;
padding:0 !important;
}

View file

@ -30,11 +30,11 @@
<span>{{ transfergroup.comment }}</span>
</div>
{% for transfer in transfergroup.transfers.all %}
<div>
<span>{{ transfer.amount }} €</span>
<span>{{ transfer.from_acc.trigramme }}</span>
<span>--></span>
<span>{{ transfer.to_acc.trigramme }}</span>
<div class="ope transfer">
<span class="amount">{{ transfer.amount }} €</span>
<span class="from_acc">{{ transfer.from_acc.trigramme }}</span>
<span class="glyphicon glyphicon-arrow-right"></span>
<span class="to_acc">{{ transfer.to_acc.trigramme }}</span>
</div>
{% endfor %}
{% endfor %}

View file

@ -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)