Skip to content

Commit 3db5d62

Browse files
committed
[MIG] account_statement_import_online_ponto: Migration to 16.0
1 parent 049f4b2 commit 3db5d62

File tree

6 files changed

+57
-26
lines changed

6 files changed

+57
-26
lines changed

account_statement_import_online_ponto/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
55
{
66
"name": "Online Bank Statements: MyPonto.com",
7-
"version": "15.0.1.0.0",
7+
"version": "16.0.1.0.0",
88
"category": "Account",
99
"website": "https://github.com/OCA/bank-statement-import",
1010
"author": "Florent de Labarre, Therp BV, Odoo Community Association (OCA)",

account_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class OnlineBankStatementProvider(models.Model):
2323
("execution_date", "Execution Date"),
2424
("value_date", "Value Date"),
2525
],
26-
string="Ponto Date Field",
2726
default="execution_date",
2827
help="Select the Ponto date field that will be used for "
2928
"the Odoo bank statement line date. If you change this parameter "
@@ -50,6 +49,7 @@ def _pull(self, date_since, date_until):
5049
stop retrieving when either we get before date_since or there is
5150
no more data available.
5251
"""
52+
# pylint: disable=missing-return
5353
ponto_providers = self.filtered(lambda provider: provider.service == "ponto")
5454
super(OnlineBankStatementProvider, self - ponto_providers)._pull(
5555
date_since, date_until
@@ -63,21 +63,27 @@ def _ponto_pull(self, date_since, date_until):
6363
is_scheduled = self.env.context.get("scheduled")
6464
if is_scheduled:
6565
_logger.debug(
66-
_("Ponto obtain statement data for journal %s from %s to %s"),
67-
self.journal_id.name,
68-
date_since,
69-
date_until,
66+
_(
67+
"Ponto obtain statement data for journal {journal}"
68+
" from {date_since} to {date_until}"
69+
),
70+
journal=self.journal_id.name,
71+
date_since=date_since,
72+
date_until=date_until,
7073
)
7174
else:
7275
_logger.debug(
7376
_("Ponto obtain all new statement data for journal %s"),
7477
self.journal_id.name,
7578
)
7679
lines = self._ponto_retrieve_data(date_since, date_until)
77-
# For scheduled runs, store latest identifier.
78-
if is_scheduled and lines:
79-
self.ponto_last_identifier = lines[0].get("id")
80-
self._ponto_store_lines(lines)
80+
if not lines:
81+
_logger.info(_("No lines were retrieved from Ponto"))
82+
else:
83+
# For scheduled runs, store latest identifier.
84+
if is_scheduled:
85+
self.ponto_last_identifier = lines[0].get("id")
86+
self._ponto_store_lines(lines)
8187

8288
def _ponto_retrieve_data(self, date_since, date_until):
8389
"""Fill buffer with data from Ponto.

account_statement_import_online_ponto/models/ponto_interface.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ def _login(self, username, password):
2828
url = PONTO_ENDPOINT + "/oauth2/token"
2929
if not (username and password):
3030
raise UserError(_("Please fill login and key."))
31-
login = "%s:%s" % (username, password)
31+
login = ":".join([username, password])
3232
login = base64.b64encode(login.encode("UTF-8")).decode("UTF-8")
3333
login_headers = {
3434
"Content-Type": "application/x-www-form-urlencoded",
3535
"Accept": "application/json",
36-
"Authorization": "Basic %s" % login,
36+
"Authorization": "Basic {login}".format(login=login),
3737
}
38-
_logger.debug(_("POST request on %s"), url)
38+
_logger.debug(_("POST request on {url}"), url=url)
3939
response = requests.post(
4040
url,
4141
params={"grant_type": "client_credentials"},
@@ -63,13 +63,15 @@ def _get_request_headers(self, access_data):
6363
access_data.update(updated_data)
6464
return {
6565
"Accept": "application/json",
66-
"Authorization": "Bearer %s" % access_data["access_token"],
66+
"Authorization": "Bearer {access_token}".format(
67+
access_token=access_data["access_token"]
68+
),
6769
}
6870

6971
def _set_access_account(self, access_data, account_number):
7072
"""Set ponto account for bank account in access_data."""
7173
url = PONTO_ENDPOINT + "/accounts"
72-
_logger.debug(_("GET request on %s"), url)
74+
_logger.debug(_("GET request on {}"), url)
7375
response = requests.get(
7476
url,
7577
params={"limit": 100},
@@ -86,8 +88,9 @@ def _set_access_account(self, access_data, account_number):
8688
return
8789
# If we get here, we did not find Ponto account for bank account.
8890
raise UserError(
89-
_("Ponto : wrong configuration, account %s not found in %s")
90-
% (account_number, data)
91+
_(
92+
"Ponto : wrong configuration, account {account} not found in {data}"
93+
).format(account=account_number, data=data)
9194
)
9295

9396
def _get_transactions(self, access_data, last_identifier):
@@ -116,7 +119,7 @@ def _get_transactions_from_data(self, data):
116119
transactions = data.get("data", [])
117120
if not transactions:
118121
_logger.debug(
119-
_("No transactions where found in data %s"),
122+
_("No transactions where found in data {}"),
120123
data,
121124
)
122125
else:
@@ -130,7 +133,10 @@ def _get_request(self, access_data, url, params):
130133
"""Interact with Ponto to get next page of data."""
131134
headers = self._get_request_headers(access_data)
132135
_logger.debug(
133-
_("GET request to %s with headers %s and params %s"), url, params, headers
136+
_("GET request to {url} with headers {headers} and params {params}"),
137+
url=url,
138+
headers=headers,
139+
params=params,
134140
)
135141
response = requests.get(
136142
url,
@@ -142,10 +148,17 @@ def _get_request(self, access_data, url, params):
142148

143149
def _get_response_data(self, response):
144150
"""Get response data for GET or POST request."""
145-
_logger.debug(_("HTTP answer code %s from Ponto"), response.status_code)
151+
_logger.debug(
152+
_("HTTP answer code {response_code} from Ponto"),
153+
response_code=response.status_code,
154+
)
146155
if response.status_code not in (200, 201):
147156
raise UserError(
148-
_("Server returned status code %s: %s")
149-
% (response.status_code, response.text)
157+
_(
158+
"Server returned status code {response_code}: {response_text}"
159+
).format(
160+
response_code=response.status_code,
161+
response_text=response.text,
162+
)
150163
)
151164
return json.loads(response.text)

account_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,18 @@ def setUp(self):
152152
"code": "BANK",
153153
"currency_id": self.currency_eur.id,
154154
"bank_statements_source": "online",
155-
"online_bank_statement_provider": "ponto",
156155
"bank_account_id": self.bank_account.id,
157156
}
158157
)
159-
self.provider = self.journal.online_bank_statement_provider_id
160-
# To get all the moves in a month at once
161-
self.provider.statement_creation_mode = "monthly"
158+
self.provider = self.OnlineBankStatementProvider.create(
159+
{
160+
"name": "Ponto Provider",
161+
"service": "ponto",
162+
"journal_id": self.journal.id,
163+
# To get all the moves in a month at once
164+
"statement_creation_mode": "monthly",
165+
}
166+
)
162167

163168
self.mock_login = lambda: mock.patch(
164169
_interface_class + "._login",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../account_statement_import_online_ponto
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)