From b4113ef770a22b4859a268c5b19415258cf0b30d Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 29 Aug 2014 12:45:27 +0000 Subject: [PATCH] Added pdf rendering support --- .../management/commands/createinitialaccount.py | 9 +++------ orchestra/apps/bills/actions.py | 6 +++++- orchestra/apps/bills/models.py | 5 +++-- orchestra/apps/bills/settings.py | 6 +++++- .../bills/templates/bills/microspective-fee.html | 8 ++++++-- .../apps/bills/templates/bills/microspective.css | 15 +++++++++++---- .../apps/bills/templates/bills/microspective.html | 6 +++--- orchestra/apps/mails/admin.py | 3 ++- orchestra/apps/orders/models.py | 3 +++ orchestra/apps/payments/actions.py | 5 ++--- orchestra/apps/payments/admin.py | 4 ++-- orchestra/apps/payments/methods/__init__.py | 2 +- .../{banktransfer.py => sepadirectdebit.py} | 12 ++++++------ orchestra/apps/payments/models.py | 2 +- orchestra/bin/orchestra-admin | 7 ++++--- orchestra/utils/system.py | 9 ++++----- 16 files changed, 61 insertions(+), 41 deletions(-) rename orchestra/apps/payments/methods/{banktransfer.py => sepadirectdebit.py} (97%) diff --git a/orchestra/apps/accounts/management/commands/createinitialaccount.py b/orchestra/apps/accounts/management/commands/createinitialaccount.py index 135f7de8..5ebde3bb 100644 --- a/orchestra/apps/accounts/management/commands/createinitialaccount.py +++ b/orchestra/apps/accounts/management/commands/createinitialaccount.py @@ -28,9 +28,6 @@ class Command(BaseCommand): email = options.get('email') username = options.get('username') password = options.get('password') - user = User.objects.create_superuser(username, email, password, account=account, - is_main=True) - account = Account.objects.create(user=user) - user.account = account - user.save() - + account = Account.objects.create() + user = User.objects.create_superuser(username, email, password, + account=account, is_main=True) diff --git a/orchestra/apps/bills/actions.py b/orchestra/apps/bills/actions.py index ba471ce4..1e61b863 100644 --- a/orchestra/apps/bills/actions.py +++ b/orchestra/apps/bills/actions.py @@ -1,7 +1,11 @@ from django.http import HttpResponse +from orchestra.utils.system import run + def generate_bill(modeladmin, request, queryset): bill = queryset.get() bill.close() - return HttpResponse(bill.html) + pdf = run('xvfb-run -a -s "-screen 0 640x4800x16" wkhtmltopdf - -', + stdin=bill.html.encode('utf-8'), display=False) + return HttpResponse(pdf, content_type='application/pdf') diff --git a/orchestra/apps/bills/models.py b/orchestra/apps/bills/models.py index bce7b2d4..28c069b1 100644 --- a/orchestra/apps/bills/models.py +++ b/orchestra/apps/bills/models.py @@ -16,7 +16,7 @@ class BillManager(models.Manager): def get_queryset(self): queryset = super(BillManager, self).get_queryset() if self.model != Bill: - bill_type = self.model.get_type() + bill_type = self.model.get_class_type() queryset = queryset.filter(type=bill_type) return queryset @@ -127,7 +127,8 @@ class Bill(models.Model): }, 'currency': settings.BILLS_CURRENCY, }) - template = getattr(settings, 'BILLS_%s_TEMPLATE' % self.get_type()) + template = getattr(settings, 'BILLS_%s_TEMPLATE' % self.get_type(), + settings.BILLS_DEFAULT_TEMPLATE) bill_template = loader.get_template(template) html = bill_template.render(context) html = html.replace('-pageskip-', '') diff --git a/orchestra/apps/bills/settings.py b/orchestra/apps/bills/settings.py index b00c5935..a90bcb4c 100644 --- a/orchestra/apps/bills/settings.py +++ b/orchestra/apps/bills/settings.py @@ -14,7 +14,11 @@ BILLS_AMENDMENT_FEE_NUMBER_PREFIX = getattr(settings, 'BILLS_AMENDMENT_FEE_NUMBE BILLS_BUDGET_NUMBER_PREFIX = getattr(settings, 'BILLS_BUDGET_NUMBER_PREFIX', 'Q') -BILLS_INVOICE_TEMPLATE = getattr(settings, 'BILLS_INVOICE_TEMPLATE', 'bills/microspective.html') +BILLS_DEFAULT_TEMPLATE = getattr(settings, 'BILLS_DEFAULT_TEMPLATE', 'bills/microspective.html') + +BILLS_FEE_TEMPLATE = getattr(settings, 'BILLS_FEE_TEMPLATE', 'bills/microspective-fee.html') + + BILLS_CURRENCY = getattr(settings, 'BILLS_CURRENCY', 'euro') diff --git a/orchestra/apps/bills/templates/bills/microspective-fee.html b/orchestra/apps/bills/templates/bills/microspective-fee.html index da594219..7df25b5a 100644 --- a/orchestra/apps/bills/templates/bills/microspective-fee.html +++ b/orchestra/apps/bills/templates/bills/microspective-fee.html @@ -36,6 +36,7 @@ float: right; padding: 15px; margin: 10px; + margin-top: 0px; width: 44%; font-size: large; } @@ -84,7 +85,7 @@ hr { {% endblock %} {% block summary %} -
+

@@ -121,5 +122,8 @@ from Apr 1, 2010 to Apr 1, 2011 Con vuestras cuotas, ademas de obtener
{% endblock %} -{% block pagination %}
{% endblock %} +{% block footer %} +
+{{ block.super }} +{% endblock %} diff --git a/orchestra/apps/bills/templates/bills/microspective.css b/orchestra/apps/bills/templates/bills/microspective.css index 2a7e17e1..5fab4783 100644 --- a/orchestra/apps/bills/templates/bills/microspective.css +++ b/orchestra/apps/bills/templates/bills/microspective.css @@ -1,5 +1,6 @@ body { - max-width: 650px; +/* max-width: 650px;*/ + max-width: 800px; margin: 40 auto !important; float: none !important; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; @@ -48,14 +49,20 @@ a:hover { } /* SUMMARY */ +#bill-summary { + clear: right; +} #bill-summary > * { float: right; border: 1px solid grey; - padding: 7px; + padding: 7px 12px 7px 12px; text-align: center; font-size: large; width: 100px; + overflow: hidden; + white-space: nowrap; + } #bill-summary hr { @@ -161,12 +168,12 @@ a:hover { } #lines .column-description { - width: 55%; + width: 65%; text-align: left; } #lines .column-quantity { - width: 20%; + width: 10%; } #lines .column-rate { diff --git a/orchestra/apps/bills/templates/bills/microspective.html b/orchestra/apps/bills/templates/bills/microspective.html index ecbd0b20..9b10535a 100644 --- a/orchestra/apps/bills/templates/bills/microspective.html +++ b/orchestra/apps/bills/templates/bills/microspective.html @@ -12,7 +12,7 @@ {% block header %}