Commit 80f72df1 authored by Skia's avatar Skia

Add product type management views

parent f230fbc1
Pipeline #74 failed with stage
in 1 minute and 54 seconds
{% extends "core/base.jinja" %}
{% block content %}
<h2>{% trans %}Create{% endtrans %}</h2>
<h2>{% trans name=form.instance.__class__._meta.verbose_name %}Create {{ name }}{% endtrans %}</h2>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p() }}
......
......@@ -14,7 +14,7 @@
{% else %}
<li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}">{{ r.revision }}</a> -
{{ user_profile_link(r.author) }} -
{{ page.revisions.last().date|localtime|date(DATETIME_FORMAT) }} {{ page.revisions.last().date|localtime|time(DATETIME_FORMAT) }}</a></li>
{{ r.date|localtime|date(DATETIME_FORMAT) }} {{ r.date|localtime|time(DATETIME_FORMAT) }}</a></li>
{% endif %}
{% endfor %}
</ul>
......
......@@ -23,7 +23,8 @@
<ul>
{% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li>
<li><a href="{{ url('counter:product_list') }}">{% trans %}General products management{% endtrans %}</a></li>
<li><a href="{{ url('counter:product_list') }}">{% trans %}Products management{% endtrans %}</a></li>
<li><a href="{{ url('counter:producttype_list') }}">{% trans %}Products type management{% endtrans %}</a></li>
{% endif %}
{% for b in settings.SITH_COUNTER_BARS %}
{% if user.is_in_group(b[1]+" admin") %}
......
......@@ -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
{% 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
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment