-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenable_banking.py
76 lines (61 loc) · 2.57 KB
/
enable_banking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import requests
from trytond.model import ModelSingleton, ModelSQL, ModelView, fields
from trytond.i18n import gettext
from trytond.exceptions import UserError
from trytond.config import config
from .common import get_base_header
from trytond.report import Report
class EnableBankingConfiguration(ModelSingleton, ModelSQL, ModelView):
"Enable Banking Configuration"
__name__ = 'enable_banking.configuration'
redirecturl = fields.Char("Redirect URL")
date_field = fields.Selection([
('booking_date', 'Booking Date'),
('transaction_date', 'Transaction Date'),
('value_date', 'Value Date'),
], "Date Field", help='Choose which date to use when importing statements')
offset = fields.Integer("Offset Days",
help="Offset in days to apply when importing statements manually")
@classmethod
def default_date_field(cls):
return 'transaction_date'
@classmethod
def default_offset(cls):
return 10
@classmethod
def __setup__(cls):
super(EnableBankingConfiguration, cls).__setup__()
cls._buttons.update({
'test_connection': {}
})
@classmethod
@ModelView.button
def test_connection(cls, aspsps):
base_headers = get_base_header()
r = requests.get(f"{config.get('enable_banking', 'api_origin')}/application",
headers=base_headers)
if r.status_code == 200:
raise UserError(gettext(
'account_statement_enable_banking.msg_connection_test_ok'))
else:
raise UserError(gettext(
'account_statement_enable_banking.msg_connection_test_error',
error_message=r.text))
class EnableBankingSession(ModelSQL, ModelView):
"Enable Banking Session"
__name__ = 'enable_banking.session'
company = fields.Many2One('company.company', "Company", required=True)
session_id = fields.Char("Session ID", readonly=True)
valid_until = fields.DateTime('Valid Until', readonly=True)
session = fields.Text("Session", readonly=True)
aspsp_name = fields.Char("ASPSP Name", readonly=True)
aspsp_country = fields.Char("ASPSP Country", readonly=True)
bank = fields.Many2One('bank', "Bank", readonly=True)
class EnableBankingSessionOK(Report):
"Enable Banking Session OK"
__name__ = 'enable_banking.session_ok'
class EnableBankingSessionKO(Report):
"Enable Banking Session KO"
__name__ = 'enable_banking.session_ko'