feat: poc inventory amount value

and lint
This commit is contained in:
Alice 2023-01-21 02:23:25 +01:00
parent dfa5b4bf69
commit 4b92716092
2 changed files with 36 additions and 6 deletions

View file

@ -48,30 +48,38 @@
<td>Stock avant</td>
<td>Stock après</td>
<td>Erreur</td>
<td>Valeur</td>
</tr>
</thead>
{% regroup inventoryarts by article.category as category_list %}
{% regroup inventoryarts by article.category.name as category_list %}
{% for category in category_list %}
<tbody class="tablesorter-no-sort">
<tr class="section">
<td colspan="4">{{ category.grouper.name }}</td>
<td colspan="4">{{ category.grouper }}</td>
</tr>
</tbody>
<tbody>
{% for inventoryart in category.list %}
<tr>
<td>
<a href="{% url "kfet.article.read" inventoryart.article.id %}">
<a href="{% url "kfet.article.read" inventoryart.article_id %}">
{{ inventoryart.article.name }}
</a>
</td>
<td>{{ inventoryart.stock_old }}</td>
<td>{{ inventoryart.stock_new }}</td>
<td>{{ inventoryart.stock_error }}</td>
<td>{{ inventoryart.amount_new }}</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
<tbody>
<tr class="section">
<th colspan="4">Total</th>
<td>{{ total_amount }}</td>
</tr>
</tbody>
</table>
</div>

View file

@ -14,7 +14,18 @@ from django.contrib.auth.models import Permission, User
from django.contrib.messages.views import SuccessMessageMixin
from django.core.exceptions import SuspiciousOperation
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.http import (
Http404,
@ -2013,12 +2024,23 @@ class InventoryRead(DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
inventoryarticles = (
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
),
)
)
.order_by("article__category__name", "article__name")
)
context["inventoryarts"] = inventoryarticles
context["inventoryarts"] = inventory_articles
context["total_amount"] = inventory_articles.aggregate(total=Sum("amount_new"))[
"total"
]
return context