forked from DGNum/gestioCOF
Merge branch '_aandres/inventory_sum_amounts' into 'master'
Affiche les montants des valeurs des stocks sur l'affichage d'un inventaire See merge request klub-dev-ens/gestioCOF!515
This commit is contained in:
commit
761ab6df90
3 changed files with 55 additions and 8 deletions
|
@ -61,7 +61,7 @@ ul {
|
||||||
}
|
}
|
||||||
|
|
||||||
.table td.no-padding {
|
.table td.no-padding {
|
||||||
padding:0;
|
padding:0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table thead {
|
.table thead {
|
||||||
|
|
|
@ -37,6 +37,12 @@
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
|
<div class="messages">
|
||||||
|
<div class="alert alert-info">
|
||||||
|
Les valeurs de stock sont calculées sur la base du prix actuel des articles.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table
|
<table
|
||||||
class="table table-condensed table-hover table-striped sortable"
|
class="table table-condensed table-hover table-striped sortable"
|
||||||
|
@ -50,28 +56,36 @@
|
||||||
<td>Erreur</td>
|
<td>Erreur</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% regroup inventoryarts by article.category as category_list %}
|
{% regroup inventoryarts by article.category.name as category_list %}
|
||||||
{% for category in category_list %}
|
{% for category in category_list %}
|
||||||
<tbody class="tablesorter-no-sort">
|
<tbody class="tablesorter-no-sort">
|
||||||
<tr class="section">
|
<tr class="section">
|
||||||
<td colspan="4">{{ category.grouper.name }}</td>
|
<td colspan="4">{{ category.grouper }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for inventoryart in category.list %}
|
{% for inventoryart in category.list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url "kfet.article.read" inventoryart.article.id %}">
|
<a href="{% url "kfet.article.read" inventoryart.article_id %}">
|
||||||
{{ inventoryart.article.name }}
|
{{ inventoryart.article.name }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ inventoryart.stock_old }}</td>
|
<td>{{ inventoryart.stock_old }}</td>
|
||||||
<td>{{ inventoryart.stock_new }}</td>
|
<td>{{ inventoryart.stock_new }}</td>
|
||||||
<td>{{ inventoryart.stock_error }}</td>
|
<td>{{ inventoryart.stock_error }} / {{ inventoryart.amount_error|floatformat:"-2" }} €</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<tbody>
|
||||||
|
<tr class="section">
|
||||||
|
<td>Valeurs totales</td>
|
||||||
|
<td>{{ total_amount_old|floatformat:"-2" }} €</td>
|
||||||
|
<td>{{ total_amount_new|floatformat:"-2" }} €</td>
|
||||||
|
<td>{{ total_amount_error|floatformat:"-2" }} €</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,18 @@ from django.contrib.auth.models import Permission, User
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Count, F, Max, OuterRef, Prefetch, Q, Subquery, Sum
|
from django.db.models import (
|
||||||
|
Count,
|
||||||
|
DecimalField,
|
||||||
|
ExpressionWrapper,
|
||||||
|
F,
|
||||||
|
Max,
|
||||||
|
OuterRef,
|
||||||
|
Prefetch,
|
||||||
|
Q,
|
||||||
|
Subquery,
|
||||||
|
Sum,
|
||||||
|
)
|
||||||
from django.forms import ValidationError, formset_factory
|
from django.forms import ValidationError, formset_factory
|
||||||
from django.http import (
|
from django.http import (
|
||||||
Http404,
|
Http404,
|
||||||
|
@ -2013,12 +2024,34 @@ class InventoryRead(DetailView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
inventoryarticles = (
|
output_field = DecimalField(max_digits=10, decimal_places=2, default=0)
|
||||||
|
inventory_articles = (
|
||||||
InventoryArticle.objects.select_related("article", "article__category")
|
InventoryArticle.objects.select_related("article", "article__category")
|
||||||
.filter(inventory=self.object)
|
.filter(inventory=self.object)
|
||||||
|
.annotate(
|
||||||
|
amount_error=ExpressionWrapper(
|
||||||
|
F("stock_error") * F("article__price"), output_field=output_field
|
||||||
|
)
|
||||||
|
)
|
||||||
.order_by("article__category__name", "article__name")
|
.order_by("article__category__name", "article__name")
|
||||||
)
|
)
|
||||||
context["inventoryarts"] = inventoryarticles
|
context["inventoryarts"] = inventory_articles
|
||||||
|
stats = inventory_articles.aggregate(
|
||||||
|
new=ExpressionWrapper(
|
||||||
|
Sum(F("stock_new") * F("article__price")), output_field=output_field
|
||||||
|
),
|
||||||
|
error=Sum("amount_error"),
|
||||||
|
old=ExpressionWrapper(
|
||||||
|
Sum(F("stock_old") * F("article__price")), output_field=output_field
|
||||||
|
),
|
||||||
|
)
|
||||||
|
context.update(
|
||||||
|
{
|
||||||
|
"total_amount_old": stats["old"],
|
||||||
|
"total_amount_new": stats["new"],
|
||||||
|
"total_amount_error": stats["error"],
|
||||||
|
}
|
||||||
|
)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue