mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-25 17:21:15 +00:00
Improve and fix user accounts
This commit is contained in:
parent
05bd177a9d
commit
b69c3a6792
@ -1,10 +1,16 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Delete confirmation{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Delete confirmation{% endtrans %}</h2>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<p>{% trans obj=object %}Are you sure you want to delete "{{ obj }}"?{% endtrans %}</p>
|
||||
<input type="submit" value="{% trans %}Confirm{% endtrans %}" />
|
||||
</form>
|
||||
<form method="GET" action="javascript:history.back();">
|
||||
<input type="submit" name="cancel" value="{% trans %}Cancel{% endtrans %}" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -1,10 +1,16 @@
|
||||
{% extends "core/file.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Delete confirmation{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block file %}
|
||||
<h2>{% trans %}Delete confirmation{% endtrans %}</h2>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<p>{% trans obj=object %}Are you sure you want to delete "{{ obj }}"?{% endtrans %}</p>
|
||||
<input type="submit" value="{% trans %}Confirm{% endtrans %}" />
|
||||
</form>
|
||||
<form method="GET" action="javascript:history.back();">
|
||||
<input type="submit" name="cancel" value="{% trans %}Cancel{% endtrans %}" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -28,6 +28,9 @@
|
||||
<td><a href="{{ i.operator.get_absolute_url() }}">{{ i.operator.get_display_name() }}</a></td>
|
||||
<td>{{ i.amount }} €</td>
|
||||
<td>{{ i.get_payment_method_display() }}</td>
|
||||
{% if i.is_owned_by(user) %}
|
||||
<td><a href="{{ url('counter:refilling_delete', refilling_id=i.id) }}">Delete</a></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@ -57,6 +60,9 @@
|
||||
<td>{{ i.quantity }}</td>
|
||||
<td>{{ i.quantity * i.unit_price }} €</td>
|
||||
<td>{{ i.get_payment_method_display() }}</td>
|
||||
{% if i.is_owned_by(user) %}
|
||||
<td><a href="{{ url('counter:selling_delete', selling_id=i.id) }}">Delete</a></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -5,8 +5,7 @@ from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.forms import ValidationError
|
||||
|
||||
from datetime import timedelta, datetime
|
||||
from pytz import timezone
|
||||
from datetime import timedelta
|
||||
import random
|
||||
import string
|
||||
|
||||
@ -188,7 +187,7 @@ class Counter(models.Model):
|
||||
|
||||
def get_random_barman(self):
|
||||
bl = self.get_barmen_list()
|
||||
return bl[randrange(0, len(bl))]
|
||||
return bl[random.randrange(0, len(bl))]
|
||||
|
||||
def is_open(self):
|
||||
response = False
|
||||
@ -220,12 +219,20 @@ class Refilling(models.Model):
|
||||
def __str__(self):
|
||||
return "Refilling: %.2f for %s" % (self.amount, self.customer.user.get_display_name())
|
||||
|
||||
def is_owned_by(self, user):
|
||||
return user.can_edit(self.counter) and self.payment_method != "CARD"
|
||||
|
||||
# def get_absolute_url(self):
|
||||
# return reverse('counter:details', kwargs={'counter_id': self.id})
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.customer.amount -= self.amount
|
||||
self.customer.save()
|
||||
super(Refilling, self).delete(*args, **kwargs)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.date:
|
||||
self.date = datetime.now().replace(tzinfo=timezone(settings.TIME_ZONE))
|
||||
self.date = timezone.now()
|
||||
self.full_clean()
|
||||
if not self.is_validated:
|
||||
self.customer.amount += self.amount
|
||||
@ -257,9 +264,17 @@ class Selling(models.Model):
|
||||
return "Selling: %d x %s (%f) for %s" % (self.quantity, self.label,
|
||||
self.quantity*self.unit_price, self.customer.user.get_display_name())
|
||||
|
||||
def is_owned_by(self, user):
|
||||
return user.can_edit(self.counter) and self.payment_method != "CARD"
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.customer.amount += self.quantity * self.unit_price
|
||||
self.customer.save()
|
||||
super(Selling, self).delete(*args, **kwargs)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.date:
|
||||
self.date = datetime.now().replace(tzinfo=timezone(settings.TIME_ZONE))
|
||||
self.date = timezone.now()
|
||||
self.full_clean()
|
||||
if not self.is_validated:
|
||||
self.customer.amount -= self.quantity * self.unit_price
|
||||
|
@ -17,6 +17,8 @@ urlpatterns = [
|
||||
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'),
|
||||
url(r'^admin/selling/(?P<selling_id>[0-9]+)/delete$', SellingDeleteView.as_view(), name='selling_delete'),
|
||||
url(r'^admin/refilling/(?P<refilling_id>[0-9]+)/delete$', RefillingDeleteView.as_view(), name='refilling_delete'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -410,3 +410,26 @@ class ProductEditView(CanEditPropMixin, UpdateView):
|
||||
template_name = 'core/edit.jinja'
|
||||
# TODO: add management of the 'counters' ForeignKey
|
||||
|
||||
|
||||
class RefillingDeleteView(CanEditPropMixin, DeleteView):
|
||||
"""
|
||||
Delete a refilling (for the admins)
|
||||
"""
|
||||
model = Refilling
|
||||
pk_url_kwarg = "refilling_id"
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('core:user_account', kwargs={'user_id': self.object.customer.user.id})
|
||||
|
||||
class SellingDeleteView(CanEditPropMixin, DeleteView):
|
||||
"""
|
||||
Delete a selling (for the admins)
|
||||
"""
|
||||
model = Selling
|
||||
pk_url_kwarg = "selling_id"
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('core:user_account', kwargs={'user_id': self.object.customer.user.id})
|
||||
|
||||
|
14
migrate.py
14
migrate.py
@ -337,6 +337,15 @@ def migrate_counters():
|
||||
print("FAIL to migrate counter %s: %s" % (r['id_comptoir'], repr(e)))
|
||||
cur.close()
|
||||
|
||||
def reset_customer_amount():
|
||||
Refilling.objects.all().delete()
|
||||
Selling.objects.all().delete()
|
||||
Invoice.objects.all().delete()
|
||||
for c in Customer.objects.all():
|
||||
c.amount = 0
|
||||
c.save()
|
||||
print("Customer amount reset")
|
||||
|
||||
def migrate_refillings():
|
||||
BANK = {
|
||||
0: "OTHER",
|
||||
@ -359,10 +368,6 @@ def migrate_refillings():
|
||||
""")
|
||||
Refilling.objects.filter(payment_method="SITH_ACCOUNT").delete()
|
||||
print("Sith account refillings deleted")
|
||||
for c in Customer.objects.all():
|
||||
c.amount = 0
|
||||
c.save()
|
||||
print("Customer amount reset")
|
||||
fail = 100
|
||||
root_cust = Customer.objects.filter(user__id=0).first()
|
||||
mde = Counter.objects.filter(id=1).first()
|
||||
@ -546,6 +551,7 @@ def main():
|
||||
# migrate_typeproducts()
|
||||
# migrate_products()
|
||||
# migrate_products_to_counter()
|
||||
reset_customer_amount()
|
||||
migrate_invoices()
|
||||
migrate_refillings()
|
||||
migrate_sellings()
|
||||
|
Loading…
Reference in New Issue
Block a user