]>
Commit | Line | Data |
---|---|---|
26235f08 MF |
1 | from django.shortcuts import render |
2 | from django.http import HttpResponse | |
3 | from django.contrib.auth.decorators import login_required | |
40e726c7 MF |
4 | from django.conf import settings |
5 | try: | |
6 | import requests | |
7 | except ModuleNotFoundError as e: | |
8 | pass | |
9 | ||
26235f08 MF |
10 | |
11 | @login_required | |
12 | def index(request): | |
40e726c7 MF |
13 | headers = {"Access-Token":settings.FORTNOX_ACCESS_TOKEN, |
14 | "Client-Secret":settings.FORTNOX_CLIENT_SECRET, | |
15 | "Content-Type":"application/json", | |
16 | "Accept":"application/json" } | |
17 | res = requests.get("https://api.fortnox.se/3/contracts/", headers=headers) | |
18 | contracts=res.json() | |
19 | contracts = [contract for contract in contracts['Contracts'] if int(contract['CustomerNumber']) == request.user.fortnox_external_id] | |
20 | res = requests.get("https://api.fortnox.se/3/invoices/", headers=headers) | |
21 | invoices = res.json() | |
22 | invoices = [invoice for invoice in invoices['Invoices'] if int(invoice['CustomerNumber']) == request.user.fortnox_external_id] | |
23 | return render(request, 'customerportal/landing.html',context={'contracts':contracts, 'invoices':invoices}) | |
26235f08 | 24 |