feat: custom through model for Counter.sellers

This commit is contained in:
imperosol
2026-03-04 16:40:41 +01:00
parent be1563f46f
commit 1701ab5f33
2 changed files with 95 additions and 1 deletions

View File

@@ -551,7 +551,11 @@ class Counter(models.Model):
choices=[("BAR", _("Bar")), ("OFFICE", _("Office")), ("EBOUTIC", _("Eboutic"))],
)
sellers = models.ManyToManyField(
User, verbose_name=_("sellers"), related_name="counters", blank=True
User,
verbose_name=_("sellers"),
related_name="counters",
blank=True,
through="CounterSellers",
)
edit_groups = models.ManyToManyField(
Group, related_name="editable_counters", blank=True
@@ -743,6 +747,23 @@ class Counter(models.Model):
]
class CounterSellers(models.Model):
counter = models.ForeignKey(Counter, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
class Meta:
verbose_name = _("counter seller")
constraints = [
models.UniqueConstraint(
fields=["counter", "user"],
name="counter_counter_sellers_counter_id_subscriber_id_key",
)
]
def __str__(self):
return f"counter {self.counter_id} - user {self.user_id}"
class RefillingQuerySet(models.QuerySet):
def annotate_total(self) -> Self:
"""Annotate the Queryset with the total amount.