Commit bdf368c8 authored by Célande Adrien's avatar Célande Adrien Committed by Romain Bignon

[oney] missing transactions

The request, that should give all transactions, is incomplete.
Making several requests, one for all except the last two months and the
last two months, resolves the issue.

Closes: 10250@zendesk
parent cdc8c4e5
......@@ -17,7 +17,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
from datetime import date
from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
from itertools import chain
from weboob.exceptions import BrowserIncorrectPassword
from weboob.browser import LoginBrowser, URL, need_login
......@@ -107,15 +109,29 @@ class OneyBrowser(LoginBrowser):
return accounts
def _build_hist_form(self):
def _build_hist_form(self, last_months=False):
form = {}
d = date.today()
form['jourDebut'] = '1'
form['moisDebut'] = '1'
form['anneeDebut'] = '2016'
form['jourFin'] = str(d.day)
form['moisFin'] = str(d.month)
form['anneeFin'] = str(d.year)
if not last_months:
# before the last two months
end = d.replace(day=1) + relativedelta(months=-1, days=-1)
form['jourDebut'] = '1'
form['moisDebut'] = '1'
form['anneeDebut'] = '2016'
form['jourFin'] = str(end.day)
form['moisFin'] = str(end.month)
form['anneeFin'] = str(end.year)
else:
# the last two months
start = d.replace(day=1) - timedelta(days=1)
form['jourDebut'] = '1'
form['moisDebut'] = str(start.month)
form['anneeDebut'] = str(start.year)
form['jourFin'] = str(d.day)
form['moisFin'] = str(d.month)
form['anneeFin'] = str(d.year)
form['typeOpe'] = 'deux'
form['formatFichier'] = 'xls' # or pdf... great choice
return form
......@@ -134,9 +150,17 @@ class OneyBrowser(LoginBrowser):
elif account._site == 'other':
if self.last_hist.go().has_transactions():
self.credit_hist.go(params=self._build_hist_form())
d = date.today().replace(day=1) # TODO is it the right date?
for tr in self.page.iter_history():
# transactions are missing from the xls from 2016 to today
# so two requests are needed
d = date.today()
page_before = self.credit_hist.open(
params=self._build_hist_form(last_months=True)
)
page_today = self.credit_hist.go(
params=self._build_hist_form()
)
for tr in chain(page_before.iter_history(), page_today.iter_history()):
if new_date(tr.date) < d:
yield tr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment