forked from DGNum/gestioCOF
feat(kfet): more values and formatting
This commit is contained in:
parent
4b92716092
commit
429e611daa
3 changed files with 25 additions and 14 deletions
|
@ -61,7 +61,7 @@ ul {
|
|||
}
|
||||
|
||||
.table td.no-padding {
|
||||
padding:0;
|
||||
padding:0 !important;
|
||||
}
|
||||
|
||||
.table thead {
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<td>Stock avant</td>
|
||||
<td>Stock après</td>
|
||||
<td>Erreur</td>
|
||||
<td>Valeur</td>
|
||||
</tr>
|
||||
</thead>
|
||||
{% regroup inventoryarts by article.category.name as category_list %}
|
||||
|
@ -68,16 +67,17 @@
|
|||
</td>
|
||||
<td>{{ inventoryart.stock_old }}</td>
|
||||
<td>{{ inventoryart.stock_new }}</td>
|
||||
<td>{{ inventoryart.stock_error }}</td>
|
||||
<td>{{ inventoryart.amount_new }}</td>
|
||||
<td>{{ inventoryart.stock_error }} / {{ inventoryart.amount_error|floatformat:"-2" }} €</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% endfor %}
|
||||
<tbody>
|
||||
<tr class="section">
|
||||
<th colspan="4">Total</th>
|
||||
<td>{{ total_amount }}</td>
|
||||
<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>
|
||||
|
|
|
@ -2024,23 +2024,34 @@ class InventoryRead(DetailView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
output_field = DecimalField(max_digits=10, decimal_places=2, default=0)
|
||||
inventory_articles = (
|
||||
InventoryArticle.objects.select_related("article", "article__category")
|
||||
.filter(inventory=self.object)
|
||||
.annotate(
|
||||
amount_new=ExpressionWrapper(
|
||||
F("stock_new") * F("article__price"),
|
||||
output_field=DecimalField(
|
||||
max_digits=6, decimal_places=2, default=0
|
||||
),
|
||||
amount_error=ExpressionWrapper(
|
||||
F("stock_error") * F("article__price"), output_field=output_field
|
||||
)
|
||||
)
|
||||
.order_by("article__category__name", "article__name")
|
||||
)
|
||||
context["inventoryarts"] = inventory_articles
|
||||
context["total_amount"] = inventory_articles.aggregate(total=Sum("amount_new"))[
|
||||
"total"
|
||||
]
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue