Commit d1b4db0c authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Romain Bignon

[spirica] Corrected history pagination and transaction invests

Several elements have changed on the Spirica website:
- the "Tout afficher" button disappeared,
- the forms to get the transactions list were modified,
- the forms to get investments for each transaction changed.
This patch corrects history for each account as well as the respective
invests.
parent 5752d4e1
......@@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from weboob.browser import LoginBrowser, URL, need_login
from weboob.exceptions import BrowserIncorrectPassword
......@@ -37,7 +38,6 @@ class SpiricaBrowser(LoginBrowser):
self.BASEURL = website
self.cache = {}
self.cache['invs'] = {}
self.cache['trs'] = {}
def do_login(self):
self.login.go().login(self.username, self.password)
......@@ -51,9 +51,7 @@ class SpiricaBrowser(LoginBrowser):
@need_login
def iter_accounts(self):
if 'accs' not in self.cache.keys():
self.cache['accs'] = [a for a in self.accounts.stay_or_go().iter_accounts()]
return self.cache['accs']
return self.accounts.go().iter_accounts()
@need_login
def iter_investment(self, account):
......@@ -69,14 +67,24 @@ class SpiricaBrowser(LoginBrowser):
@need_login
def iter_history(self, account):
if account.id not in self.cache['trs']:
self.location(account.url)
self.page.go_historytab()
# Get form to show all transactions
self.page.go_historyall()
trs = [t for t in self.page.iter_history()]
self.cache['trs'][account.id] = trs
return self.cache['trs'][account.id]
self.location(account.url)
self.page.go_historytab()
transaction_page = self.page
# Determining the number of transaction pages:
total_pages = int(self.page.count_transactions()) // 100
# Scraping transactions for each page:
for page_number in range(total_pages + 1):
self.page.go_historyall(page_number)
for transaction in self.page.iter_history():
transaction_page.go_investments_form(transaction._index)
transaction.investments = []
for inv in self.page.iter_transactions_investments():
# Only keep investments that have at least a label and a valuation:
if inv.label and inv.valuation:
transaction.investments.append(inv)
yield transaction
def fill_from_list(self, invs, objects_list):
matching_fields = ['code', 'unitvalue', 'label', '_gestion_type']
......
This diff is collapsed.
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