add parts list

master
agp8x 2019-12-04 01:10:36 +01:00
parent f23d76b101
commit 03a17839be
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<h1>parts</h1>
<table>
<tr>
<th>Teil-Nr.</th>
<th>Teilbezeichnung</th>
{% for product in products %}
<th>{{product.name}}</th>
{% endfor %}
<th>Summe</th>
</tr>
{% for part in quantities %}
<tr>
<td>{{part.number}}</td>
<td>{{part.name}}</td>
{% for product in part.quantities %}
<td>{{product}}</td>
{% endfor %}
<td>{{part.sum}}</td>
</tr>
{% endfor %}
<tr>
<td>Summe:</td>
<td>{{len}}</td>
<td>Teile</td>
</table>

View File

@ -7,6 +7,7 @@ urlpatterns = [
path('', views.index, name="index"),
path('product/<int:product_id>/', views.product, name="detail"),
path('sketch/<int:sketch_id>/', views.sketch, name="sketch"),
path('parts', views.parts, name="parts"),
path('add/<int:product_id>/sketch/<int:sketch_id>', views.sketch_add, name="continue_sketch"),
path('add/<int:product_id>/sketch', views.sketch_add, name="new_sketch"),
path('search/part/', views.part_search, name="part_search"),

View File

@ -3,6 +3,7 @@ from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse
from django.db import transaction
from django.db.models import Sum
from .models import *
@ -28,6 +29,32 @@ def sketch(request, sketch_id):
return render(request, 'parts/sketch.html', context)
def parts(request):
products = Product.objects.order_by('name')
parts = BrandedPart.objects.order_by('number')
quantities = []
for part in parts: # FIXME!
qtys = part.usage_set.values('productusage__product__name').annotate(Sum('productusage__quantity')).order_by('productusage__product__name')
#prod_qtys = {}
prod_qtys = []
for obj in qtys:
# FIXME: make sure there are n(==products) entries
#prod_qtys['productusage__product__name'] = obj['productusage__quantity__sum']
qty = obj['productusage__quantity__sum']
if not qty:
qty = 0
prod_qtys.append(qty)
quantities.append({
"name": part.get_name(),
"number": part.number,
"quantities": prod_qtys,
"sum": sum(prod_qtys),
})
context = {'products': products, 'parts': parts, 'quantities': quantities, 'len': len(quantities)}
return render(request, 'parts/parts.html', context)
def part_search(request):
if "term" in request.GET:
term = request.GET.get("term", '')