Example #1
0
def genro_invoice_pdf(request, assopy_id):
    import urllib
    from assopy.clients import genro
    from assopy.models import OrderItem

    data = genro.invoice(assopy_id)

    conferences = OrderItem.objects\
        .filter(order__assopy_id=data['order_id'])\
        .values_list('ticket__fare__conference', flat=True)\
        .distinct()

    try:
        conference = filter(None, conferences)[0]
    except IndexError:
        raise http.Http404()

    fname = '[%s] invoice.pdf' % (conference,)
    f = urllib.urlopen(genro.invoice_url(assopy_id))
    response = http.HttpResponse(f, mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="%s"' % fname
    return response
Example #2
0
def genro_invoice_pdf(request, assopy_id):
    import urllib
    from assopy.clients import genro
    from assopy.models import OrderItem

    data = genro.invoice(assopy_id)

    conferences = OrderItem.objects\
        .filter(order__assopy_id=data['order_id'])\
        .values_list('ticket__fare__conference', flat=True)\
        .distinct()

    try:
        conference = filter(None, conferences)[0]
    except IndexError:
        raise http.Http404()

    fname = '[%s] invoice.pdf' % (conference, )
    f = urllib.urlopen(genro.invoice_url(assopy_id))
    response = http.HttpResponse(f, mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="%s"' % fname
    return response
Example #3
0
def invoice(request, order_code, code, mode='html'):
    if not request.user.is_staff:
        userfilter = {
            'order__user__user': request.user,
        }
    else:
        userfilter = {}
    invoice = get_object_or_404(
        models.Invoice,
        code=unquote(code),
        order__code=unquote(order_code),
        **userfilter
    )
    if mode == 'html':
        order = invoice.order
        address = '%s, %s' % (order.address, unicode(order.country))
        ctx = {
            'document': ('Fattura N.', 'Invoice N.'),
            'title': unicode(invoice),
            'code': invoice.code,
            'emit_date': invoice.emit_date,
            'order': {
                'card_name': order.card_name,
                'address': address,
                'billing_notes': order.billing_notes,
                'cf_code': order.cf_code,
                'vat_number': order.vat_number,
            },
            'items': invoice.invoice_items(),
            'note': invoice.note,
            'price': {
                'net': invoice.net_price(),
                'vat': invoice.vat_value(),
                'total': invoice.price,
            },
            'vat': invoice.vat,
            'real': settings.IS_REAL_INVOICE(invoice.code),
        }
        return render_to_response('assopy/invoice.html', ctx, RequestContext(request))
    else:
        if settings.GENRO_BACKEND:
            assopy_id = invoice.assopy_id
            data = genro.invoice(assopy_id)
            if data.get('credit_note'):
                order = get_object_or_404(models.Order, invoices__credit_notes__assopy_id=assopy_id)
            else:
                order = get_object_or_404(models.Order, assopy_id=data['order_id'])
            raw = urllib.urlopen(genro.invoice_url(assopy_id))
        else:
            hurl = reverse('assopy-invoice-html', args=(order_code, code))
            if not settings.WKHTMLTOPDF_PATH:
                return HttpResponseRedirectSeeOther(hurl)
            raw = _pdf(request, hurl)
            order = invoice.order

        from conference.models import Conference
        try:
            conf = Conference.objects\
                .get(conference_start__year=order.created.year).code
        except Conference.DoesNotExist:
            conf = order.created.year
        fname = '[%s invoice] %s.pdf' % (conf, invoice.code.replace('/', '-'))

        response = http.HttpResponse(raw, mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="%s"' % fname
        return response
Example #4
0
def invoice(request, order_code, code, mode='html'):
    if not request.user.is_staff:
        userfilter = {
            'order__user__user': request.user,
        }
    else:
        userfilter = {}
    invoice = get_object_or_404(
        models.Invoice,
        code=unquote(code),
        order__code=unquote(order_code),
        **userfilter
    )
    if mode == 'html':
        order = invoice.order
        address = '%s, %s' % (order.address, unicode(order.country))
        ctx = {
            'document': ('Fattura N.', 'Invoice N.'),
            'title': unicode(invoice),
            'code': invoice.code,
            'emit_date': invoice.emit_date,
            'order': {
                'card_name': order.card_name,
                'address': address,
                'billing_notes': order.billing_notes,
                'cf_code': order.cf_code,
                'vat_number': order.vat_number,
            },
            'items': invoice.invoice_items(),
            'note': invoice.note,
            'price': {
                'net': invoice.net_price(),
                'vat': invoice.vat_value(),
                'total': invoice.price,
            },
            'vat': invoice.vat,
            'real': settings.IS_REAL_INVOICE(invoice.code),
        }
        return render_to_response('assopy/invoice.html', ctx, RequestContext(request))
    else:
        if settings.GENRO_BACKEND:
            assopy_id = invoice.assopy_id
            data = genro.invoice(assopy_id)
            if data.get('credit_note'):
                order = get_object_or_404(models.Order, invoices__credit_notes__assopy_id=assopy_id)
            else:
                order = get_object_or_404(models.Order, assopy_id=data['order_id'])
            raw = urllib.urlopen(genro.invoice_url(assopy_id))
        else:
            hurl = reverse('assopy-invoice-html', args=(order_code, code))
            if not settings.WKHTMLTOPDF_PATH:
                return HttpResponseRedirectSeeOther(hurl)
            raw = _pdf(request, hurl)
            order = invoice.order

        from conference.models import Conference
        try:
            conf = Conference.objects\
                .get(conference_start__year=order.created.year).code
        except Conference.DoesNotExist:
            conf = order.created.year
        fname = '[%s invoice] %s.pdf' % (conf, invoice.code.replace('/', '-'))

        response = http.HttpResponse(raw, mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="%s"' % fname
        return response