Show free and mounted spools in stock table

This commit is contained in:
Mikei386 committed 2026-11-14 18:53:12 +01:00
1 parent 71c3f75966
commit fedd019854
5 files changed
+129 -11

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ class PrivatePageMiddleware:
image_sources = "'self' data:"
if request.resolver_match and request.resolver_match.url_name in {
"inventory",
"empty_spools",
"shared_inventory",
"orders",
"order_history",
+25 -1
View File
@@ -401,6 +401,21 @@ p {
margin-top: 4px;
color: var(--muted);
}
.spool-totals {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.spool-stock-editor {
padding: 16px 22px;
border-top: 1px solid var(--line);
}
.spool-stock-editor summary {
cursor: pointer;
color: var(--green);
font-size: 13px;
font-weight: 650;
}
.empty-spool-form {
margin-top: 20px;
}
@@ -460,10 +475,19 @@ td.quantity {
}
.order-row--unavailable,
.order-row--unavailable:hover,
.order-row--unavailable:focus-within {
.order-row--unavailable:focus-within,
.spool-row--in-use,
.spool-row--in-use:hover {
background: #e5eaee;
color: #4d6069;
}
.spool-row--in-use .badge {
color: var(--muted);
background: #27455414;
}
.spool-row--in-use td.quantity {
color: inherit;
}
.order-row--ordered,
.order-row--ordered:hover,
.order-row--ordered:focus-within {
+35
View File
@@ -60,6 +60,41 @@ class EmptySpoolTests(CatalogTestCase):
)
self.assertFalse(InventoryItem.objects.filter(pk=self.refills.pk).exists())
def test_spool_table_counts_mounted_and_free_spools_without_double_counting(self):
mounted_other = InventoryItem.objects.create(
owner=self.alice, variant=self.spool, quantity=3, bambu_spool=False
)
InventoryItem.objects.create(
owner=self.bob, variant=self.black_spool, quantity=99, bambu_spool=True
)
response = self.client.get(self.tab)
self.assertEqual(response.context["mounted"], [mounted_other])
self.assertEqual(response.context["quantity"], 1)
self.assertEqual(response.context["total"], 4)
self.assertEqual(response.context["bambu_total"], 1)
self.assertContains(response, "Andere Spule")
self.assertContains(response, 'class="spool-row--in-use"', count=1)
self.client.post(self.mount_url, {"quantity": 2})
response = self.client.get(self.tab)
self.assertEqual(response.context["quantity"], 0)
self.assertEqual(response.context["in_use"], 4)
self.assertEqual(response.context["total"], 4)
self.assertEqual(response.context["bambu_total"], 1)
self.assertContains(response, "SUNLU · PLA Matte")
self.assertContains(response, '<span class="badge">In Benutzung</span>', count=2)
mounted = InventoryItem.objects.get(
owner=self.alice, variant=self.sunlu_refill, bambu_spool=True
)
self.client.post(
reverse("inventory_consume", args=[mounted.pk]), {"quantity": 1, "action": "consume"}
)
response = self.client.get(self.tab)
self.assertEqual(response.context["mounted"], [mounted_other])
self.assertEqual(response.context["quantity"], 1)
self.assertEqual(response.context["in_use"], 3)
self.assertEqual(response.context["total"], 4)
def test_mount_and_correction_validate_current_quantity_and_stay_private(self):
self.assertRedirects(
self.client.post(self.tab, {"quantity": 0, "expected_quantity": 1}), self.tab
+15 -1
View File
@@ -329,7 +329,21 @@ def empty_spools(request):
else:
messages.success(request, "Leerrollenbestand gespeichert.")
return redirect("empty_spools")
return render(request, "filament/empty_spools.html", {"form": form, "quantity": quantity})
mounted = list(_stock_items().filter(owner=request.user, spool_type=Variant.SpoolType.SPOOL))
in_use = sum(item.quantity for item in mounted)
bambu_in_use = sum(item.quantity for item in mounted if item.bambu_spool)
return render(
request,
"filament/empty_spools.html",
{
"form": form,
"quantity": quantity,
"mounted": mounted,
"in_use": in_use,
"total": quantity + in_use,
"bambu_total": quantity + bambu_in_use,
},
)
@login_required
+53 -9
View File
@@ -5,15 +5,59 @@
<div><h1>Mein Bestand</h1></div>
</div>
{% include "filament/inventory_tabs.html" with active="spools" empty_count=quantity only %}
<section class="panel form-panel">
<h2>Bambu-Lab-Leerrollen</h2>
<p class="muted">Trag deine vorhandenen Leerrollen ein. Beim Aufziehen und Verbrauchen passt sich die Stückzahl automatisch an.</p>
<form method="post" class="empty-spool-form">
{% csrf_token %}{{ form.non_field_errors }}{{ form.expected_quantity }}{{ form.expected_quantity.errors }}
<div class="field">
{{ form.quantity.label_tag }}{{ form.quantity }}{{ form.quantity.errors }}
<section class="panel" aria-labelledby="spool-stock-title">
<div class="panel-heading stock-panel-heading">
<h2 id="spool-stock-title">Deine Spulen</h2>
<div class="spool-totals">
<span class="badge">{{ quantity }} frei</span>
<span class="badge">{{ in_use }} in Benutzung</span>
<span class="badge">{{ total }} gesamt · {{ bambu_total }} Bambu Lab</span>
</div>
<button class="button" type="submit">Bestand speichern</button>
</form>
</div>
<div class="table-wrap">
<table class="inventory-table">
<thead>
<tr>
<th scope="col">Spule</th>
<th scope="col">Filament</th>
<th scope="col">Farbe</th>
<th scope="col">Status</th>
<th scope="col">Stück</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bambu Lab</td>
<td>–</td>
<td>–</td>
<td><span class="badge">Frei</span></td>
<td class="quantity">{{ quantity }}</td>
</tr>
{% for item in mounted %}
<tr class="spool-row--in-use">
<td>{% if item.bambu_spool %}Bambu Lab{% else %}Andere Spule{% endif %}</td>
<td>{{ item.variant.product_type }}</td>
<td><div class="variant-preview">
{% include "filament/variant_thumbnail.html" with variant=item.variant only %}
<strong>{{ item.variant.color }}</strong>
</div></td>
<td><span class="badge">In Benutzung</span></td>
<td class="quantity">{{ item.quantity }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<details class="spool-stock-editor"{% if form.errors %} open{% endif %}>
<summary>Freie Bambu-Lab-Spulen bearbeiten</summary>
<form method="post" class="empty-spool-form">
{% csrf_token %}{{ form.non_field_errors }}{{ form.expected_quantity }}{{ form.expected_quantity.errors }}
<div class="field">
{{ form.quantity.label_tag }}{{ form.quantity }}{{ form.quantity.errors }}
</div>
<button class="button" type="submit">Bestand speichern</button>
</form>
</details>
</section>
<p class="hint">Bambu-Lab-Spulen werden beim Verbrauch automatisch frei und können zum Aufziehen verwendet werden.</p>
{% endblock %}