Add JAYO and Anycubic filament starter catalogs
This commit is contained in:
1 parent
fbb7a5fc49
commit
e2ad117685
5 files changed
+6996
-3
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -3,11 +3,13 @@ from decimal import Decimal
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import transaction
|
||||
|
||||
from filament.anycubic_catalog import ANYCUBIC_CATALOG
|
||||
from filament.bambu_catalog import BAMBU_LAB_CATALOG, BAMBU_LAB_VARIANT_COUNT
|
||||
from filament.bambu_images_0006 import bambu_image_url
|
||||
from filament.bambu_petg_catalog import BAMBU_PETG_CATALOG
|
||||
from filament.bambu_swatches_0005 import BAMBU_SWATCHES
|
||||
from filament.esun_catalog import ESUN_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
|
||||
|
||||
@@ -15,10 +17,12 @@ BAMBU_LAB_BOOTSTRAP_KEY = "bambu-lab-eu-initial-catalog"
|
||||
BAMBU_PETG_BOOTSTRAP_KEY = "bambu-lab-eu-petg-basic-matte"
|
||||
SUNLU_BOOTSTRAP_KEY = "sunlu-de-initial-catalog"
|
||||
ESUN_BOOTSTRAP_KEY = "esun-eu-initial-catalog"
|
||||
JAYO_BOOTSTRAP_KEY = "jayo-eu-initial-catalog"
|
||||
ANYCUBIC_BOOTSTRAP_KEY = "anycubic-de-initial-catalog"
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Importiert die Erstkataloge von Bambu Lab, SUNLU und eSUN einmalig pro Datenbank."
|
||||
help = "Importiert die mitgelieferten Herstellerkataloge einmalig pro Datenbank."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.seed_bambu(options["verbosity"])
|
||||
@@ -29,6 +33,16 @@ class Command(BaseCommand):
|
||||
options["verbosity"], SUNLU_BOOTSTRAP_KEY, "SUNLU", SUNLU_CATALOG, sunlu_image_url
|
||||
)
|
||||
self.seed_catalog(options["verbosity"], ESUN_BOOTSTRAP_KEY, "eSUN", ESUN_CATALOG)
|
||||
self.seed_catalog(
|
||||
options["verbosity"], JAYO_BOOTSTRAP_KEY, "JAYO", JAYO_CATALOG, shopify_image_url
|
||||
)
|
||||
self.seed_catalog(
|
||||
options["verbosity"],
|
||||
ANYCUBIC_BOOTSTRAP_KEY,
|
||||
"Anycubic",
|
||||
ANYCUBIC_CATALOG,
|
||||
shopify_image_url,
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def seed_bambu(self, verbosity):
|
||||
@@ -107,3 +121,7 @@ class Command(BaseCommand):
|
||||
|
||||
def sunlu_image_url(path):
|
||||
return SUNLU_IMAGE_BASE + path + "?width=144" if path else ""
|
||||
|
||||
|
||||
def shopify_image_url(path):
|
||||
return "https://cdn.shopify.com/" + path if path else ""
|
||||
@@ -3,9 +3,11 @@ from django.core.management import call_command, get_commands
|
||||
from filament.bambu_catalog import BAMBU_LAB_PRODUCT_COUNT, BAMBU_LAB_VARIANT_COUNT
|
||||
from filament.forms import VariantSelectionForm
|
||||
from filament.management.commands.seed_catalog import (
|
||||
ANYCUBIC_BOOTSTRAP_KEY,
|
||||
BAMBU_LAB_BOOTSTRAP_KEY,
|
||||
BAMBU_PETG_BOOTSTRAP_KEY,
|
||||
ESUN_BOOTSTRAP_KEY,
|
||||
JAYO_BOOTSTRAP_KEY,
|
||||
SUNLU_BOOTSTRAP_KEY,
|
||||
)
|
||||
from filament.models import (
|
||||
@@ -431,3 +433,63 @@ class CatalogTests(CatalogTestCase):
|
||||
refill.delete()
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
self.assertFalse(variants.filter(manufacturer_color_code="30106").exists())
|
||||
|
||||
def test_jayo_and_anycubic_import_once_for_existing_installations(self):
|
||||
CatalogBootstrap.objects.bulk_create(
|
||||
CatalogBootstrap(key=key)
|
||||
for key in (
|
||||
BAMBU_LAB_BOOTSTRAP_KEY,
|
||||
BAMBU_PETG_BOOTSTRAP_KEY,
|
||||
SUNLU_BOOTSTRAP_KEY,
|
||||
ESUN_BOOTSTRAP_KEY,
|
||||
)
|
||||
)
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
for brand, key, count in (
|
||||
("JAYO", JAYO_BOOTSTRAP_KEY, 574),
|
||||
("Anycubic", ANYCUBIC_BOOTSTRAP_KEY, 266),
|
||||
):
|
||||
self.assertTrue(CatalogBootstrap.objects.filter(key=key).exists())
|
||||
self.assertEqual(
|
||||
Variant.objects.filter(product_type__manufacturer__name=brand).count(), count
|
||||
)
|
||||
|
||||
jayo = Variant.objects.filter(product_type__manufacturer__name="JAYO", color__name="Black")
|
||||
normal = jayo.get(product_type__name="PLA", spool_type="spool")
|
||||
reusable = jayo.get(product_type__name="PLA (Mehrwegspule)", spool_type="spool")
|
||||
refill = jayo.get(product_type__name="PLA", spool_type="refill")
|
||||
self.assertEqual(reusable.net_weight_g, 1100)
|
||||
self.assertEqual(refill.manufacturer_color_code, "DLZ-EU-JY-PLA-BK-1.1kg-N")
|
||||
self.assertEqual(jayo.get(product_type__name="PLA (5 kg)").net_weight_g, 5000)
|
||||
self.assertTrue(refill.image_url.startswith("https://cdn.shopify.com/"))
|
||||
|
||||
anycubic = Variant.objects.filter(
|
||||
product_type__manufacturer__name="Anycubic",
|
||||
product_type__name="PETG",
|
||||
color__name="Schwarz",
|
||||
)
|
||||
spool = anycubic.get(spool_type="spool")
|
||||
self.assertEqual(spool.swatch, "#212721")
|
||||
self.assertEqual(spool.net_weight_g, 1000)
|
||||
self.assertEqual(anycubic.get(spool_type="refill").manufacturer_color_code, "AHPEBK-A102")
|
||||
for url, variant in (
|
||||
("/bestand/hinzufuegen/", refill),
|
||||
("/bestellung/hinzufuegen/", spool),
|
||||
):
|
||||
response = self.client.post(
|
||||
url, {"action": "lookup", "article_number": variant.manufacturer_color_code}
|
||||
)
|
||||
self.assertEqual(response.context["form"].initial, self.selection(variant))
|
||||
self.assertRedirects(
|
||||
self.client.post(url, response.context["form"].initial),
|
||||
url.removesuffix("hinzufuegen/"),
|
||||
)
|
||||
|
||||
normal.delete()
|
||||
spool.is_active = False
|
||||
spool.save(update_fields=["is_active"])
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
self.assertFalse(jayo.filter(product_type__name="PLA", spool_type="spool").exists())
|
||||
spool.refresh_from_db()
|
||||
self.assertFalse(spool.is_active)
|
||||
self.assertEqual(Variant.objects.filter(product_type__manufacturer=self.maker).count(), 3)
|
||||
Reference in new issue
Block a user