feat: добавлена страница с графиком движения товаров

main
Artem-Darius Weber 1 day ago
parent c6dfbc90dd
commit d48ae7e3a1

@ -99,3 +99,37 @@ Watching for file changes with StatReloader
"GET /admin/warehouse/stockoperation/1/change/ HTTP/1.1" 200 19394
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 14799
Watching for file changes with StatReloader
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 14886
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
Watching for file changes with StatReloader
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 14914
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
/Users/darius/Documents/franchise_store/warehouse/admin.py changed, reloading.
Watching for file changes with StatReloader
/Users/darius/Documents/franchise_store/warehouse/admin.py changed, reloading.
Watching for file changes with StatReloader
/Users/darius/Documents/franchise_store/warehouse/admin.py changed, reloading.
Watching for file changes with StatReloader
Watching for file changes with StatReloader
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 14886
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/warehouse/stockoperation/statistics/ HTTP/1.1" 200 24699
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 14886
"GET /admin/warehouse/stockoperation/add/ HTTP/1.1" 200 19071
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/product_directory/product/1/change/?_to_field=id&_popup=1 HTTP/1.1" 200 10158
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/product_directory/product/1/change/?_to_field=id HTTP/1.1" 200 17244
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/warehouse/stockoperation/add/ HTTP/1.1" 200 19071
"GET /admin/product_directory/product/add/?_to_field=id&_popup=1 HTTP/1.1" 200 10066
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"POST /admin/warehouse/stockoperation/add/ HTTP/1.1" 302 0
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 15687
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/warehouse/stockoperation/statistics/ HTTP/1.1" 200 28103
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 15416
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/warehouse/stockoperation/statistics/ HTTP/1.1" 200 28103
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 15416

@ -1,5 +1,13 @@
from django.contrib import admin
from .models import Warehouse, StorageLocation, StockOperation
from django.urls import path
from django.shortcuts import render
import matplotlib.pyplot as plt
from io import BytesIO
import base64
import matplotlib
matplotlib.use('Agg')
@admin.register(Warehouse)
class WarehouseAdmin(admin.ModelAdmin):
@ -19,3 +27,43 @@ class StockOperationAdmin(admin.ModelAdmin):
list_display = ('product', 'warehouse', 'operation_type', 'quantity', 'operation_date')
search_fields = ('product__name', 'warehouse__name', 'operation_type')
list_filter = ('operation_type', 'operation_date')
def changelist_view(self, request, extra_context=None):
extra_context = extra_context or {}
extra_context['custom_button'] = {
'url': 'statistics/',
'label': 'Просмотреть статистику'
}
return super().changelist_view(request, extra_context)
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('statistics/', self.admin_site.admin_view(self.statistics_view), name='stock_operation_statistics'),
]
return custom_urls + urls
def statistics_view(self, request):
operations = StockOperation.objects.all()
incoming_count = operations.filter(operation_type='Incoming').count()
outgoing_count = operations.filter(operation_type='Outgoing').count()
transfer_count = operations.filter(operation_type='Transfer').count()
writeoff_count = operations.filter(operation_type='WriteOff').count()
labels = ['Incoming', 'Outgoing', 'Transfer', 'WriteOff']
data = [incoming_count, outgoing_count, transfer_count, writeoff_count]
plt.figure(figsize=(6, 6))
plt.pie(data, labels=labels, autopct='%1.1f%%', startangle=90)
plt.axis('equal')
buffer = BytesIO()
plt.savefig(buffer, format='png')
buffer.seek(0)
image_png = buffer.getvalue()
buffer.close()
chart = base64.b64encode(image_png).decode('utf-8')
context = {'chart': chart}
return render(request, 'admin/warehouse/stock_statistics.html', context)

@ -0,0 +1,7 @@
{% extends "admin/base_site.html" %}
{% block content %}
<h1>Статистика операций на складе</h1>
<img src="data:image/png;base64,{{ chart }}" alt="График статистики" />
<a href="{% url 'admin:warehouse_stockoperation_changelist' %}" class="button">Назад к списку операций</a>
{% endblock %}

@ -0,0 +1,6 @@
{% extends "admin/change_list.html" %}
{% block object-tools %}
{{ block.super }}
<a href="{{ custom_button.url }}" class="button">{{ custom_button.label }}</a>
{% endblock %}
Loading…
Cancel
Save