Skip to content

Commit 2cbefb1

Browse files
committed
[IMP] *_online_ponto: make conditions readable in data retrieval
1 parent 53d7dac commit 2cbefb1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

account_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _pull(self, date_since, date_until):
6060
def _ponto_pull(self, date_since, date_until):
6161
"""Translate information from Ponto to Odoo bank statement lines."""
6262
self.ensure_one()
63-
is_scheduled = self.env.context.get("scheduled")
63+
is_scheduled = self.env.context.get("scheduled", False)
6464
if is_scheduled:
6565
_logger.debug(
6666
_(
@@ -97,12 +97,12 @@ def _ponto_retrieve_data(self, date_since, date_until):
9797
Note: when reading data they are likely to be in descending order of
9898
execution_date (not seen a guarantee for this in Ponto API). When using
9999
value date, they may well be out of order. So we cannot simply stop
100-
when we have foundd a transaction date before the date_since.
100+
when we have found a transaction date before the date_since.
101101
102102
We will not read transactions more then a week before before date_since.
103103
"""
104104
date_stop = date_since - timedelta(days=7)
105-
is_scheduled = self.env.context.get("scheduled")
105+
is_scheduled = self.env.context.get("scheduled", False)
106106
lines = []
107107
interface_model = self.env["ponto.interface"]
108108
access_data = interface_model._login(self.username, self.password)
@@ -113,15 +113,21 @@ def _ponto_retrieve_data(self, date_since, date_until):
113113
for line in transactions:
114114
identifier = line.get("id")
115115
transaction_datetime = self._ponto_get_transaction_datetime(line)
116-
if (is_scheduled and identifier == self.ponto_last_identifier) or (
117-
transaction_datetime < date_stop
118-
and (not self.ponto_last_identifier or not is_scheduled)
119-
):
120-
return lines
121-
if not is_scheduled:
122-
if transaction_datetime < date_since:
116+
if is_scheduled:
117+
# Handle all stop conditions for scheduled runs.
118+
if identifier == self.ponto_last_identifier or (
119+
not self.ponto_last_identifier
120+
and transaction_datetime < date_stop
121+
):
123122
return lines
124-
if transaction_datetime > date_until:
123+
else:
124+
# Handle stop conditions for non scheduled runs.
125+
if transaction_datetime < date_stop:
126+
return lines
127+
if (
128+
transaction_datetime < date_since
129+
or transaction_datetime > date_until
130+
):
125131
continue
126132
line["transaction_datetime"] = transaction_datetime
127133
lines.append(line)

0 commit comments

Comments
 (0)