forked from DGNum/gestioCOF
(little) cleaning of order_create view
This commit is contained in:
parent
b0e7ebfbc5
commit
b1e46792c8
1 changed files with 6 additions and 16 deletions
|
@ -1823,23 +1823,17 @@ def order_create(request, pk):
|
||||||
)
|
)
|
||||||
scale = WeekScale(last=True, n_steps=5, std_chunk=False)
|
scale = WeekScale(last=True, n_steps=5, std_chunk=False)
|
||||||
chunks = scale.chunkify_qs(sales_q, field='group__at')
|
chunks = scale.chunkify_qs(sales_q, field='group__at')
|
||||||
sales = []
|
|
||||||
|
|
||||||
for chunk in chunks:
|
sales = [
|
||||||
sales.append(
|
|
||||||
{d['article']: d['nb'] for d in chunk}
|
{d['article']: d['nb'] for d in chunk}
|
||||||
)
|
for chunk in chunks
|
||||||
|
]
|
||||||
|
|
||||||
initial = []
|
initial = []
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
# Get sales for each 5 last weeks
|
# Get sales for each 5 last weeks
|
||||||
v_s1 = sales[0].get(article.pk, 0)
|
v_all = [chunk.get(article.pk, 0) for chunk in sales]
|
||||||
v_s2 = sales[1].get(article.pk, 0)
|
|
||||||
v_s3 = sales[2].get(article.pk, 0)
|
|
||||||
v_s4 = sales[3].get(article.pk, 0)
|
|
||||||
v_s5 = sales[4].get(article.pk, 0)
|
|
||||||
v_all = [v_s1, v_s2, v_s3, v_s4, v_s5]
|
|
||||||
# Take the 3 greatest (eg to avoid 2 weeks of vacations)
|
# Take the 3 greatest (eg to avoid 2 weeks of vacations)
|
||||||
v_3max = heapq.nlargest(3, v_all)
|
v_3max = heapq.nlargest(3, v_all)
|
||||||
# Get average and standard deviation
|
# Get average and standard deviation
|
||||||
|
@ -1869,11 +1863,7 @@ def order_create(request, pk):
|
||||||
'category__name': article.category.name,
|
'category__name': article.category.name,
|
||||||
'stock': article.stock,
|
'stock': article.stock,
|
||||||
'box_capacity': article.box_capacity,
|
'box_capacity': article.box_capacity,
|
||||||
'v_s1': v_s1,
|
'v_all': v_all,
|
||||||
'v_s2': v_s2,
|
|
||||||
'v_s3': v_s3,
|
|
||||||
'v_s4': v_s4,
|
|
||||||
'v_s5': v_s5,
|
|
||||||
'v_moy': round(v_moy),
|
'v_moy': round(v_moy),
|
||||||
'v_et': round(v_et),
|
'v_et': round(v_et),
|
||||||
'v_prev': round(v_prev),
|
'v_prev': round(v_prev),
|
||||||
|
|
Loading…
Reference in a new issue