mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Add basic account view for user and refactor user tool bar
This commit is contained in:
35
counter/migrations/0005_auto_20160717_1029.py
Normal file
35
counter/migrations/0005_auto_20160717_1029.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('counter', '0004_auto_20160717_0933'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='refilling',
|
||||
name='customer',
|
||||
field=models.ForeignKey(to='counter.Customer', related_name='refillings'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='refilling',
|
||||
name='operator',
|
||||
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='refillings_as_operator'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='selling',
|
||||
name='customer',
|
||||
field=models.ForeignKey(to='counter.Customer', related_name='sellings'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='selling',
|
||||
name='seller',
|
||||
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='sellings_as_operator'),
|
||||
),
|
||||
]
|
19
counter/migrations/0006_auto_20160717_1033.py
Normal file
19
counter/migrations/0006_auto_20160717_1033.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('counter', '0005_auto_20160717_1029'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='selling',
|
||||
name='customer',
|
||||
field=models.ForeignKey(to='counter.Customer', related_name='buyings'),
|
||||
),
|
||||
]
|
@ -119,8 +119,8 @@ class Refilling(models.Model):
|
||||
"""
|
||||
counter = models.ForeignKey(Counter, related_name="refillings", blank=False)
|
||||
amount = CurrencyField(_('amount'))
|
||||
operator = models.ForeignKey(User, related_name="refill_operators", blank=False)
|
||||
customer = models.ForeignKey(Customer, related_name="refill_customers", blank=False)
|
||||
operator = models.ForeignKey(User, related_name="refillings_as_operator", blank=False)
|
||||
customer = models.ForeignKey(Customer, related_name="refillings", blank=False)
|
||||
date = models.DateTimeField(_('date'), auto_now=True)
|
||||
payment_method = models.CharField(_('payment method'), max_length=255,
|
||||
choices=settings.SITH_COUNTER_PAYMENT_METHOD, default='cash')
|
||||
@ -147,8 +147,8 @@ class Selling(models.Model):
|
||||
counter = models.ForeignKey(Counter, related_name="sellings", blank=False)
|
||||
unit_price = CurrencyField(_('unit price'))
|
||||
quantity = models.IntegerField(_('quantity'))
|
||||
seller = models.ForeignKey(User, related_name="sellers", blank=False)
|
||||
customer = models.ForeignKey(Customer, related_name="customers", blank=False)
|
||||
seller = models.ForeignKey(User, related_name="sellings_as_operator", blank=False)
|
||||
customer = models.ForeignKey(Customer, related_name="buyings", blank=False)
|
||||
date = models.DateTimeField(_('date'), auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
|
16
counter/templates/counter/user_account.jinja
Normal file
16
counter/templates/counter/user_account.jinja
Normal file
@ -0,0 +1,16 @@
|
||||
{% extends "core/user_base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{{ profile.get_display_name() }}'s account
|
||||
{% endblock %}
|
||||
|
||||
{% block infos %}
|
||||
<h3>User account</h3>
|
||||
<p>{{ customer.refillings.all() }}</p>
|
||||
<p>{{ customer.buyings.all() }}</p>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ from django.http import HttpResponseRedirect
|
||||
from django.utils import timezone
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
import re
|
||||
|
||||
@ -345,4 +346,28 @@ class CounterDeleteView(CanEditMixin, DeleteView):
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
success_url = reverse_lazy('counter:admin_list')
|
||||
|
||||
# User accounting infos
|
||||
|
||||
class UserAccountView(DetailView):
|
||||
"""
|
||||
Display a user's account
|
||||
"""
|
||||
model = Customer
|
||||
pk_url_kwarg = "user_id"
|
||||
template_name = "counter/user_account.jinja"
|
||||
|
||||
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'])):
|
||||
return res
|
||||
raise PermissionDenied
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserAccountView, self).get_context_data(**kwargs)
|
||||
kwargs['profile'] = self.object.user
|
||||
# TODO: add list of month where account has activity
|
||||
return kwargs
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user