From 1596c642731e5839da942c7727bbc1fa8016fdee Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 27 Sep 2018 11:33:59 -0500 Subject: version 9 of stylesheet --- app/income/migrations/0005_invoice_slug.py | 19 +++++++++++++++ app/income/parser.py | 19 +++++++++++++++ app/income/views.py | 38 ++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 app/income/migrations/0005_invoice_slug.py create mode 100644 app/income/parser.py create mode 100644 app/income/views.py (limited to 'app/income') diff --git a/app/income/migrations/0005_invoice_slug.py b/app/income/migrations/0005_invoice_slug.py new file mode 100644 index 0000000..3b6dfb2 --- /dev/null +++ b/app/income/migrations/0005_invoice_slug.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.1 on 2018-09-03 19:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('income', '0004_invoice_invoiceitem'), + ] + + operations = [ + migrations.AddField( + model_name='invoice', + name='slug', + field=models.SlugField(default='slug'), + preserve_default=False, + ), + ] diff --git a/app/income/parser.py b/app/income/parser.py new file mode 100644 index 0000000..9524902 --- /dev/null +++ b/app/income/parser.py @@ -0,0 +1,19 @@ +with open('timesheet.csv', newline='') as csvfile: + reader = csv.reader(csvfile, delimiter=';') + counter = 0 + f = "%Y-%m-%d %H:%M:%S" + for row in reader: + if counter > 0: + timer = row[0]+' '+row[1] + timerer = row[0]+' '+row[2] + time_start = datetime.datetime.strptime(timer, f) + time_end = datetime.datetime.strptime(timerer, f) + print(row[4]) + print(timerer, time_end) + InvoiceItem.objects.get_or_create( + time_start=time_start, + time_end=time_end, + work_done=row[4] + ) + counter = counter +1 +f = "%Y-%m-%d %H:%M:%S" diff --git a/app/income/views.py b/app/income/views.py new file mode 100644 index 0000000..69ca1fd --- /dev/null +++ b/app/income/views.py @@ -0,0 +1,38 @@ +import datetime +from django.views.generic.detail import DetailView + +from templated_docs import fill_template +from templated_docs.http import FileResponse + +from .models import Invoice, InvoiceItem + + +class MonthlyInvoiceView(DetailView): + model = Invoice + template_name = "admin/income/monthly.html" + slug_field = "slug" + + def get_context_data(self, **kwargs): + context = super(MonthlyInvoiceView, self).get_context_data(**kwargs) + context['object_list'] = InvoiceItem.objects.filter(time_start__range=[self.object.date_start, self.object.date_end]) + total_time = [] + for item in context['object_list']: + total_time.append(item.rounded_total) + duration = (sum(total_time, datetime.timedelta())) + hours = duration.total_seconds() // 3600 + context['total_hours'] = hours + context['total_billed'] = int(hours * 100) + context['invoice_number'] = self.object.id+21 + return context + + +class DownloadMonthlyInvoiceView(MonthlyInvoiceView): + model = Invoice + slug_field = "slug" + + def get(self, *args, **kwargs): + self.object = self.get_object() # assign the object to the view + obj = self.get_context_data() + filename = fill_template('invoice.odt', obj, output_format='pdf') + visible_filename = 'invoice.{}'.format('pdf') + return FileResponse(filename, visible_filename) -- cgit v1.2.3-70-g09d2