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 avant</td>
<td>Stock après</td> <td>Stock après</td>
<td>Erreur</td> <td>Erreur</td>
<td>Valeur</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 }}</td>
<td>{{ inventoryart.amount_new }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
{% endfor %} {% endfor %}
<tbody>
<tr class="section">
<th colspan="4">Total</th>
<td>{{ total_amount }}</td>
</tr>
</tbody>
</table> </table>
</div> </div>

View file

@ -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,23 @@ 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 = ( 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_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") .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 return context