mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 20:09:25 +00:00
Add product type management views
This commit is contained in:
@ -39,6 +39,9 @@ class ProductType(models.Model):
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
icon = models.ImageField(upload_to='products', null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('product type')
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
@ -50,6 +53,9 @@ class ProductType(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('counter:producttype_list')
|
||||
|
||||
class Product(models.Model):
|
||||
"""
|
||||
This describes a product, with all its related informations
|
||||
@ -64,6 +70,9 @@ class Product(models.Model):
|
||||
icon = models.ImageField(upload_to='products', null=True, blank=True)
|
||||
club = models.ForeignKey(Club, related_name="products")
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('product')
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
@ -89,6 +98,9 @@ class Counter(models.Model):
|
||||
view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
|
||||
barmen_session = {}
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('counter')
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name == "owner_group":
|
||||
return Group.objects.filter(name=self.club.unix_name+settings.SITH_BOARD_SUFFIX).first()
|
||||
@ -173,6 +185,9 @@ class Refilling(models.Model):
|
||||
bank = models.CharField(_('bank'), max_length=255,
|
||||
choices=settings.SITH_COUNTER_BANK, default='other')
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("refilling")
|
||||
|
||||
def __str__(self):
|
||||
return "Refilling: %.2f for %s" % (self.amount, self.customer.user.get_display_name())
|
||||
|
||||
@ -197,6 +212,9 @@ class Selling(models.Model):
|
||||
customer = models.ForeignKey(Customer, related_name="buyings", blank=False)
|
||||
date = models.DateTimeField(_('date'), auto_now=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("selling")
|
||||
|
||||
def __str__(self):
|
||||
return "Selling: %d x %s (%f) for %s" % (self.quantity, self.product.name,
|
||||
self.quantity*self.unit_price, self.customer.user.get_display_name())
|
||||
@ -219,14 +237,11 @@ class Permanency(models.Model):
|
||||
start = models.DateTimeField(_('start date'))
|
||||
end = models.DateTimeField(_('end date'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("permanency")
|
||||
|
||||
def __str__(self):
|
||||
return "%s in %s from %s to %s" % (self.user, self.counter,
|
||||
self.start.strftime("%Y-%m-%d %H:%M:%S"), self.end.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
|
||||
|
||||
# TODO:
|
||||
# une classe Vente
|
||||
# foreign key vers comptoir, vendeur, client, produit, mais stocker le prix du produit, pour gerer les maj de prix
|
||||
# une classe Rechargement
|
||||
# foreign key vers comptoir, vendeur, client, plus montant
|
||||
|
||||
|
24
counter/templates/counter/producttype_list.jinja
Normal file
24
counter/templates/counter/producttype_list.jinja
Normal file
@ -0,0 +1,24 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Product type list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p><a href="{{ url('counter:new_producttype') }}">{% trans %}New product type{% endtrans %}</a></p>
|
||||
{% if producttype_list %}
|
||||
<h3>{% trans %}Product type list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for t in producttype_list %}
|
||||
<li><a href="{{ url('counter:producttype_edit', type_id=t.id) }}">{{ t }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no product types in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -14,6 +14,9 @@ urlpatterns = [
|
||||
url(r'^admin/product/list$', ProductListView.as_view(), name='product_list'),
|
||||
url(r'^admin/product/create$', ProductCreateView.as_view(), name='new_product'),
|
||||
url(r'^admin/product/(?P<product_id>[0-9]+)$', ProductEditView.as_view(), name='product_edit'),
|
||||
url(r'^admin/producttype/list$', ProductTypeListView.as_view(), name='producttype_list'),
|
||||
url(r'^admin/producttype/create$', ProductTypeCreateView.as_view(), name='new_producttype'),
|
||||
url(r'^admin/producttype/(?P<type_id>[0-9]+)$', ProductTypeEditView.as_view(), name='producttype_edit'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ import re
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
from subscription.models import Subscriber
|
||||
from counter.models import Counter, Customer, Product, Selling, Refilling
|
||||
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType
|
||||
|
||||
class GetUserForm(forms.Form):
|
||||
"""
|
||||
@ -42,7 +42,7 @@ class GetUserForm(forms.Form):
|
||||
elif cleaned_data['id'] is not None:
|
||||
user = Customer.objects.filter(user=cleaned_data['id']).first()
|
||||
if user is None:
|
||||
raise forms.ValidationError("User not found")
|
||||
raise forms.ValidationError(_("User not found"))
|
||||
cleaned_data['user_id'] = user.user.id
|
||||
return cleaned_data
|
||||
|
||||
@ -69,7 +69,6 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
|
||||
if self.request.method == 'POST':
|
||||
self.object = self.get_object()
|
||||
kwargs = super(CounterMain, self).get_context_data(**kwargs)
|
||||
# TODO: make some checks on the counter type, in order not to make the AuthenticationForm if there is no need to
|
||||
kwargs['login_form'] = AuthenticationForm()
|
||||
kwargs['login_form'].fields['username'].widget.attrs['autofocus'] = True
|
||||
kwargs['form'] = self.get_form()
|
||||
@ -353,6 +352,30 @@ class CounterDeleteView(CanEditMixin, DeleteView):
|
||||
|
||||
# Product management
|
||||
|
||||
class ProductTypeListView(ListView):
|
||||
"""
|
||||
A list view for the admins
|
||||
"""
|
||||
model = ProductType
|
||||
template_name = 'counter/producttype_list.jinja'
|
||||
|
||||
class ProductTypeCreateView(CreateView):
|
||||
"""
|
||||
A create view for the admins
|
||||
"""
|
||||
model = ProductType
|
||||
fields = ['name', 'description', 'icon']
|
||||
template_name = 'core/create.jinja'
|
||||
|
||||
class ProductTypeEditView(UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
model = ProductType
|
||||
template_name = 'core/edit.jinja'
|
||||
fields = ['name', 'description', 'icon']
|
||||
pk_url_kwarg = "type_id"
|
||||
|
||||
class ProductListView(ListView):
|
||||
"""
|
||||
A list view for the admins
|
||||
@ -365,15 +388,17 @@ class ProductCreateView(CreateView):
|
||||
A create view for the admins
|
||||
"""
|
||||
model = Product
|
||||
template_name = 'core/edit.jinja'
|
||||
fields = ['name', 'description', 'product_type', 'code', 'purchase_price',
|
||||
'selling_price', 'special_selling_price', 'icon', 'club']
|
||||
template_name = 'core/create.jinja'
|
||||
|
||||
class ProductEditView(UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
model = Product
|
||||
form_class = modelform_factory(Product, fields=['name', 'description', 'product_type', 'code', 'purchase_price',
|
||||
'selling_price', 'special_selling_price', 'icon', 'club'])
|
||||
fields = ['name', 'description', 'product_type', 'code', 'purchase_price',
|
||||
'selling_price', 'special_selling_price', 'icon', 'club']
|
||||
pk_url_kwarg = "product_id"
|
||||
template_name = 'core/edit.jinja'
|
||||
# TODO: add management of the 'counters' ForeignKey
|
||||
@ -391,8 +416,8 @@ class UserAccountView(DetailView):
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
|
||||
if (self.object.user == request.user
|
||||
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
|
||||
or request.user.is_in_group(settings.SITH_GROUPS['root']['name'])):
|
||||
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
|
||||
or request.user.is_in_group(settings.SITH_GROUPS['root']['name'])):
|
||||
return res
|
||||
raise PermissionDenied
|
||||
|
||||
|
Reference in New Issue
Block a user