Compare commits

...

2 commits

Author SHA1 Message Date
Hugo Manet
d9411c5b5a Add box_capacity to template + minor changes 2017-04-18 11:43:27 +02:00
Hugo Manet
96dbfc22da Add two weeks, count in negative 2017-04-16 20:47:45 +02:00
3 changed files with 76 additions and 46 deletions

View file

@ -517,11 +517,13 @@ class OrderArticleForm(forms.Form):
self.category = kwargs['initial']['category']
self.category_name = kwargs['initial']['category__name']
self.box_capacity = kwargs['initial']['box_capacity']
self.v_s1 = kwargs['initial']['v_s1']
self.v_s2 = kwargs['initial']['v_s2']
self.v_s3 = kwargs['initial']['v_s3']
self.v_s4 = kwargs['initial']['v_s4']
self.v_s5 = kwargs['initial']['v_s5']
self.v_s_7 = kwargs['initial']['v_s_7']
self.v_s_6 = kwargs['initial']['v_s_6']
self.v_s_5 = kwargs['initial']['v_s_5']
self.v_s_4 = kwargs['initial']['v_s_4']
self.v_s_3 = kwargs['initial']['v_s_3']
self.v_s_2 = kwargs['initial']['v_s_2']
self.v_s_1 = kwargs['initial']['v_s_1']
self.v_moy = kwargs['initial']['v_moy']
self.v_et = kwargs['initial']['v_et']
self.v_prev = kwargs['initial']['v_prev']

View file

@ -14,8 +14,8 @@
<thead>
<tr>
<td rowspan="2">Article</td>
<td colspan="5">Ventes
<span class='glyphicon glyphicon-question-sign' title="Ventes des 5 dernières semaines" data-placement="bottom"></span>
<td colspan="7">Ventes
<span class='glyphicon glyphicon-question-sign' title="Ventes des 7 dernières semaines" data-placement="bottom"></span>
</td>
<td rowspan="2">V. moy.
<span class='glyphicon glyphicon-question-sign' title="Moyenne des ventes" data-placement="bottom"></span>
@ -27,17 +27,22 @@
<span class='glyphicon glyphicon-question-sign' title="Prévision de ventes" data-placement="bottom"></span>
</td>
<td rowspan="2">Stock</td>
<td rowspan="2">Box
<span class='glyphicon glyphicon-question-sign' title="Capacité d'une boite" data-placement="bottom"></span>
</td>
<td rowspan="2">Rec.
<span class='glyphicon glyphicon-question-sign' title="Quantité conseillée" data-placement="bottom"></span>
</td>
<td rowspan="2">Commande</td>
</tr>
<tr>
<td>S1</td>
<td>S2</td>
<td>S3</td>
<td>S4</td>
<td>S5</td>
<td>S -7</td>
<td>S -6</td>
<td>S -5</td>
<td>S -4</td>
<td>S -3</td>
<td>S -2</td>
<td>S -1</td>
</tr>
</thead>
<tbody>
@ -45,21 +50,24 @@
{% ifchanged form.category %}
<tr class='section'>
<td> {{ form.category_name }}</td>
<td colspan="11"></td>
<td colspan="14"></td>
</tr>
{% endifchanged %}
<tr>
{{ form.article }}
<td>{{ form.name }}</td>
<td>{{ form.v_s1 }}</td>
<td>{{ form.v_s2 }}</td>
<td>{{ form.v_s3 }}</td>
<td>{{ form.v_s4 }}</td>
<td>{{ form.v_s5 }}</td>
<td>{{ form.v_s_7 }}</td>
<td>{{ form.v_s_6 }}</td>
<td>{{ form.v_s_5 }}</td>
<td>{{ form.v_s_4 }}</td>
<td>{{ form.v_s_3 }}</td>
<td>{{ form.v_s_2 }}</td>
<td>{{ form.v_s_1 }}</td>
<td>{{ form.v_moy }}</td>
<td>{{ form.v_et }}</td>
<td>{{ form.v_prev }}</td>
<td>{{ form.stock }}</td>
<td>{{ form.box_capacity }}</td>
<td>{{ form.c_rec }}</td>
<td>{{ form.quantity_ordered | add_class:"form-control" }}</td>
</tr>

View file

@ -1793,47 +1793,65 @@ def order_create(request, pk):
.select_related('group')
.filter(article__in=articles, canceled_at=None)
.values('article'))
sales_s1 = (sales_q
sales_s_7 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=7),
group__at__lt = today-timedelta(weeks=7-1))
.annotate(nb=Sum('article_nb'))
)
sales_s_7 = { d['article']:d['nb'] for d in sales_s_7 }
sales_s_6 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=6),
group__at__lt = today-timedelta(weeks=6-1))
.annotate(nb=Sum('article_nb'))
)
sales_s_6 = { d['article']:d['nb'] for d in sales_s_6 }
sales_s_5 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=5),
group__at__lt = today-timedelta(weeks=4))
group__at__lt = today-timedelta(weeks=5-1))
.annotate(nb=Sum('article_nb'))
)
sales_s1 = { d['article']:d['nb'] for d in sales_s1 }
sales_s2 = (sales_q
sales_s_5 = { d['article']:d['nb'] for d in sales_s_5 }
sales_s_4 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=4),
group__at__lt = today-timedelta(weeks=3))
group__at__lt = today-timedelta(weeks=4-1))
.annotate(nb=Sum('article_nb'))
)
sales_s2 = { d['article']:d['nb'] for d in sales_s2 }
sales_s3 = (sales_q
sales_s_4 = { d['article']:d['nb'] for d in sales_s_4 }
sales_s_3 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=3),
group__at__lt = today-timedelta(weeks=2))
group__at__lt = today-timedelta(weeks=3-1))
.annotate(nb=Sum('article_nb'))
)
sales_s3 = { d['article']:d['nb'] for d in sales_s3 }
sales_s4 = (sales_q
sales_s_3 = { d['article']:d['nb'] for d in sales_s_3 }
sales_s_2 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=2),
group__at__lt = today-timedelta(weeks=1))
group__at__lt = today-timedelta(weeks=2-1))
.annotate(nb=Sum('article_nb'))
)
sales_s4 = { d['article']:d['nb'] for d in sales_s4 }
sales_s5 = (sales_q
.filter(group__at__gte = today-timedelta(weeks=1))
sales_s_2 = { d['article']:d['nb'] for d in sales_s_2 }
sales_s_1 = (sales_q
.filter(
group__at__gte = today-timedelta(weeks=1),
group__at__lt = today
.annotate(nb=Sum('article_nb'))
)
sales_s5 = { d['article']:d['nb'] for d in sales_s5 }
sales_s_1 = { d['article']:d['nb'] for d in sales_s_1 }
for article in articles:
v_s1 = sales_s1.get(article.pk, 0)
v_s2 = sales_s2.get(article.pk, 0)
v_s3 = sales_s3.get(article.pk, 0)
v_s4 = sales_s4.get(article.pk, 0)
v_s5 = sales_s5.get(article.pk, 0)
v_all = [v_s1, v_s2, v_s3, v_s4, v_s5]
v_s_7 = sales_s_7.get(article.pk, 0)
v_s_6 = sales_s_6.get(article.pk, 0)
v_s_5 = sales_s_5.get(article.pk, 0)
v_s_4 = sales_s_4.get(article.pk, 0)
v_s_3 = sales_s_3.get(article.pk, 0)
v_s_2 = sales_s_2.get(article.pk, 0)
v_s_1 = sales_s_1.get(article.pk, 0)
v_all = [v_s_7, v_s_6, v_s_5, v_s_4, v_s_3, v_s_2, v_s_1]
v_3max = heapq.nlargest(3, v_all)
v_moy = statistics.mean(v_3max)
v_et = statistics.pstdev(v_3max, v_moy)
@ -1856,15 +1874,17 @@ def order_create(request, pk):
'category__name': article.category.name,
'stock': article.stock,
'box_capacity': article.box_capacity,
'v_s1': v_s1,
'v_s2': v_s2,
'v_s3': v_s3,
'v_s4': v_s4,
'v_s5': v_s5,
'v_s_7': v_s_7,
'v_s_6': v_s_6,
'v_s_5': v_s_5,
'v_s_4': v_s_4,
'v_s_3': v_s_3,
'v_s_2': v_s_2,
'v_s_1': v_s_1,
'v_moy': round(v_moy),
'v_et': round(v_et),
'v_prev': round(v_prev),
'c_rec': article.box_capacity and c_rec or round(c_rec_tot),
'c_rec': c_rec if article.box_capacity else round(c_rec_tot),
})
cls_formset = formset_factory(