Track reusable Bambu Lab spools in personal inventory
This commit is contained in:
1 parent
0287643b97
commit
47efe317bf
17 files changed
+560
-32
No files matched your search
@@ -48,6 +48,34 @@ class QuantityForm(forms.Form):
|
||||
quantity = forms.IntegerField(label="Stückzahl", min_value=1, max_value=9999)
|
||||
|
||||
|
||||
class InventoryQuantityForm(QuantityForm):
|
||||
expected_quantity = forms.IntegerField(
|
||||
min_value=1, max_value=9999, required=False, widget=forms.HiddenInput
|
||||
)
|
||||
bambu_spool = forms.TypedChoiceField(
|
||||
label="Spulenhersteller",
|
||||
required=False,
|
||||
choices=[("bambu", "Bambu Lab"), ("other", "Andere Spule")],
|
||||
coerce=lambda value: value == "bambu",
|
||||
empty_value=None,
|
||||
)
|
||||
|
||||
def __init__(self, *args, item, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.initial["bambu_spool"] = "bambu" if item.bambu_spool else "other"
|
||||
if item.spool_type != Variant.SpoolType.SPOOL:
|
||||
del self.fields["bambu_spool"]
|
||||
|
||||
|
||||
class EmptySpoolQuantityForm(forms.Form):
|
||||
quantity = forms.IntegerField(label="Bambu-Lab-Leerrollen", min_value=0, max_value=9999)
|
||||
expected_quantity = forms.IntegerField(min_value=0, max_value=9999, widget=forms.HiddenInput)
|
||||
|
||||
|
||||
class MountRefillForm(forms.Form):
|
||||
quantity = forms.IntegerField(min_value=1, max_value=9999, widget=forms.HiddenInput)
|
||||
|
||||
|
||||
class ArticleLookupForm(forms.Form):
|
||||
use_required_attribute = False
|
||||
|
||||
@@ -105,14 +133,32 @@ class VariantSelectionForm(forms.Form):
|
||||
widget=ColorSelect(attrs={"data-color-select": ""}),
|
||||
)
|
||||
spool_type = forms.ChoiceField(label="Spulenausführung", choices=[])
|
||||
spool_brand = forms.ChoiceField(
|
||||
label="Spulenhersteller",
|
||||
required=False,
|
||||
choices=[
|
||||
("", "Automatisch nach Filamenthersteller"),
|
||||
("bambu", "Bambu Lab"),
|
||||
("other", "Andere Spule"),
|
||||
],
|
||||
widget=forms.Select(attrs={"data-spool-brand": ""}),
|
||||
)
|
||||
quantity = forms.IntegerField(label="Stückzahl", min_value=1, max_value=9999, initial=1)
|
||||
|
||||
def __init__(self, *args, selection=None, for_inventory=False, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.for_inventory = for_inventory
|
||||
if not for_inventory:
|
||||
del self.fields["spool_brand"]
|
||||
values = self.data if self.is_bound else (selection or {})
|
||||
if not self.is_bound:
|
||||
self.initial.update({k: values[k] for k in self.fields if k in values})
|
||||
if for_inventory and values.get("spool_type") not in (
|
||||
None,
|
||||
"",
|
||||
Variant.SpoolType.SPOOL,
|
||||
):
|
||||
self.initial.pop("spool_brand", None)
|
||||
active = Variant.objects.filter(is_active=True)
|
||||
maker = selection_id(values.get("manufacturer"))
|
||||
product = selection_id(values.get("product_type"))
|
||||
@@ -162,6 +208,8 @@ class VariantSelectionForm(forms.Form):
|
||||
spool_field.widget.attrs["disabled"] = True
|
||||
elif not self.is_bound and values.get("spool_type") not in dict(spool_choices):
|
||||
self.initial["spool_type"] = next(key for key, _ in spool_choices if key in spools)
|
||||
if for_inventory and self["spool_type"].value() != Variant.SpoolType.SPOOL:
|
||||
del self.fields["spool_brand"]
|
||||
|
||||
def clean(self):
|
||||
cleaned = super().clean()
|
||||
@@ -182,4 +230,8 @@ class VariantSelectionForm(forms.Form):
|
||||
raise forms.ValidationError(
|
||||
"Diese Variante ist nicht mehr verfügbar. Bitte neu auswählen."
|
||||
)
|
||||
if self.for_inventory and cleaned["spool_type"] == Variant.SpoolType.SPOOL:
|
||||
self.bambu_spool = {"bambu": True, "other": False}.get(cleaned.get("spool_brand"))
|
||||
else:
|
||||
self.bambu_spool = False
|
||||
return cleaned
|
||||
Reference in new issue
Block a user