feat: implement Fil-A-Management Django MVP

This commit is contained in:
Jean-Luc Picode committed 2026-11-14 10:39:49 +01:00
commit 1127e7ecf4
66 files changed
+3774

No files matched your search

+158
View File
@@ -0,0 +1,158 @@
from django.conf import settings
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
class Manufacturer(models.Model):
name = models.CharField("Hersteller", max_length=100, unique=True)
class Meta:
ordering = ["name"]
verbose_name = "Hersteller"
verbose_name_plural = "Hersteller"
def __str__(self):
return self.name
class ProductType(models.Model):
manufacturer = models.ForeignKey(
Manufacturer, on_delete=models.PROTECT, verbose_name="Hersteller"
)
name = models.CharField("Produktart", max_length=100)
class Meta:
ordering = ["manufacturer__name", "name"]
constraints = [
models.UniqueConstraint(
fields=["manufacturer", "name"], name="unique_product_per_manufacturer"
)
]
verbose_name = "Produktart"
verbose_name_plural = "Produktarten"
def __str__(self):
return f"{self.manufacturer} · {self.name}"
class Color(models.Model):
name = models.CharField("Farbe", max_length=100, unique=True)
class Meta:
ordering = ["name"]
verbose_name = "Farbe"
verbose_name_plural = "Farben"
def __str__(self):
return self.name
class Variant(models.Model):
class SpoolType(models.TextChoices):
SPOOL = "spool", "Mit Spule"
REFILL = "refill", "Refill (ohne Spule)"
product_type = models.ForeignKey(
ProductType, on_delete=models.PROTECT, related_name="variants", verbose_name="Produktart"
)
color = models.ForeignKey(
Color, on_delete=models.PROTECT, related_name="variants", verbose_name="Farbe"
)
spool_type = models.CharField("Spulenausführung", max_length=10, choices=SpoolType.choices)
manufacturer_color_code = models.CharField("Hersteller-Farbcode", max_length=40, blank=True)
net_weight_g = models.PositiveIntegerField(
"Nettogewicht (g)", null=True, blank=True, validators=[MinValueValidator(1)]
)
diameter_mm = models.DecimalField(
"Durchmesser (mm)",
max_digits=4,
decimal_places=2,
null=True,
blank=True,
validators=[MinValueValidator(0.01)],
)
is_active = models.BooleanField("Aktiv", default=True)
class Meta:
ordering = [
"product_type__manufacturer__name",
"product_type__name",
"color__name",
"spool_type",
]
constraints = [
models.UniqueConstraint(
fields=["product_type", "color", "spool_type"], name="unique_catalog_variant"
),
models.CheckConstraint(
condition=models.Q(spool_type__in=["spool", "refill"]), name="valid_spool_type"
),
models.CheckConstraint(
condition=models.Q(net_weight_g__isnull=True) | models.Q(net_weight_g__gt=0),
name="positive_net_weight",
),
models.CheckConstraint(
condition=models.Q(diameter_mm__isnull=True) | models.Q(diameter_mm__gt=0),
name="positive_diameter",
),
]
verbose_name = "Filamentvariante"
verbose_name_plural = "Filamentvarianten"
@property
def manufacturer(self):
return self.product_type.manufacturer
def __str__(self):
return f"{self.product_type} · {self.color} · {self.get_spool_type_display()}"
class QuantityPosition(models.Model):
owner = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="Person"
)
variant = models.ForeignKey(Variant, on_delete=models.PROTECT, verbose_name="Filamentvariante")
quantity = models.PositiveIntegerField(
"Stückzahl", validators=[MinValueValidator(1), MaxValueValidator(9999)]
)
class Meta:
abstract = True
ordering = [
"variant__product_type__manufacturer__name",
"variant__product_type__name",
"variant__color__name",
"variant__spool_type",
]
constraints = [
models.UniqueConstraint(fields=["owner", "variant"], name="%(class)s_owner_variant"),
models.CheckConstraint(
condition=models.Q(quantity__gte=1, quantity__lte=9999),
name="%(class)s_quantity_range",
),
]
def __str__(self):
return f"{self.quantity} × {self.variant}"
class InventoryItem(QuantityPosition):
"""Aggregate per owner/variant; individual-roll consumption is reserved for v2."""
class OrderItem(QuantityPosition):
"""One request per person/variant for the next shared order."""
class Printer(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
manufacturer = models.CharField("Hersteller", max_length=100)
model = models.CharField("Modell", max_length=100)
name = models.CharField("Name (optional)", max_length=100, blank=True)
class Meta:
ordering = ["manufacturer", "model", "name"]
def __str__(self):
base = f"{self.manufacturer} {self.model}"
return f"{base} · {self.name}" if self.name else base