示例#1
0
文件: admin.py 项目: synasius/assopy
 def _invoice(self, i):
     fake = not i.payment_date
     if settings.GENRO_BACKEND:
         view = genro.invoice_url(i.assopy_id)
         download = view
     else:
         view = urlresolvers.reverse('assopy-invoice-html', kwargs={'order_code': i.order.code, 'code': i.code})
         download = urlresolvers.reverse('assopy-invoice-pdf', kwargs={'order_code': i.order.code, 'code': i.code})
     return '<a href="%s">View</a> - <a href="%s">Download</a> %s' % (view, download, '[Not payed]' if fake else '')
示例#2
0
 def _invoice(self, i):
     fake = not i.payment_date
     if settings.GENRO_BACKEND:
         view = genro.invoice_url(i.assopy_id)
         download = view
     else:
         view = urlresolvers.reverse('assopy-invoice-html',
                                     kwargs={
                                         'order_code': i.order.code,
                                         'code': i.code
                                     })
         download = urlresolvers.reverse('assopy-invoice-pdf',
                                         kwargs={
                                             'order_code': i.order.code,
                                             'code': i.code
                                         })
     return '<a href="%s">View</a> - <a href="%s">Download</a> %s' % (
         view, download, '[Not payed]' if fake else '')
示例#3
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
示例#4
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
示例#5
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
示例#6
0
文件: views.py 项目: yakky/assopy
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