diff --git a/orchestra/admin/utils.py b/orchestra/admin/utils.py index b6e16e0f..c9d118eb 100644 --- a/orchestra/admin/utils.py +++ b/orchestra/admin/utils.py @@ -5,7 +5,7 @@ from functools import wraps from django.conf import settings from django.contrib import admin from django.core.exceptions import ObjectDoesNotExist -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, NoReverseMatch from django.db import models from django.shortcuts import redirect import importlib @@ -107,12 +107,16 @@ def admin_link(*args, **kwargs): return '---' if not getattr(obj, 'pk', None): return '---' - url = change_url(obj) display = kwargs.get('display') if display: display = getattr(obj, display, 'merda') else: display = obj + try: + url = change_url(obj) + except NoReverseMatch: + # Does not has admin + return str(display) extra = '' if kwargs['popup']: extra = 'onclick="return showAddAnotherPopup(this);"' diff --git a/orchestra/contrib/bills/actions.py b/orchestra/contrib/bills/actions.py index 592d3b53..a73789af 100644 --- a/orchestra/contrib/bills/actions.py +++ b/orchestra/contrib/bills/actions.py @@ -1,6 +1,6 @@ +import io import zipfile from datetime import date -from io import StringIO from django.contrib import messages from django.contrib.admin import helpers @@ -22,17 +22,17 @@ from .helpers import validate_contact def download_bills(modeladmin, request, queryset): if queryset.count() > 1: - stringio = StringIO() - archive = zipfile.ZipFile(stringio, 'w') + bytesio = io.BytesIO() + archive = zipfile.ZipFile(bytesio, 'w') for bill in queryset: - pdf = html_to_pdf(bill.html or bill.render()) + pdf = bill.as_pdf() archive.writestr('%s.pdf' % bill.number, pdf) archive.close() - response = HttpResponse(stringio.getvalue(), content_type='application/pdf') + response = HttpResponse(bytesio.getvalue(), content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="orchestra-bills.zip"' return response bill = queryset.get() - pdf = html_to_pdf(bill.html or bill.render(), pagination=bill.has_multiple_pages) + pdf = bill.as_pdf() return HttpResponse(pdf, content_type='application/pdf') download_bills.verbose_name = _("Download") download_bills.url_name = 'download' diff --git a/orchestra/contrib/bills/models.py b/orchestra/contrib/bills/models.py index 199c1d81..b0f9e2b9 100644 --- a/orchestra/contrib/bills/models.py +++ b/orchestra/contrib/bills/models.py @@ -136,7 +136,7 @@ class Bill(models.Model): if not self.is_open: return self.total try: - return self.computed_total + return round(self.computed_total, 2) except AttributeError: self.computed_total = self.compute_total() return self.computed_total @@ -199,8 +199,7 @@ class Bill(models.Model): return transaction def send(self): - html = self.html or self.render() - pdf = html_to_pdf(html, pagination=self.has_multiple_pages) + pdf = self.as_pdf() self.account.send_email( template=settings.BILLS_EMAIL_NOTIFICATION_TEMPLATE, context={ @@ -243,6 +242,10 @@ class Bill(models.Model): html = html.replace('-pageskip-', '') return html + def as_pdf(self): + html = self.html or self.render() + return html_to_pdf(html, pagination=self.has_multiple_pages) + def save(self, *args, **kwargs): if not self.type: self.type = self.get_type() diff --git a/orchestra/contrib/mailer/models.py b/orchestra/contrib/mailer/models.py index fb7217f6..e0e3c3b8 100644 --- a/orchestra/contrib/mailer/models.py +++ b/orchestra/contrib/mailer/models.py @@ -50,7 +50,7 @@ class Message(models.Model): def sent(self): self.state = self.SENT - self.save(update_fiields=('state',)) + self.save(update_fields=('state',)) def log(self, error): result = SMTPLog.SUCCESS diff --git a/orchestra/contrib/orchestration/admin.py b/orchestra/contrib/orchestration/admin.py index cac1404d..9a85e91a 100644 --- a/orchestra/contrib/orchestration/admin.py +++ b/orchestra/contrib/orchestration/admin.py @@ -109,7 +109,7 @@ class BackendOperationInline(admin.TabularInline): def instance_link(self, operation): link = admin_link('instance')(self, operation) - if not link.startswith(' + + Transaction Report + + + + + + + + + + + + + + + +{% for transaction in transactions %} + + + + + + + + + + +{% endfor %} +
ID{% trans "Bill" %}{% trans "Contact" %}IBAN{% trans "Amount" %}{% trans "State" %}{% trans "Created" %}{% trans "Updated" %}
{{ transaction.id }}{{ transaction.bill.number }}{{ transaction.bill.buyer.get_name }}{{ transaction.source.data.iban }}{{ transaction.amount }}{{ transaction.get_state_display }}{{ transaction.created_at|date }}{{ transaction.modified_at|date }}
+ +