diff --git a/README.md b/README.md index d5bcff3..f9a4e0e 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Keine SPA, keine externen Schriften/Skripte, kein externer Datenbankserver. - Die Bestellhistorie zeigt die bestellten, eingetroffenen und übergebenen Positionen der Gruppe. Bestell- und Übergabezeitpunkte werden bei den jeweiligen Statuswechseln gespeichert. - Deaktivierte Varianten bleiben in vorhandenen Positionen sichtbar, sind nicht neu wählbar. -- Einmalig ladbare Startkataloge für Bambu Lab, SUNLU, eSUN, JAYO, Anycubic und Geeetech - sowie konsistentes SQLite-Online-Backup. +- Einmalig ladbare Startkataloge für Bambu Lab, SUNLU, eSUN, JAYO, Anycubic, Geeetech + und Sonstige sowie konsistentes SQLite-Online-Backup. Unter „Spule verbraucht“ lässt sich eine Rolle ausbuchen und optional ihre Katalogvariante in die Sammelbestellung übernehmen. Die Sammelbestellung ist eine Planungsliste. @@ -363,6 +363,11 @@ EU-Varianten aus 14 Shop-Produktreihen mit 1,75 mm Durchmesser und 1 kg pro Spul Im Katalog bilden die PLA-CF-Farben eine eigene Unterart. Alle Varianten haben eine Artikelnummer. Der Feed ordnet 166 Varianten ein Produktbild zu. Stand 14. November 2026. +**Sonstige** bietet PLA, ABS, PETG, ASA und TPU mit der Unterart **Standard**. +Alle neun Grundfarben stehen mit und ohne Spule zur Auswahl. Die Farbvorschauen sind +generisch. Artikelnummer, Nettogewicht und Durchmesser sind offen, und die App verwendet +den Platzhalter für Produktbilder. + Die Datenstände werden mit dem Programm ausgeliefert und beim Start nicht aus dem Shop nachgeladen. Der erste erfolgreiche Import wird je Hersteller in der Datenbank markiert. Spätere Aufrufe überspringen den Import vollständig, sodass lokale Löschungen, Deaktivierungen, Umbenennungen und Ergänzungen diff --git a/filament/generic_catalog.py b/filament/generic_catalog.py new file mode 100644 index 0000000..c604f4c --- /dev/null +++ b/filament/generic_catalog.py @@ -0,0 +1,23 @@ +"""Brand-neutral starter variants with illustrative color previews.""" + +MATERIALS = ("PLA", "ABS", "PETG", "ASA", "TPU") +COLORS = { + "Weiß": "#FFFFFF", + "Schwarz": "#222222", + "Grau": "#808080", + "Rot": "#D62828", + "Gelb": "#F4C430", + "Grün": "#228B22", + "Blau": "#2463BB", + "Orange": "#EF791D", + "Braun": "#805432", +} + +GENERIC_CATALOG = { + f"{material} Standard": tuple( + (color, spool_type, "", None, swatch, "") + for color, swatch in COLORS.items() + for spool_type in ("spool", "refill") + ) + for material in MATERIALS +} diff --git a/filament/management/commands/seed_catalog.py b/filament/management/commands/seed_catalog.py index 880b463..9efa2f1 100644 --- a/filament/management/commands/seed_catalog.py +++ b/filament/management/commands/seed_catalog.py @@ -11,6 +11,7 @@ from filament.bambu_pla_pure_catalog import BAMBU_PLA_PURE_CATALOG from filament.bambu_swatches_0005 import BAMBU_SWATCHES from filament.esun_catalog import ESUN_CATALOG from filament.geeetech_catalog import GEEETECH_CATALOG +from filament.generic_catalog import GENERIC_CATALOG from filament.jayo_catalog import JAYO_CATALOG from filament.models import CatalogBootstrap, Color, Manufacturer, ProductType, Variant from filament.sunlu_catalog import SUNLU_CATALOG, SUNLU_IMAGE_BASE @@ -23,6 +24,7 @@ ESUN_BOOTSTRAP_KEY = "esun-eu-initial-catalog" JAYO_BOOTSTRAP_KEY = "jayo-eu-initial-catalog" ANYCUBIC_BOOTSTRAP_KEY = "anycubic-de-initial-catalog" GEEETECH_BOOTSTRAP_KEY = "geeetech-eu-initial-catalog" +GENERIC_BOOTSTRAP_KEY = "generic-initial-catalog" class Command(BaseCommand): @@ -57,6 +59,13 @@ class Command(BaseCommand): GEEETECH_CATALOG, shopify_image_url, ) + self.seed_catalog( + options["verbosity"], + GENERIC_BOOTSTRAP_KEY, + "Sonstige", + GENERIC_CATALOG, + diameter_mm=None, + ) @transaction.atomic def seed_bambu(self, verbosity): @@ -103,7 +112,16 @@ class Command(BaseCommand): ) @transaction.atomic - def seed_catalog(self, verbosity, key, manufacturer_name, catalog, image_url=None): + def seed_catalog( + self, + verbosity, + key, + manufacturer_name, + catalog, + image_url=None, + *, + diameter_mm=Decimal("1.75"), + ): _, should_import = CatalogBootstrap.objects.get_or_create(key=key) if not should_import: return @@ -121,7 +139,7 @@ class Command(BaseCommand): defaults={ "manufacturer_color_code": sku, "net_weight_g": weight, - "diameter_mm": Decimal("1.75"), + "diameter_mm": diameter_mm, "swatch": swatch, "image_url": image_url(image_path) if image_url else image_path, }, diff --git a/filament/tests/test_catalog.py b/filament/tests/test_catalog.py index 882ba18..521df5d 100644 --- a/filament/tests/test_catalog.py +++ b/filament/tests/test_catalog.py @@ -9,6 +9,7 @@ from filament.management.commands.seed_catalog import ( BAMBU_PLA_PURE_BOOTSTRAP_KEY, ESUN_BOOTSTRAP_KEY, GEEETECH_BOOTSTRAP_KEY, + GENERIC_BOOTSTRAP_KEY, JAYO_BOOTSTRAP_KEY, SUNLU_BOOTSTRAP_KEY, ) @@ -625,3 +626,62 @@ class CatalogTests(CatalogTestCase): self.assertEqual(variants.count(), 169) spool.refresh_from_db() self.assertFalse(spool.is_active) + + def test_sonstige_catalog_imports_once_and_is_selectable_in_both_forms(self): + CatalogBootstrap.objects.bulk_create( + CatalogBootstrap(key=key) + for key in ( + ANYCUBIC_BOOTSTRAP_KEY, + BAMBU_LAB_BOOTSTRAP_KEY, + BAMBU_PETG_BOOTSTRAP_KEY, + BAMBU_PLA_PURE_BOOTSTRAP_KEY, + ESUN_BOOTSTRAP_KEY, + GEEETECH_BOOTSTRAP_KEY, + JAYO_BOOTSTRAP_KEY, + SUNLU_BOOTSTRAP_KEY, + ) + ) + call_command("seed_catalog", verbosity=0) + self.assertTrue(CatalogBootstrap.objects.filter(key=GENERIC_BOOTSTRAP_KEY).exists()) + maker = Manufacturer.objects.get(name="Sonstige") + variants = Variant.objects.filter(product_type__manufacturer=maker) + materials = {"PLA", "ABS", "PETG", "ASA", "TPU"} + colors = {"Weiß", "Schwarz", "Grau", "Rot", "Gelb", "Grün", "Blau", "Orange", "Braun"} + self.assertEqual( + set(variants.values_list("product_type__name", "color__name", "spool_type")), + { + (f"{material} Standard", color, spool_type) + for material in materials + for color in colors + for spool_type in ("spool", "refill") + }, + ) + self.assertFalse( + variants.exclude( + manufacturer_color_code="", net_weight_g=None, diameter_mm=None, image_url="" + ).exists() + ) + self.assertFalse(variants.filter(swatch="").exists()) + for url, model, spool_type in ( + ("/bestand/hinzufuegen/", InventoryItem, "spool"), + ("/bestellung/hinzufuegen/", OrderItem, "refill"), + ): + variant = variants.get( + product_type__name="ASA Standard", color__name="Grau", spool_type=spool_type + ) + data = self.selection(variant) + response = self.client.post(url, data | {"action": "filter"}) + form = response.context["form"] + self.assertEqual({key for key, _ in form.fields["material"].choices if key}, materials) + self.assertEqual( + [label for key, label in form.fields["product_type"].choices if key], ["Standard"] + ) + self.assertEqual(set(dict(form.fields["spool_type"].choices)), {"spool", "refill"}) + self.assertRedirects(self.client.post(url, data), url.removesuffix("hinzufuegen/")) + self.assertEqual(model.objects.get(owner=self.alice).variant, variant) + unused_variant = variants.get( + product_type__name="TPU Standard", color__name="Grün", spool_type="spool" + ) + unused_variant.delete() + call_command("seed_catalog", verbosity=0) + self.assertEqual(variants.count(), 89)