lingo remote regie draft
This commit is contained in:
parent
32dc372d82
commit
3013665bc3
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
('data', '0009_auto_20150529_2247'),
|
||||
('lingo', '0007_lingobasketlinkcell'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='LingoRemoteRegie',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('placeholder', models.CharField(max_length=20)),
|
||||
('order', models.PositiveIntegerField()),
|
||||
('slug', models.SlugField(verbose_name='Slug', blank=True)),
|
||||
('public', models.BooleanField(default=True, verbose_name='Public')),
|
||||
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
|
||||
('page', models.ForeignKey(to='data.Page')),
|
||||
('regie', models.ForeignKey(to='lingo.Regie')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Remote Regie',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='regie',
|
||||
name='ws_url',
|
||||
field=models.URLField(verbose_name='Webservice URL', blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='regie',
|
||||
name='service',
|
||||
field=models.CharField(max_length=64, verbose_name='Payment Service', choices=[(b'dummy', 'Dummy (for tests)'), (b'systempayv2', b'systempay (Banque Populaire)'), (b'sips', b'SIPS'), (b'spplus', "SP+ (Caisse d'epargne)"), (b'ogone', 'Ingenico (formerly Ogone)'), (b'paybox', 'Paybox')]),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lingo', '0008_auto_20150813_1415'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lingoremoteregie',
|
||||
name='regie',
|
||||
field=models.ForeignKey(to='lingo.Regie', null=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -26,6 +26,8 @@ from django.conf import settings
|
|||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from django.forms import Select
|
||||
from django.forms import models as model_forms
|
||||
|
||||
from combo.data.models import CellBase
|
||||
from combo.data.library import register_cell_class
|
||||
|
@ -49,6 +51,7 @@ class Regie(models.Model):
|
|||
max_length=64, choices=SERVICES)
|
||||
service_options = JSONField(blank=True,
|
||||
verbose_name=_('Payment Service Options'))
|
||||
ws_url = models.URLField(_('Webservice URL'), blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Regie')
|
||||
|
@ -64,6 +67,24 @@ class Regie(models.Model):
|
|||
'label': self.label,
|
||||
'description': self.description}
|
||||
|
||||
def get_invoices(self, nameid):
|
||||
url = self.ws_url + '/regie/%s/invoices/?orig=combo&NameID=%s&months=12' % (self.slug,
|
||||
nameid)
|
||||
url = sign_url(url, key='xxx')
|
||||
return requests.get(url).json()
|
||||
|
||||
def get_invoice(self, invoice_id, nameid):
|
||||
url = self.ws_url + '/regie/%s/invoice/%s/?orig=combo&NameID=%s' % (self.slug,
|
||||
invoice_id, nameid)
|
||||
url = sign_url(url, key='xxx')
|
||||
return requests.get(url).json()
|
||||
|
||||
def download_invoice(self, invoice_id, nameid):
|
||||
url = self.ws_url + '/invoice-pdf/%s/?orig=combo&NameID=%s' % (invoice_id,
|
||||
nameid)
|
||||
url = sign_url(url, key='xxx')
|
||||
return requests.get(url).json()
|
||||
|
||||
|
||||
class BasketItem(models.Model):
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||
|
@ -116,7 +137,7 @@ class LingoBasketCell(CellBase):
|
|||
|
||||
@classmethod
|
||||
def is_enabled(cls):
|
||||
return Regie.objects.count() > 0
|
||||
return Regie.objects.filter(ws_url='').count() > 0
|
||||
|
||||
def is_relevant(self, context):
|
||||
if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
|
||||
|
@ -143,7 +164,7 @@ class LingoRecentTransactionsCell(CellBase):
|
|||
|
||||
@classmethod
|
||||
def is_enabled(cls):
|
||||
return Regie.objects.count() > 0
|
||||
return Regie.objects.filter(ws_url='').count() > 0
|
||||
|
||||
def is_relevant(self, context):
|
||||
if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
|
||||
|
@ -172,7 +193,7 @@ class LingoBasketLinkCell(CellBase):
|
|||
|
||||
@classmethod
|
||||
def is_enabled(cls):
|
||||
return Regie.objects.count() > 0
|
||||
return Regie.objects.filter(ws_url='').count() > 0
|
||||
|
||||
def is_relevant(self, context):
|
||||
if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
|
||||
|
@ -189,3 +210,28 @@ class LingoBasketLinkCell(CellBase):
|
|||
).exclude(cancellation_date__isnull=False)
|
||||
context['total'] = sum([x.amount for x in context['items']])
|
||||
return basket_template.render(context)
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class LingoRemoteRegie(CellBase):
|
||||
regie = models.ForeignKey(Regie, null=True)
|
||||
user_dependant = True
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Remote Regie')
|
||||
|
||||
@classmethod
|
||||
def is_enabled(cls):
|
||||
return Regie.objects.exclude(ws_url='').count() > 0
|
||||
|
||||
def render(self, context):
|
||||
request = context.get('request')
|
||||
nameid = request.session['mellon_session'].get('name_id_content')
|
||||
context.update({'regie': self.regie})
|
||||
if request.GET.get('number'):
|
||||
context.update({'invoice': self.regie.get_invoice(request.GET['number'],
|
||||
nameid)})
|
||||
else:
|
||||
context.update({'invoices': self.regie.get_invoices(nameid)})
|
||||
tmpl = template.loader.get_template('lingo/combo/remote_regie.html')
|
||||
return tmpl.render(context)
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
{% load i18n %}
|
||||
{% if invoices.data %}
|
||||
<h2>{% trans "Your invoices for" %} {{ regie }}</h2>
|
||||
<table id="invoices">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans "N°" %}</td>
|
||||
<td>{% trans "Date" %}</td>
|
||||
<td>{% trans "Amount" %}</td>
|
||||
<td></td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for invoice in invoices.data %}
|
||||
<tr>
|
||||
<td>{{ invoice.nofacture }}</td>
|
||||
<td>{{ invoice.femission }}</td>
|
||||
<td>{{ invoice.fmontant }} €</td>
|
||||
<td>
|
||||
<a href="{{ page.get_online_url }}?number={{ invoice.nofacture }}" class="view">{% trans "View" %}</a>
|
||||
{% if invoice.fpdf %} /
|
||||
<a href="{% url 'download-invoice-pdf' regie_slug=regie.slug invoice_id=invoice.nofacture %}">
|
||||
{% trans "Download" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% elif invoice.data %}
|
||||
|
||||
{% with invoice=invoice.data %}
|
||||
<h2>{% trans "Invoice nr. " %} {{ invoice.nofacture }}</h2>
|
||||
<p><strong>{% trans "Label:" %}</strong> {{ invoice.flibelle }}</p>
|
||||
<p><strong>{% trans "Amount:" %}</strong> {{ invoice.fmontant }}€</p>
|
||||
<p><strong>{% trans "Date:" %}</strong> {{ invoice.femission }}</p>
|
||||
<p><strong>{% trans "Balance:" %}</strong> {{ invoice.resteapayer }}€</p>
|
||||
<p class='download'>
|
||||
{% if invoice.fpdf %}
|
||||
<a href="{% url 'download-invoice-pdf' regie_slug=regie.slug invoice_id=invoice.nofacture %}">
|
||||
{% trans "Download invoice" %}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
<h5>{% trans "Unknown invoice" %}</h5>
|
||||
{% endif %}
|
|
@ -18,7 +18,8 @@ from django.conf.urls import patterns, url, include
|
|||
|
||||
from combo.urls_utils import decorated_includes, manager_required
|
||||
|
||||
from .views import RegiesApiView, AddBasketItemApiView, PayView, CallbackView
|
||||
from .views import RegiesApiView, AddBasketItemApiView, PayView, CallbackView, \
|
||||
InvoiceDownloadView
|
||||
from .manager_views import (RegieListView, RegieCreateView, RegieUpdateView,
|
||||
RegieDeleteView)
|
||||
|
||||
|
@ -39,4 +40,6 @@ urlpatterns = patterns('',
|
|||
url(r'^lingo/callback/(?P<regie_pk>\w+)/$', CallbackView.as_view(), name='lingo-callback'),
|
||||
url(r'^manage/lingo/', decorated_includes(manager_required,
|
||||
include(lingo_manager_urls))),
|
||||
url(r'^lingo/invoice-pdf/(?P<regie_slug>[\w,-]+)/(?P<invoice_id>[\w,-]+)/$',
|
||||
InvoiceDownloadView.as_view(), name='download-invoice-pdf'),
|
||||
)
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
from decimal import Decimal
|
||||
import json
|
||||
import base64
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect, \
|
||||
HttpResponseForbidden, Http404
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -159,3 +161,22 @@ class CallbackView(View):
|
|||
# ignore errors, it will be retried later on if it fails
|
||||
pass
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
class InvoiceDownloadView(View):
|
||||
http_method_names = [u'get']
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
mellon = self.request.session.get('mellon_session')
|
||||
if mellon:
|
||||
regie = Regie.objects.get(slug=kwargs['regie_slug'])
|
||||
invoice = regie.download_invoice(kwargs['invoice_id'], mellon['name_id_content'])
|
||||
response = HttpResponse(content_type='application/pdf')
|
||||
data = invoice['data']
|
||||
response['Content-Disposition'] = 'attachment; filename="%s.pdf"' % data['id']
|
||||
if data['file']:
|
||||
response.write(base64.b64decode(data['file']))
|
||||
return response
|
||||
else:
|
||||
return Http404()
|
||||
return HttpResponseForbidden()
|
||||
|
|
Reference in New Issue