From bdf368c8be73267c54b11c531a1c25e0c6d05ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lande=20Adrien?= Date: Thu, 28 Mar 2019 10:26:46 +0100 Subject: [PATCH] [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 --- modules/oney/browser.py | 46 +++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/modules/oney/browser.py b/modules/oney/browser.py index 15db5e6378..a7f5ee4f53 100644 --- a/modules/oney/browser.py +++ b/modules/oney/browser.py @@ -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 . -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 @@ def get_accounts_list(self): 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 @@ def iter_history(self, account): 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 -- GitLab