Update statuses from consolidated orders and restore scroll position
This commit is contained in:
1 parent
3061eed44c
commit
45219614bb
11 files changed
+352
-94
No files matched your search
@@ -74,6 +74,11 @@ urlpatterns = [
|
||||
path("bestand/<int:pk>/anbieten/", views.marketplace_offer, name="marketplace_offer"),
|
||||
path("bestellung/", views.orders, name="orders"),
|
||||
path("bestellung/einkaufsliste/", views.order_shopping_list, name="order_shopping_list"),
|
||||
path(
|
||||
"bestellung/einkaufsliste/<str:source>/<int:product_id>/<int:color_id>/<str:spool_type>/status/",
|
||||
views.shopping_order_status,
|
||||
name="shopping_order_status",
|
||||
),
|
||||
path(
|
||||
"bestellung/person/<int:owner_id>/status/",
|
||||
views.person_order_status,
|
||||
|
||||
@@ -22,6 +22,8 @@ Keine SPA, keine externen Schriften/Skripte, kein externer Datenbankserver.
|
||||
- Sammelbestellung mit separater Tabelle je Person. Angemeldete Mitglieder können den Status
|
||||
einzeln oder für ausgewählte Positionen in der Reihenfolge Offen → Bestellt → Eingetroffen
|
||||
→ Übergeben ändern. Teilmengen lassen sich bei Lieferung und Übergabe erfassen.
|
||||
- Die konsolidierte Bestellliste fasst dieselben laufenden Positionen nach Variante und Status
|
||||
zusammen. Vor einer Statusänderung lassen sich die betroffenen Positionen je Person auswählen.
|
||||
- Bei Übergabe wird die Menge in den Bestand der Person gebucht. Spule und Refill bleiben getrennt.
|
||||
Bestellte und eingetroffene Positionen sind vor dem Entfernen geschützt. Korrekturen und
|
||||
Stornierungen werden mit Begründung im Bestellverlauf protokolliert.
|
||||
|
||||
+6
-4
@@ -262,13 +262,15 @@ class OrderStatusForm(forms.Form):
|
||||
confirmation = forms.CharField(required=False, max_length=100)
|
||||
|
||||
|
||||
class PersonOrderStatusForm(forms.Form):
|
||||
status = forms.ChoiceField(
|
||||
choices=[(status, status.label) for status in OrderItem.BULK_STATUS_SOURCES]
|
||||
)
|
||||
class OrderGroupStatusForm(forms.Form):
|
||||
status = forms.ChoiceField()
|
||||
snapshot = forms.CharField(max_length=64)
|
||||
confirmation = forms.CharField(required=False, max_length=128)
|
||||
|
||||
def __init__(self, *args, statuses, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["status"].choices = [(status, status.label) for status in statuses]
|
||||
|
||||
|
||||
class OrderAdjustmentForm(forms.Form):
|
||||
status = forms.ChoiceField(label="Aktion")
|
||||
|
||||
+10
-5
@@ -415,11 +415,7 @@ class OrderItem(QuantityPosition):
|
||||
|
||||
PENDING_STATUSES = (Status.OPEN, Status.UNAVAILABLE)
|
||||
HISTORY_STATUSES = (Status.HANDED_OVER, Status.CANCELLED)
|
||||
BULK_STATUS_SOURCES = {
|
||||
Status.ORDERED: (Status.OPEN,),
|
||||
Status.ARRIVED: (Status.ORDERED,),
|
||||
Status.HANDED_OVER: (Status.ARRIVED,),
|
||||
}
|
||||
BULK_STATUSES = (Status.ORDERED, Status.ARRIVED, Status.HANDED_OVER)
|
||||
STATUS_TRANSITIONS = {
|
||||
Status.OPEN: (Status.OPEN, Status.UNAVAILABLE, Status.ORDERED),
|
||||
Status.UNAVAILABLE: (Status.UNAVAILABLE, Status.OPEN),
|
||||
@@ -503,6 +499,15 @@ class OrderItem(QuantityPosition):
|
||||
def default_order_variant(self):
|
||||
return next(iter(self.order_variants), None)
|
||||
|
||||
@property
|
||||
def shopping_variant(self):
|
||||
return self.default_order_variant if self.is_pending else self.variant
|
||||
|
||||
@property
|
||||
def shopping_spool_type(self):
|
||||
variant = self.shopping_variant
|
||||
return variant.spool_type if variant else self.requested_spool_type
|
||||
|
||||
@property
|
||||
def available_status_choices(self):
|
||||
return [
|
||||
|
||||
+13
-7
@@ -339,24 +339,30 @@ def person_order_items(owner_id):
|
||||
)
|
||||
|
||||
|
||||
def person_order_targets(entries, status):
|
||||
sources = OrderItem.BULK_STATUS_SOURCES.get(status, ())
|
||||
return [entry for entry in entries if entry.status in sources]
|
||||
def order_status_targets(entries, status):
|
||||
return [
|
||||
entry
|
||||
for entry in entries
|
||||
if status != entry.status and status in OrderItem.STATUS_TRANSITIONS.get(entry.status, ())
|
||||
]
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def update_person_order_status(owner_id, status, expected_snapshot, selected_spools):
|
||||
def update_order_group_status(
|
||||
positions, status, expected_snapshot, selected_spools, *, spool_type=None
|
||||
):
|
||||
entries = list(
|
||||
person_order_items(owner_id)
|
||||
.select_for_update()
|
||||
positions.select_for_update()
|
||||
.select_related("variant__product_type__manufacturer", "variant__color")
|
||||
.order_by("pk")
|
||||
)
|
||||
if spool_type is not None:
|
||||
entries = [entry for entry in entries if entry.shopping_spool_type == spool_type]
|
||||
if order_group_snapshot(entries) != expected_snapshot:
|
||||
raise ValidationError(
|
||||
"Die Bestellwünsche haben sich geändert. Bitte prüfe die aktuelle Liste."
|
||||
)
|
||||
targets = [item for item in person_order_targets(entries, status) if item.pk in selected_spools]
|
||||
targets = [item for item in order_status_targets(entries, status) if item.pk in selected_spools]
|
||||
if not targets or len(targets) != len(selected_spools):
|
||||
raise ValidationError("Bitte wähle gültige Positionen für diesen Status aus.")
|
||||
for item in targets:
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
(() => {
|
||||
const search = new URL(location.href).searchParams.get("q")?.trim().slice(0, 200) || "";
|
||||
const key = `order-scroll:${location.pathname}:${search}`;
|
||||
|
||||
function remember(control) {
|
||||
const anchor = control.closest("[data-order-anchor]");
|
||||
if (!anchor) return;
|
||||
const neighbor = [anchor.nextElementSibling, anchor.previousElementSibling].find(
|
||||
(element) => element?.hasAttribute("data-order-anchor"),
|
||||
);
|
||||
const state = {
|
||||
top: window.scrollY,
|
||||
anchors: [anchor, neighbor].filter(Boolean).map(
|
||||
(element) => ({ id: element.id, offset: element.getBoundingClientRect().top }),
|
||||
),
|
||||
};
|
||||
try {
|
||||
sessionStorage.setItem(key, JSON.stringify(state));
|
||||
} catch {
|
||||
// Session storage can be disabled by the browser.
|
||||
}
|
||||
}
|
||||
|
||||
function restore() {
|
||||
let state;
|
||||
try {
|
||||
state = JSON.parse(sessionStorage.getItem(key));
|
||||
sessionStorage.removeItem(key);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (!state) return;
|
||||
for (const { id, offset } of state.anchors) {
|
||||
const anchor = document.getElementById(id);
|
||||
if (anchor) {
|
||||
window.scrollTo({ top: window.scrollY + anchor.getBoundingClientRect().top - offset });
|
||||
return;
|
||||
}
|
||||
}
|
||||
window.scrollTo({ top: state.top });
|
||||
}
|
||||
|
||||
document.addEventListener("submit", (event) => {
|
||||
if (!event.defaultPrevented && event.target.matches("form[data-order-scroll]")) {
|
||||
remember(event.target);
|
||||
}
|
||||
});
|
||||
document.addEventListener("click", (event) => {
|
||||
if (event.defaultPrevented || event.button !== 0 || event.ctrlKey || event.metaKey
|
||||
|| event.shiftKey || event.altKey) return;
|
||||
const link = event.target.closest("a[data-order-scroll]");
|
||||
if (link) remember(link);
|
||||
});
|
||||
window.addEventListener("pageshow", restore);
|
||||
})();
|
||||
@@ -192,16 +192,93 @@ class SharedOrderTests(CatalogTestCase):
|
||||
self.assertContains(orders, 'aria-label="Artikelnummer 10100 kopieren"', count=5)
|
||||
result = self.client.get(url, {"q": "10100"})
|
||||
self.assertEqual(
|
||||
{variant.pk: variant.order_quantity for variant in result.context["variants"]},
|
||||
{
|
||||
group["variant"].pk: group["quantity"]
|
||||
for group in result.context["groups"]
|
||||
if group["status"] == OrderItem.Status.OPEN
|
||||
},
|
||||
{self.spool.pk: 3, self.refill.pk: 1},
|
||||
)
|
||||
self.assertContains(result, 'aria-label="Artikelnummer 10100 kopieren"', count=2)
|
||||
self.assertContains(result, 'aria-label="Artikelnummer 10100 kopieren"', count=4)
|
||||
self.assertEqual(result.context["total"], 4)
|
||||
self.assertNotContains(result, "Im Bambu-Shop suchen")
|
||||
self.assertNotContains(result, 'class="article-copy-icon"')
|
||||
self.assertEqual(self.client.get(url, {"q": "10100, 10101"}).context["total"], 5)
|
||||
self.assertEqual(self.client.post(url).status_code, 405)
|
||||
|
||||
def test_consolidated_status_updates_selected_recipients_and_preserves_filter(self):
|
||||
first = OrderItem.objects.create(owner=self.alice, variant=self.spool, quantity=2)
|
||||
second = OrderItem.objects.create(owner=self.bob, variant=self.spool, quantity=3)
|
||||
refill = OrderItem.objects.create(owner=self.bob, variant=self.refill, quantity=1)
|
||||
Variant.objects.filter(pk__in=[self.spool.pk, self.refill.pk]).update(
|
||||
manufacturer_color_code="10100"
|
||||
)
|
||||
self.client.force_login(self.alice)
|
||||
listing = reverse("order_shopping_list", query={"q": "10100"})
|
||||
self.assertContains(self.client.get(listing), "order_scroll.js")
|
||||
self.assertContains(self.client.get(reverse("orders")), "order_scroll.js")
|
||||
source = OrderItem.Status.OPEN
|
||||
for target in (
|
||||
OrderItem.Status.ORDERED,
|
||||
OrderItem.Status.ARRIVED,
|
||||
OrderItem.Status.HANDED_OVER,
|
||||
):
|
||||
with self.subTest(target=target):
|
||||
group = next(
|
||||
row
|
||||
for row in self.client.get(listing).context["groups"]
|
||||
if row["variant"].pk == self.spool.pk and row["status"] == source
|
||||
)
|
||||
url = group["url"]
|
||||
data = {"status": target, "snapshot": group["snapshot"]}
|
||||
preview = self.client.post(url, data)
|
||||
self.assertContains(preview, self.bob.username)
|
||||
self.assertEqual(preview.context["entries"], [first, second])
|
||||
self.assertEqual(preview.context["back_url"], listing)
|
||||
self.assertFalse(InventoryItem.objects.exists())
|
||||
confirmation = self.person_confirmation(data, preview)
|
||||
rejected = self.client.post(
|
||||
url, confirmation | {"entry_ids": [first.pk, refill.pk]}, follow=True
|
||||
)
|
||||
self.assertContains(rejected, "Bitte wähle gültige Positionen")
|
||||
self.assertRedirects(self.client.post(url, confirmation), listing)
|
||||
self.assertRedirects(self.client.post(url, confirmation), listing)
|
||||
first.refresh_from_db()
|
||||
second.refresh_from_db()
|
||||
self.assertEqual((first.status, second.status), (target, target))
|
||||
source = target
|
||||
quantities = dict(
|
||||
InventoryItem.objects.filter(variant=self.spool).values_list("owner_id", "quantity")
|
||||
)
|
||||
self.assertEqual(quantities, {self.alice.pk: 2, self.bob.pk: 3})
|
||||
self.assertEqual(self.client.get(listing).context["total"], 1)
|
||||
orders = self.client.get(reverse("orders"))
|
||||
self.assertContains(orders, f'id="order-item-{refill.pk}"')
|
||||
self.assertNotContains(orders, f'id="order-item-{first.pk}"')
|
||||
|
||||
def test_consolidated_unavailable_can_be_set_and_reopened_for_part_of_a_group(self):
|
||||
first = OrderItem.objects.create(owner=self.alice, variant=self.spool, quantity=2)
|
||||
second = OrderItem.objects.create(owner=self.bob, variant=self.spool, quantity=3)
|
||||
self.client.force_login(self.alice)
|
||||
listing = reverse("order_shopping_list")
|
||||
source = OrderItem.Status.OPEN
|
||||
for target in (OrderItem.Status.UNAVAILABLE, OrderItem.Status.OPEN):
|
||||
group = next(
|
||||
row for row in self.client.get(listing).context["groups"] if row["status"] == source
|
||||
)
|
||||
data = {"status": target, "snapshot": group["snapshot"]}
|
||||
preview = self.client.post(group["url"], data)
|
||||
self.assertRedirects(
|
||||
self.client.post(group["url"], self.person_confirmation(data, preview, [first])),
|
||||
listing,
|
||||
)
|
||||
self.assertContains(self.client.get(reverse("orders")), f"order-row--{target}")
|
||||
first.refresh_from_db()
|
||||
second.refresh_from_db()
|
||||
self.assertEqual(first.status, target)
|
||||
self.assertEqual(second.status, OrderItem.Status.OPEN)
|
||||
source = target
|
||||
|
||||
def test_history_is_shared_and_records_order_and_handover_times(self):
|
||||
url = reverse("order_history")
|
||||
self.assertRedirects(self.client.get(url), f"/anmelden/?next={url}")
|
||||
@@ -467,7 +544,7 @@ class SharedOrderTests(CatalogTestCase):
|
||||
product_type=self.product, color=self.black, spool_type=Variant.SpoolType.REFILL
|
||||
)
|
||||
shopping = self.client.get(reverse("order_shopping_list"))
|
||||
self.assertEqual([item.pk for item in shopping.context["variants"]], [variant.pk])
|
||||
self.assertEqual([row["variant"].pk for row in shopping.context["groups"]], [variant.pk])
|
||||
self.assertEqual((shopping.context["total"], shopping.context["unavailable"]), (2, 0))
|
||||
|
||||
def test_can_explicitly_order_an_allowed_alternative_when_both_types_exist(self):
|
||||
|
||||
+137
-49
@@ -28,10 +28,10 @@ from .forms import (
|
||||
MountRefillForm,
|
||||
OrderAdjustmentForm,
|
||||
OrderArrivalForm,
|
||||
OrderGroupStatusForm,
|
||||
OrderHandoverForm,
|
||||
OrderSelectionForm,
|
||||
OrderStatusForm,
|
||||
PersonOrderStatusForm,
|
||||
PrinterAddonForm,
|
||||
PrinterForm,
|
||||
PrinterNozzleForm,
|
||||
@@ -68,15 +68,15 @@ from .services import (
|
||||
create_marketplace_offer,
|
||||
mount_refill,
|
||||
order_group_snapshot,
|
||||
order_status_targets,
|
||||
person_order_items,
|
||||
person_order_targets,
|
||||
record_order_arrival,
|
||||
remove_inventory_position,
|
||||
take_marketplace_offer,
|
||||
undo_order_handover,
|
||||
update_inventory_position,
|
||||
update_order_group_status,
|
||||
update_order_status,
|
||||
update_person_order_status,
|
||||
withdraw_marketplace_offer,
|
||||
)
|
||||
|
||||
@@ -984,7 +984,7 @@ def orders(request):
|
||||
for entry in entries
|
||||
}
|
||||
),
|
||||
"bulk_statuses": OrderItem.BULK_STATUS_SOURCES,
|
||||
"bulk_statuses": OrderItem.BULK_STATUSES,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -992,121 +992,209 @@ def orders(request):
|
||||
@login_required
|
||||
@require_http_methods(["GET", "HEAD"])
|
||||
def order_shopping_list(request):
|
||||
search = request.GET.get("q", "").strip()[:200]
|
||||
search = _shopping_search(request)
|
||||
codes = {code.casefold() for code in re.split(r"[\s,;]+", search) if code}
|
||||
if search:
|
||||
codes.add(search.casefold())
|
||||
grouped = {}
|
||||
total = 0
|
||||
unavailable = 0
|
||||
for entry in _orders_with_catalog(OrderItem.objects.filter(status=OrderItem.Status.OPEN)):
|
||||
variant = entry.default_order_variant
|
||||
if variant is None:
|
||||
unavailable += entry.quantity
|
||||
entries = _orders_with_catalog(OrderItem.objects.exclude(status__in=OrderItem.HISTORY_STATUSES))
|
||||
for entry in entries:
|
||||
variant = entry.shopping_variant
|
||||
article = variant.manufacturer_color_code.strip() if variant else ""
|
||||
if codes and article.casefold() not in codes:
|
||||
continue
|
||||
if codes and variant.manufacturer_color_code.strip().casefold() not in codes:
|
||||
continue
|
||||
if variant.pk not in grouped:
|
||||
variant.order_quantity = 0
|
||||
variant.alternative_quantity = 0
|
||||
grouped[variant.pk] = variant
|
||||
selected = grouped[variant.pk]
|
||||
selected.order_quantity += entry.quantity
|
||||
if variant.spool_type != entry.requested_spool_type:
|
||||
selected.alternative_quantity += entry.quantity
|
||||
variants = sorted(
|
||||
grouped.values(),
|
||||
key=lambda variant: (
|
||||
variant.manufacturer.name,
|
||||
variant.product_type.name,
|
||||
variant.color.name,
|
||||
variant.spool_type,
|
||||
variant.pk,
|
||||
),
|
||||
spool_type = Variant.SpoolType(entry.shopping_spool_type)
|
||||
source = OrderItem.Status(entry.status)
|
||||
reference = variant or entry.variant
|
||||
key = (source, reference.product_type_id, reference.color_id, spool_type)
|
||||
if key not in grouped:
|
||||
grouped[key] = {
|
||||
"variant": reference,
|
||||
"spool_type": spool_type,
|
||||
"article": article,
|
||||
"available": variant is not None,
|
||||
"status": source,
|
||||
"choices": _shopping_status_choices(source, variant is not None),
|
||||
"quantity": 0,
|
||||
"alternative_quantity": 0,
|
||||
"entries": [],
|
||||
}
|
||||
group = grouped[key]
|
||||
group["quantity"] += entry.quantity
|
||||
group["entries"].append(entry)
|
||||
if spool_type != entry.requested_spool_type:
|
||||
group["alternative_quantity"] += entry.quantity
|
||||
if source == OrderItem.Status.OPEN:
|
||||
if variant is None:
|
||||
unavailable += entry.quantity
|
||||
else:
|
||||
total += entry.quantity
|
||||
|
||||
groups = []
|
||||
for key, group in grouped.items():
|
||||
group["anchor"] = "shopping-" + "-".join(str(part) for part in key)
|
||||
group["url"] = reverse(
|
||||
"shopping_order_status", args=key, query={"q": search} if search else None
|
||||
)
|
||||
group["snapshot"] = order_group_snapshot(group.pop("entries"))
|
||||
groups.append(group)
|
||||
groups.sort(
|
||||
key=lambda group: (
|
||||
group["variant"].manufacturer.name,
|
||||
group["variant"].product_type.name,
|
||||
group["variant"].color.name,
|
||||
group["spool_type"],
|
||||
OrderItem.Status.values.index(group["status"]),
|
||||
)
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"filament/order_shopping_list.html",
|
||||
{
|
||||
"variants": variants,
|
||||
"total": sum(variant.order_quantity for variant in variants),
|
||||
"groups": groups,
|
||||
"total": total,
|
||||
"search": search,
|
||||
"unavailable": unavailable if not search else 0,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _shopping_search(request):
|
||||
return request.GET.get("q", "").strip()[:200]
|
||||
|
||||
|
||||
def _shopping_status_choices(source, available=True):
|
||||
return [
|
||||
status
|
||||
for status in OrderItem.STATUS_TRANSITIONS.get(source, ())
|
||||
if status != source and (available or status != OrderItem.Status.ORDERED)
|
||||
]
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["POST"])
|
||||
def person_order_status(request, owner_id):
|
||||
form = PersonOrderStatusForm(request.POST)
|
||||
return _order_group_status(
|
||||
request,
|
||||
person_order_items(owner_id),
|
||||
OrderItem.BULK_STATUSES,
|
||||
reverse("orders"),
|
||||
by_person=True,
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["POST"])
|
||||
def shopping_order_status(request, source, product_id, color_id, spool_type):
|
||||
if source not in OrderItem.STATUS_TRANSITIONS or spool_type not in Variant.SpoolType.values:
|
||||
raise Http404
|
||||
positions = OrderItem.objects.filter(
|
||||
status=source, variant__product_type_id=product_id, variant__color_id=color_id
|
||||
)
|
||||
search = _shopping_search(request)
|
||||
return _order_group_status(
|
||||
request,
|
||||
positions,
|
||||
_shopping_status_choices(source),
|
||||
reverse("order_shopping_list", query={"q": search} if search else None),
|
||||
spool_type=spool_type,
|
||||
)
|
||||
|
||||
|
||||
def _order_group_status(
|
||||
request, positions, statuses, back_url, *, by_person=False, spool_type=None
|
||||
):
|
||||
form = OrderGroupStatusForm(request.POST, statuses=statuses)
|
||||
if not form.is_valid():
|
||||
messages.error(request, "Bitte wähle einen gültigen Status für die Sammeländerung.")
|
||||
return redirect("orders")
|
||||
return redirect(back_url)
|
||||
|
||||
status = form.cleaned_data["status"]
|
||||
snapshot = form.cleaned_data["snapshot"]
|
||||
confirmation = form.cleaned_data["confirmation"]
|
||||
signer = Signer(salt=f"filament.person_order_status.{request.user.pk}.{owner_id}")
|
||||
signer = Signer(salt=f"filament.order_group_status.{request.user.pk}.{request.path}")
|
||||
signature_value = f"{status}:{snapshot}"
|
||||
if not confirmation:
|
||||
return _confirm_person_order_status(
|
||||
request, owner_id, status, snapshot, signer.sign(signature_value)
|
||||
return _confirm_order_group_status(
|
||||
request,
|
||||
positions,
|
||||
status,
|
||||
snapshot,
|
||||
signer.sign(signature_value),
|
||||
back_url,
|
||||
by_person=by_person,
|
||||
spool_type=spool_type,
|
||||
)
|
||||
try:
|
||||
if signer.unsign(confirmation) != signature_value:
|
||||
raise BadSignature
|
||||
except BadSignature:
|
||||
messages.error(request, "Bitte bestätige die Sammeländerung erneut.")
|
||||
return redirect("orders")
|
||||
return redirect(back_url)
|
||||
|
||||
selected_spools = {
|
||||
selection_id(value): request.POST.get(f"spool_type_{value}")
|
||||
for value in request.POST.getlist("entry_ids")
|
||||
}
|
||||
try:
|
||||
entries = update_person_order_status(owner_id, status, snapshot, selected_spools)
|
||||
entries = update_order_group_status(
|
||||
positions, status, snapshot, selected_spools, spool_type=spool_type
|
||||
)
|
||||
except ValidationError as error:
|
||||
messages.error(request, error.messages[0])
|
||||
else:
|
||||
if status == OrderItem.Status.HANDED_OVER:
|
||||
total = sum(entry.quantity for entry in entries)
|
||||
destination = (
|
||||
f"im Bestand von {entries[0].owner.username}"
|
||||
if by_person
|
||||
else "in die jeweiligen Bestände"
|
||||
)
|
||||
messages.success(
|
||||
request,
|
||||
f"Übergabe gespeichert. {total} Stück im Bestand von "
|
||||
f"{entries[0].owner.username} eingebucht.",
|
||||
f"Übergabe gespeichert. {total} Stück {destination} eingebucht.",
|
||||
)
|
||||
else:
|
||||
messages.success(request, f"Bestellstatus für {len(entries)} Positionen gespeichert.")
|
||||
return redirect("orders")
|
||||
count = len(entries)
|
||||
label = "Position" if count == 1 else "Positionen"
|
||||
messages.success(request, f"Bestellstatus für {count} {label} gespeichert.")
|
||||
return redirect(back_url)
|
||||
|
||||
|
||||
def _confirm_person_order_status(request, owner_id, status, snapshot, confirmation):
|
||||
def _confirm_order_group_status(
|
||||
request, positions, status, snapshot, confirmation, back_url, *, by_person, spool_type
|
||||
):
|
||||
entries = list(
|
||||
_orders_with_catalog(person_order_items(owner_id)).order_by(
|
||||
"variant__product_type__name", "variant__color__name", "pk"
|
||||
_orders_with_catalog(positions).order_by(
|
||||
"owner__username", "variant__product_type__name", "variant__color__name", "pk"
|
||||
)
|
||||
)
|
||||
if spool_type is not None:
|
||||
entries = [entry for entry in entries if entry.shopping_spool_type == spool_type]
|
||||
if order_group_snapshot(entries) != snapshot:
|
||||
messages.error(
|
||||
request, "Die Bestellwünsche haben sich geändert. Bitte prüfe die aktuelle Liste."
|
||||
)
|
||||
return redirect("orders")
|
||||
targets = person_order_targets(entries, status)
|
||||
return redirect(back_url)
|
||||
targets = order_status_targets(entries, status)
|
||||
if status == OrderItem.Status.ORDERED:
|
||||
targets = [entry for entry in targets if entry.order_variants]
|
||||
if not targets:
|
||||
messages.info(request, "Für diesen Status gibt es keine passenden Bestellpositionen.")
|
||||
return redirect("orders")
|
||||
return redirect(back_url)
|
||||
return render(
|
||||
request,
|
||||
"filament/order_person_status.html",
|
||||
"filament/order_group_status.html",
|
||||
{
|
||||
"owner": targets[0].owner,
|
||||
"owner": targets[0].owner if by_person else None,
|
||||
"entries": targets,
|
||||
"total": sum(entry.quantity for entry in targets),
|
||||
"snapshot": snapshot,
|
||||
"confirmation": confirmation,
|
||||
"status": OrderItem.Status(status),
|
||||
"back_url": back_url,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
+4
-4
@@ -5,8 +5,8 @@
|
||||
<h1>{% if status == "handed_over" %}Sammelübergabe bestätigen{% else %}Bestellstatus ändern{% endif %}</h1>
|
||||
</div>
|
||||
<section class="panel form-panel">
|
||||
<p><strong>{{ owner.username }}</strong> · {{ status.label }} · {{ total }} Rolle{{ total|pluralize:"n" }} zur Auswahl</p>
|
||||
{% if status == "handed_over" %}<p>Die ausgewählten Rollen werden in den Bestand von {{ owner.username }} eingebucht.</p>{% endif %}
|
||||
<p>{% if owner %}<strong>{{ owner.username }}</strong> · {% endif %}{{ status.label }} · {{ total }} Rolle{{ total|pluralize:"n" }} zur Auswahl</p>
|
||||
{% if status == "handed_over" %}<p>Die ausgewählten Rollen werden {% if owner %}in den Bestand von {{ owner.username }}{% else %}in die jeweiligen Bestände{% endif %} eingebucht.</p>{% endif %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="status" value="{{ status }}">
|
||||
@@ -18,7 +18,7 @@
|
||||
{% with catalog=entry.catalog_details %}
|
||||
<div class="order-selection-item">
|
||||
<label><input name="entry_ids" type="checkbox" value="{{ entry.pk }}" checked>
|
||||
<span>{{ entry.quantity }} × {{ catalog.manufacturer }} · {{ catalog.product }} · {{ catalog.color }}
|
||||
<span>{% if not owner %}<strong>{{ entry.owner.username }}</strong> · {% endif %}{{ entry.quantity }} × {{ catalog.manufacturer }} · {{ catalog.product }} · {{ catalog.color }}
|
||||
{% if status == "ordered" %}
|
||||
· Gewünscht: {{ entry.requested_spool_label }}
|
||||
{% else %}
|
||||
@@ -39,7 +39,7 @@
|
||||
</fieldset>
|
||||
<div class="form-actions">
|
||||
<button class="button" type="submit">{% if status == "handed_over" %}Übergabe bestätigen und einbuchen{% else %}Status bestätigen{% endif %}</button>
|
||||
<a class="button secondary" href="{% url 'orders' %}">Abbrechen</a>
|
||||
<a class="button secondary" href="{{ back_url }}">Abbrechen</a>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
@@ -4,33 +4,49 @@
|
||||
{% block content %}
|
||||
<a class="back-link" href="{% url 'orders' %}">← Sammelbestellung nach Person</a>
|
||||
<div class="page-heading">
|
||||
<div><h1>Konsolidierte Bestellliste</h1><p class="muted">Offene Bestellwünsche aller Personen, zusammengezählt pro Variante.</p></div>
|
||||
<div><h1>Konsolidierte Bestellliste</h1><p class="muted">Laufende Bestellpositionen aller Personen, zusammengezählt pro Variante und Status.</p></div>
|
||||
</div>
|
||||
{% include "filament/list_search.html" with search_url="order_shopping_list" search_label="Nach einer oder mehreren Artikelnummern suchen" placeholder="Artikelnummern, z. B. 10100, 10604" %}
|
||||
{% if unavailable %}<p class="hint">Für {{ unavailable }} Rolle{{ unavailable|pluralize:"n" }} ist keine zulässige Spulenausführung im Katalog verfügbar.</p>{% endif %}
|
||||
{% if variants %}
|
||||
<section class="panel" aria-label="Offene Bestellwünsche">
|
||||
{% if groups %}
|
||||
<section class="panel" aria-label="Laufende Bestellpositionen">
|
||||
<div class="panel-heading">
|
||||
<h2>{% if search %}Suchergebnis{% else %}Offene Bestellwünsche{% endif %}</h2>
|
||||
<span class="badge">{{ total }} Rolle{{ total|pluralize:"n" }} · {{ variants|length }} Variante{{ variants|length|pluralize:"n" }}</span>
|
||||
<h2>{% if search %}Suchergebnis{% else %}Bestellpositionen{% endif %}</h2>
|
||||
<span class="badge">{{ total }} Rolle{{ total|pluralize:"n" }} offen zur Bestellung</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="order-table">
|
||||
<thead><tr><th scope="col">Stück</th><th scope="col">Produktart</th><th scope="col">Farbe</th><th scope="col">Spulenausführung</th><th scope="col">Artikelnr.</th></tr></thead>
|
||||
<thead><tr><th scope="col">Stück</th><th scope="col">Produktart</th><th scope="col">Farbe</th><th scope="col">Spulenausführung</th><th scope="col">Artikelnr.</th><th scope="col">Status</th></tr></thead>
|
||||
<tbody>
|
||||
{% for variant in variants %}
|
||||
<tr>
|
||||
<td class="quantity">{{ variant.order_quantity }}</td>
|
||||
{% for group in groups %}
|
||||
{% with variant=group.variant %}
|
||||
<tr id="{{ group.anchor }}" class="order-row order-row--{{ group.status }}" data-order-anchor>
|
||||
<td class="quantity">{{ group.quantity }}</td>
|
||||
<td>{{ variant.product_type.name }}<small>{{ variant.manufacturer }}</small></td>
|
||||
<td><div class="variant-preview">{% include "filament/variant_thumbnail.html" with variant=variant only %}<strong>{{ variant.color_label }}</strong></div></td>
|
||||
<td>
|
||||
<span class="badge">{{ variant.get_spool_type_display }}</span>
|
||||
{% if variant.alternative_quantity %}<small>Davon {{ variant.alternative_quantity }} als erlaubte Alternative</small>{% endif %}
|
||||
<span class="badge">{{ group.spool_type.label }}</span>
|
||||
{% if group.alternative_quantity %}<small>Davon {{ group.alternative_quantity }} als erlaubte Alternative</small>{% endif %}
|
||||
{% if not group.available %}<small class="warning">Keine zulässige Ausführung im Katalog</small>{% else %}
|
||||
{% if variant.net_weight_g or variant.diameter_mm %}<small>{% if variant.net_weight_g %}{{ variant.net_weight_g }} g{% endif %}{% if variant.net_weight_g and variant.diameter_mm %} · {% endif %}{% if variant.diameter_mm %}{{ variant.diameter_mm }} mm{% endif %}</small>{% endif %}
|
||||
{% if not variant.is_active %}<small class="warning">Katalogvariante deaktiviert</small>{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="article-number">{% include "filament/order_article_number.html" with article=group.article only %}</td>
|
||||
<td>
|
||||
<form class="order-status-form" method="post" action="{{ group.url }}" data-order-scroll>
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="snapshot" value="{{ group.snapshot }}">
|
||||
<label class="sr-only" for="{{ group.anchor }}-status">Status für {{ variant.product_type }} · {{ variant.color_label }} · {{ group.spool_type.label }} · {{ group.status.label }}</label>
|
||||
<select id="{{ group.anchor }}-status" name="status" required>
|
||||
<option value="" selected>{{ group.status.label }}</option>
|
||||
{% for status in group.choices %}<option value="{{ status }}">{{ status.label }}</option>{% endfor %}
|
||||
</select>
|
||||
<button class="button secondary" type="submit">Positionen auswählen</button>
|
||||
</form>
|
||||
</td>
|
||||
<td class="article-number">{% include "filament/order_article_number.html" with article=variant.manufacturer_color_code.strip only %}</td>
|
||||
</tr>
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -39,6 +55,7 @@
|
||||
</section>
|
||||
<script src="{% static 'filament/order_article_copy.js' %}" defer></script>
|
||||
{% else %}
|
||||
<section class="panel"><div class="empty"><h2>{% if search %}Keine offenen Wünsche zu diesen Artikelnummern{% else %}Keine offenen Bestellwünsche{% endif %}</h2></div></section>
|
||||
<section class="panel"><div class="empty"><h2>{% if search %}Keine laufenden Positionen zu diesen Artikelnummern{% else %}Keine laufenden Bestellpositionen{% endif %}</h2></div></section>
|
||||
{% endif %}
|
||||
<script src="{% static 'filament/order_scroll.js' %}" defer></script>
|
||||
{% endblock %}
|
||||
@@ -16,9 +16,9 @@
|
||||
</div>
|
||||
{% for username, entries, roll_count, snapshot in groups %}
|
||||
<section class="panel">
|
||||
<div class="panel-heading order-person-heading">
|
||||
<div id="order-owner-{{ entries.0.owner_id }}" class="panel-heading order-person-heading" data-order-anchor>
|
||||
<h2 id="order-person-{{ forloop.counter }}">Bestellwunsch · {{ username }} · ×{{ roll_count }}</h2>
|
||||
<form class="order-status-form person-order-status-form" method="post" action="{% url 'person_order_status' entries.0.owner_id %}">
|
||||
<form class="order-status-form person-order-status-form" method="post" action="{% url 'person_order_status' entries.0.owner_id %}" data-order-scroll>
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="snapshot" value="{{ snapshot }}">
|
||||
<label class="sr-only" for="person-order-status-{{ entries.0.owner_id }}">Status gesammelt ändern für {{ username }}</label>
|
||||
@@ -37,7 +37,7 @@
|
||||
<tbody>
|
||||
{% for entry in entries %}
|
||||
{% with catalog=entry.catalog_details purchase=entry.default_order_variant %}
|
||||
<tr class="order-row order-row--{{ entry.status }}">
|
||||
<tr id="order-item-{{ entry.pk }}" class="order-row order-row--{{ entry.status }}" data-order-anchor>
|
||||
<td class="quantity">{{ entry.quantity }}</td>
|
||||
<td>{{ catalog.product }}<small>{{ catalog.manufacturer }}</small></td>
|
||||
<td><div class="variant-preview">{% include "filament/variant_thumbnail.html" with variant=catalog only %}<strong>{{ catalog.color }}</strong></div></td>
|
||||
@@ -61,7 +61,7 @@
|
||||
{% if not entry.variant.is_active and not purchase %}<small class="warning">Deaktiviert · Katalogvariante</small>{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<form class="order-status-form" method="post" action="{% url 'order_status' entry.pk %}">
|
||||
<form class="order-status-form" method="post" action="{% url 'order_status' entry.pk %}" data-order-scroll>
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="expected_status" value="{{ entry.status }}">
|
||||
<input type="hidden" name="expected_quantity" value="{{ entry.quantity }}">
|
||||
@@ -80,18 +80,18 @@
|
||||
</td>
|
||||
<td class="actions">
|
||||
{% if entry.owner_id == user.pk and entry.is_pending %}
|
||||
<a href="{% url 'order_edit' entry.pk %}">Ändern</a>
|
||||
<a href="{% url 'order_edit' entry.pk %}" data-order-scroll>Ändern</a>
|
||||
{% if not entry.adjustments.all %}
|
||||
<a class="danger-link" href="{% url 'order_delete' entry.pk %}">Entfernen</a>
|
||||
<a class="danger-link" href="{% url 'order_delete' entry.pk %}" data-order-scroll>Entfernen</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if entry.adjustment_choices %}
|
||||
<a href="{% url 'order_adjustment' entry.pk %}">{% if entry.is_pending %}Stornieren{% else %}Korrigieren oder stornieren{% endif %}</a>
|
||||
<a href="{% url 'order_adjustment' entry.pk %}" data-order-scroll>{% if entry.is_pending %}Stornieren{% else %}Korrigieren oder stornieren{% endif %}</a>
|
||||
{% elif entry.adjustments.all %}
|
||||
<a href="{% url 'order_adjustment' entry.pk %}">Verlauf</a>
|
||||
<a href="{% url 'order_adjustment' entry.pk %}" data-order-scroll>Verlauf</a>
|
||||
{% endif %}
|
||||
{% if entry.status == "ordered" and entry.quantity > 1 %}
|
||||
<a href="{% url 'order_arrival' entry.pk %}">Teillieferung erfassen</a>
|
||||
<a href="{% url 'order_arrival' entry.pk %}" data-order-scroll>Teillieferung erfassen</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -108,4 +108,5 @@
|
||||
<p class="sr-only" role="status" data-copy-status></p>
|
||||
<script src="{% static 'filament/order_article_copy.js' %}" defer></script>
|
||||
{% endif %}
|
||||
<script src="{% static 'filament/order_scroll.js' %}" defer></script>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user