2023-04-06 11:08:42 +00:00
|
|
|
# -*- coding:utf-8 -*-
|
2017-04-25 14:17:04 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# Copyright 2023 © AE UTBM
|
|
|
|
# ae@utbm.fr / ae.info@utbm.fr
|
|
|
|
# All contributors are listed in the CONTRIBUTORS file.
|
2017-04-25 14:17:04 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
|
|
|
# https://ae.utbm.fr.
|
2017-04-25 14:17:04 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# You can find the whole source code at https://github.com/ae-utbm/sith3
|
2017-04-25 14:17:04 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE"
|
2017-04-25 14:17:04 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# PREVIOUSLY LICENSED UNDER THE MIT LICENSE,
|
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE.old
|
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE.old"
|
2017-04-25 14:17:04 +00:00
|
|
|
#
|
|
|
|
|
2024-06-24 11:07:36 +00:00
|
|
|
from django.conf import settings
|
2016-10-26 15:20:42 +00:00
|
|
|
from django.db import models
|
2019-10-06 11:28:56 +00:00
|
|
|
from django.urls import reverse
|
2024-06-24 11:07:36 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2016-11-09 16:49:19 +00:00
|
|
|
|
2016-11-13 23:38:33 +00:00
|
|
|
from counter.models import Counter, ProductType
|
2016-10-26 15:20:42 +00:00
|
|
|
|
2018-10-04 19:29:19 +00:00
|
|
|
|
2016-10-26 15:20:42 +00:00
|
|
|
class Stock(models.Model):
|
2017-04-25 06:57:07 +00:00
|
|
|
"""
|
|
|
|
The Stock class, this one is used to know how many products are left for a specific counter
|
|
|
|
"""
|
2018-10-04 19:29:19 +00:00
|
|
|
|
|
|
|
name = models.CharField(_("name"), max_length=64)
|
|
|
|
counter = models.OneToOneField(
|
2019-10-05 17:09:15 +00:00
|
|
|
Counter,
|
|
|
|
verbose_name=_("counter"),
|
|
|
|
related_name="stock",
|
|
|
|
on_delete=models.CASCADE,
|
2018-10-04 19:29:19 +00:00
|
|
|
)
|
2016-10-31 07:19:46 +00:00
|
|
|
|
2017-04-25 06:57:07 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "%s (%s)" % (self.name, self.counter)
|
2016-10-26 20:12:56 +00:00
|
|
|
|
2017-04-25 06:57:07 +00:00
|
|
|
def get_absolute_url(self):
|
2018-10-04 19:29:19 +00:00
|
|
|
return reverse("stock:list")
|
2016-11-09 16:49:19 +00:00
|
|
|
|
2017-04-25 06:57:07 +00:00
|
|
|
def can_be_viewed_by(self, user):
|
2023-05-02 10:36:59 +00:00
|
|
|
return user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
2017-01-04 23:52:27 +00:00
|
|
|
|
2018-10-04 19:29:19 +00:00
|
|
|
|
2016-10-26 20:12:56 +00:00
|
|
|
class StockItem(models.Model):
|
2017-04-25 06:57:07 +00:00
|
|
|
"""
|
|
|
|
The StockItem class, element of the stock
|
|
|
|
"""
|
2018-10-04 19:29:19 +00:00
|
|
|
|
|
|
|
name = models.CharField(_("name"), max_length=64)
|
|
|
|
unit_quantity = models.IntegerField(
|
|
|
|
_("unit quantity"), default=0, help_text=_("number of element in one box")
|
|
|
|
)
|
|
|
|
effective_quantity = models.IntegerField(
|
|
|
|
_("effective quantity"), default=0, help_text=_("number of box")
|
|
|
|
)
|
|
|
|
minimal_quantity = models.IntegerField(
|
|
|
|
_("minimal quantity"),
|
|
|
|
default=1,
|
|
|
|
help_text=_(
|
|
|
|
"if the effective quantity is less than the minimal, item is added to the shopping list"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
type = models.ForeignKey(
|
|
|
|
ProductType,
|
|
|
|
related_name="stock_items",
|
|
|
|
verbose_name=_("type"),
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
)
|
2019-10-05 17:05:56 +00:00
|
|
|
stock_owner = models.ForeignKey(
|
|
|
|
Stock, related_name="items", on_delete=models.CASCADE
|
|
|
|
)
|
2017-04-25 06:57:07 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s" % (self.name)
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2018-10-04 19:29:19 +00:00
|
|
|
return reverse("stock:items_list", kwargs={"stock_id": self.stock_owner.id})
|
2017-04-25 06:57:07 +00:00
|
|
|
|
|
|
|
def can_be_viewed_by(self, user):
|
2023-05-02 10:36:59 +00:00
|
|
|
return user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
2017-01-04 23:52:27 +00:00
|
|
|
|
2018-10-04 19:29:19 +00:00
|
|
|
|
2016-12-28 18:25:43 +00:00
|
|
|
class ShoppingList(models.Model):
|
2017-04-25 06:57:07 +00:00
|
|
|
"""
|
|
|
|
The ShoppingList class, used to make an history of the shopping lists
|
|
|
|
"""
|
2018-10-04 19:29:19 +00:00
|
|
|
|
|
|
|
date = models.DateTimeField(_("date"))
|
|
|
|
name = models.CharField(_("name"), max_length=64)
|
|
|
|
todo = models.BooleanField(_("todo"))
|
|
|
|
comment = models.TextField(_("comment"), null=True, blank=True)
|
2019-10-05 17:05:56 +00:00
|
|
|
stock_owner = models.ForeignKey(
|
|
|
|
Stock, null=True, related_name="shopping_lists", on_delete=models.CASCADE
|
|
|
|
)
|
2016-11-13 23:38:33 +00:00
|
|
|
|
2017-04-25 06:57:07 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "%s (%s)" % (self.name, self.date)
|
2016-10-26 20:12:56 +00:00
|
|
|
|
2017-04-25 06:57:07 +00:00
|
|
|
def get_absolute_url(self):
|
2018-10-04 19:29:19 +00:00
|
|
|
return reverse("stock:shoppinglist_list")
|
2017-01-04 23:52:27 +00:00
|
|
|
|
2017-04-25 06:57:07 +00:00
|
|
|
def can_be_viewed_by(self, user):
|
2023-05-02 10:36:59 +00:00
|
|
|
return user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
2017-01-07 10:17:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ShoppingListItem(models.Model):
|
2020-08-27 13:59:42 +00:00
|
|
|
""""""
|
2018-10-04 19:29:19 +00:00
|
|
|
|
|
|
|
shopping_lists = models.ManyToManyField(
|
|
|
|
ShoppingList,
|
|
|
|
verbose_name=_("shopping lists"),
|
|
|
|
related_name="shopping_items_to_buy",
|
|
|
|
)
|
|
|
|
stockitem_owner = models.ForeignKey(
|
2019-10-05 17:05:56 +00:00
|
|
|
StockItem, related_name="shopping_item", null=True, on_delete=models.CASCADE
|
2018-10-04 19:29:19 +00:00
|
|
|
)
|
|
|
|
name = models.CharField(_("name"), max_length=64)
|
|
|
|
type = models.ForeignKey(
|
|
|
|
ProductType,
|
|
|
|
related_name="shoppinglist_items",
|
|
|
|
verbose_name=_("type"),
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
)
|
|
|
|
tobuy_quantity = models.IntegerField(
|
|
|
|
_("quantity to buy"),
|
|
|
|
default=6,
|
|
|
|
help_text=_("quantity to buy during the next shopping session"),
|
|
|
|
)
|
|
|
|
bought_quantity = models.IntegerField(
|
|
|
|
_("quantity bought"),
|
|
|
|
default=0,
|
|
|
|
help_text=_("quantity bought during the last shopping session"),
|
|
|
|
)
|
2017-04-25 06:57:07 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s - %s" % (self.name, self.shopping_lists.first())
|
|
|
|
|
|
|
|
def can_be_viewed_by(self, user):
|
2023-05-02 10:36:59 +00:00
|
|
|
return user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
2017-04-25 06:57:07 +00:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2018-10-04 19:29:19 +00:00
|
|
|
return reverse("stock:shoppinglist_list")
|