modify accounting model
This commit is contained in:
parent
9f6477e5f1
commit
a8b9e7e61e
@ -27,4 +27,4 @@ class DeskAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(Accounting)
|
@admin.register(Accounting)
|
||||||
class AccountingAdmin(admin.ModelAdmin):
|
class AccountingAdmin(admin.ModelAdmin):
|
||||||
list_display = ('client', 'desk_no', 'time_from', 'time_to', 'prize')
|
list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed')
|
||||||
|
22
billard/migrations/0012_auto_20170211_1003.py
Normal file
22
billard/migrations/0012_auto_20170211_1003.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.5 on 2017-02-11 09:03
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('billard', '0011_auto_20170210_2122'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='accounting',
|
||||||
|
name='client',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Accounting',
|
||||||
|
),
|
||||||
|
]
|
32
billard/migrations/0013_accounting.py
Normal file
32
billard/migrations/0013_accounting.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.5 on 2017-02-11 09:03
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('billard', '0012_auto_20170211_1003'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Accounting',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('time_from', models.DateTimeField(verbose_name='Beginn')),
|
||||||
|
('time_to', models.DateTimeField(blank=True, null=True, verbose_name='Ende')),
|
||||||
|
('prize', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True, verbose_name='Preis')),
|
||||||
|
('billed', models.BooleanField(default=False, verbose_name='Abgerechnet')),
|
||||||
|
('desk', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billard.Desk', verbose_name='Tisch')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name_plural': 'Buchhaltungseinträge',
|
||||||
|
'verbose_name': 'Buchhaltungseintrag',
|
||||||
|
'ordering': ['-time_from'],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@ -84,14 +84,14 @@ class Desk(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Accounting(models.Model):
|
class Accounting(models.Model):
|
||||||
client = models.ForeignKey(Client, verbose_name="Client")
|
desk = models.ForeignKey(Desk, verbose_name="Tisch")
|
||||||
desk_no = models.IntegerField(verbose_name="Tischnummer")
|
|
||||||
time_from = models.DateTimeField(verbose_name="Beginn")
|
time_from = models.DateTimeField(verbose_name="Beginn")
|
||||||
time_to = models.DateTimeField(blank=True, null=True, verbose_name="Ende")
|
time_to = models.DateTimeField(blank=True, null=True, verbose_name="Ende")
|
||||||
prize = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis")
|
prize = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis")
|
||||||
|
billed = models.BooleanField(default=False, verbose_name="Abgerechnet")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}: {} -> {}, {}'.format(self.client.uuid, self.time_from, self.time_to, self.prize)
|
return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['-time_from']
|
ordering = ['-time_from']
|
||||||
@ -117,15 +117,14 @@ def process_location_data():
|
|||||||
else:
|
else:
|
||||||
cli = cli[0]
|
cli = cli[0]
|
||||||
desk = cli.desks.filter(desk_no=ld.desk_no)[0]
|
desk = cli.desks.filter(desk_no=ld.desk_no)[0]
|
||||||
ac = Accounting.objects.filter(client=cli, desk_no=ld.desk_no).order_by('time_from').reverse()
|
ac = desk.accounting_set.order_by('time_from').reverse()
|
||||||
if ld.on_off:
|
if ld.on_off:
|
||||||
if ac.count() > 0 and ac[0].time_to is None:
|
if ac.count() > 0 and ac[0].time_to is None:
|
||||||
ac[0].time_to = datetime.now()
|
ac[0].time_to = datetime.now()
|
||||||
ac[0].save()
|
ac[0].save()
|
||||||
# TODO Send error eMail to Admin
|
# TODO Send error eMail to Admin
|
||||||
acc = Accounting(
|
acc = Accounting(
|
||||||
client=cli,
|
desk=desk,
|
||||||
desk_no=ld.desk_no,
|
|
||||||
time_from=ld.tst,
|
time_from=ld.tst,
|
||||||
)
|
)
|
||||||
acc.save()
|
acc.save()
|
||||||
|
@ -17,12 +17,13 @@ def display_client(client, desk_no):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
alert = 'alert-success'
|
alert = 'alert-success'
|
||||||
acc = Accounting.objects.filter(client=client, desk_no=desk_no)[:3][::-1]
|
#acc = Accounting.objects.filter(client=client, desk_no=desk_no)[:3][::-1]
|
||||||
|
acc = desk.accounting_set.all()[:3][::-1]
|
||||||
if acc is not None and len(acc) > 0:
|
if acc is not None and len(acc) > 0:
|
||||||
a = acc[-1]
|
a = acc[-1]
|
||||||
if a.time_to is None:
|
if a.time_to is None:
|
||||||
alert = 'alert-info'
|
alert = 'alert-info'
|
||||||
prize = utils.get_prize_for(start=a.time_from, end=datetime.now(timezone.utc), pph=desk.prize)
|
prize = utils.get_prize_for(start=a.time_from, end=datetime.now(), pph=desk.prize)
|
||||||
prize = '{0:.2f}'.format(prize)
|
prize = '{0:.2f}'.format(prize)
|
||||||
if prize != a.prize:
|
if prize != a.prize:
|
||||||
a.prize = prize
|
a.prize = prize
|
||||||
@ -34,7 +35,7 @@ def display_client(client, desk_no):
|
|||||||
html += ' <table class="table">\n'
|
html += ' <table class="table">\n'
|
||||||
for a in acc:
|
for a in acc:
|
||||||
html += ' <tr>\n'
|
html += ' <tr>\n'
|
||||||
html += ' <td>{}</td>\n'.format(a.time_from)
|
html += ' <td>{}</td>\n'.format(a.time_from.strftime('%d.%m.%Y %H:%M:%S'))
|
||||||
html += ' <td>{}</td>\n'.format((a.time_to if a.time_to is not None else ''))
|
html += ' <td>{}</td>\n'.format((a.time_to if a.time_to is not None else ''))
|
||||||
html += ' <td style="text-align: center;">{}</td>\n'\
|
html += ' <td style="text-align: center;">{}</td>\n'\
|
||||||
.format((a.prize if a.prize is not None else ''))
|
.format((a.prize if a.prize is not None else ''))
|
||||||
|
@ -112,7 +112,7 @@ USE_I18N = True
|
|||||||
|
|
||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = False
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
||||||
|
Loading…
Reference in New Issue
Block a user