2016-10-26 15:20:42 +00:00
|
|
|
from django.db import models
|
2016-10-31 07:19:46 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-11-09 16:49:19 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
|
2016-11-13 23:38:33 +00:00
|
|
|
from counter.models import Counter, ProductType
|
2016-10-26 15:20:42 +00:00
|
|
|
|
|
|
|
class Stock(models.Model):
|
2016-11-13 23:38:33 +00:00
|
|
|
"""
|
|
|
|
The Stock class, this one is used to know how many products are left for a specific counter
|
|
|
|
"""
|
2016-10-26 15:20:42 +00:00
|
|
|
name = models.CharField(_('name'), max_length=64)
|
|
|
|
counter = models.OneToOneField(Counter, verbose_name=_('counter'), related_name='stock')
|
2016-10-31 07:19:46 +00:00
|
|
|
|
2016-10-26 15:20:42 +00:00
|
|
|
def __str__(self):
|
2016-10-31 07:19:46 +00:00
|
|
|
return "%s (%s)" % (self.name, self.counter)
|
2016-10-26 20:12:56 +00:00
|
|
|
|
2016-11-09 16:49:19 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse('stock:list')
|
|
|
|
|
2016-10-26 20:12:56 +00:00
|
|
|
class StockItem(models.Model):
|
2016-11-13 23:38:33 +00:00
|
|
|
"""
|
|
|
|
The StockItem class, element of the stock
|
|
|
|
"""
|
2016-10-26 20:12:56 +00:00
|
|
|
name = models.CharField(_('name'), max_length=64)
|
2016-11-16 16:17:17 +00:00
|
|
|
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')
|
|
|
|
type = models.ForeignKey(ProductType, related_name="stock_items", verbose_name=_("type"), null=True, blank=True,
|
2016-11-13 23:38:33 +00:00
|
|
|
on_delete=models.SET_NULL)
|
2016-11-16 16:17:17 +00:00
|
|
|
stock_owner = models.ForeignKey(Stock, related_name="items")
|
2016-10-26 20:12:56 +00:00
|
|
|
|
2016-11-13 23:38:33 +00:00
|
|
|
|
2016-10-26 20:12:56 +00:00
|
|
|
def __str__(self):
|
2016-11-16 16:17:17 +00:00
|
|
|
return "%s (%s)" % (self.name, self.effective_quantity)
|
2016-10-26 20:12:56 +00:00
|
|
|
|
2016-11-16 16:17:17 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse('stock:items_list', kwargs={'stock_id':self.stock_owner.id})
|