diff --git a/modules/infomaniak/browser.py b/modules/infomaniak/browser.py index 3467dbd2e5fc76ea844b92c80bc584611eda3aa5..8c3f4309f87b5c574f7b08b7a687d53f187bc418 100644 --- a/modules/infomaniak/browser.py +++ b/modules/infomaniak/browser.py @@ -19,8 +19,6 @@ from __future__ import unicode_literals -from datetime import date - from weboob.browser import LoginBrowser, URL, need_login from weboob.exceptions import BrowserIncorrectPassword @@ -32,7 +30,7 @@ class InfomaniakBrowser(LoginBrowser): login = URL(r'https://login.infomaniak.com/api/login', LoginPage) profile = URL(r'/v3/api/profile/me', SubscriptionsPage) - documents = URL(r'/admin/facturation/operations/satable_load.php', DocumentsPage) + documents = URL(r'/v3/api/invoicing/(?P.*)/invoices', DocumentsPage) def do_login(self): self.login.go(data={'login': self.username, 'password': self.password}) @@ -47,29 +45,12 @@ def iter_subscription(self): @need_login def iter_documents(self, subscription): - for offset in range(0, 400, 20): - data = { - 'iOffset': offset, - 'iCount': 20, - 'sSort': 'none', - 'iCodeService': '0', - 'dStart_toolbar_select': 'allOperations', - 'dStart': '2000-01-01', - 'dEnd': date.today().strftime('%Y-%m-%d'), - 'cb_collections_card': '1', - 'cb_collections_post': '1', - 'cb_collections_paypal': '1', - 'cb_collections_iban': '1', - 'cb_collections_bvr': '1', - 'cb_collections_prepaid': '1', - 'cb_collections_cash': '1', - } - self.documents.go(data=data) - some = False - for doc in self.page.iter_documents(subid=subscription.id): - some = True - yield doc - if not some: - break - else: - assert False, 'are there that many bills?' + params = { + 'ajax': 'true', + 'order_by': 'name', + 'order_for[name]': 'asc', + 'page': '1', + 'per_page': '100' + } + self.documents.go(subid=subscription.id, params=params) + return self.page.iter_documents(subid=subscription.id) diff --git a/modules/infomaniak/pages.py b/modules/infomaniak/pages.py index 91dac5ac654a18055b925e731526e98e12ce6cae..94b4a71ca00b50eb5cb74c39da9a473fb6197d72 100644 --- a/modules/infomaniak/pages.py +++ b/modules/infomaniak/pages.py @@ -21,14 +21,13 @@ from datetime import datetime -from weboob.browser.pages import LoggedPage, JsonPage +from weboob.browser.pages import LoggedPage, JsonPage, pagination from weboob.browser.elements import ItemElement, method, DictElement from weboob.browser.filters.standard import ( - CleanDecimal, Env, Regexp, Format, Currency, Field, Eval, + CleanDecimal, Env, Format, Currency, Field, Eval, ) from weboob.browser.filters.json import Dict -from weboob.capabilities.bill import DocumentTypes, Bill, Subscription -from weboob.tools.compat import urljoin +from weboob.capabilities.bill import Bill, Subscription class LoginPage(JsonPage): @@ -48,22 +47,35 @@ class get_subscription(ItemElement): class DocumentsPage(LoggedPage, JsonPage): + @pagination @method class iter_documents(DictElement): - item_xpath = 'aLines' + item_xpath = 'data' + + def next_page(self): + doc = self.page.doc + current_page = int(doc['page']) + if current_page >= doc['pages']: + return + + params = { + 'ajax': 'true', + 'order_by': 'name', + 'order_for[name]': 'asc', + 'page': current_page + 1, + 'per_page': '100' + } + return self.page.browser.documents.build(subid=self.env['subid'], params=params) class item(ItemElement): klass = Bill - def obj_url(self): - return urljoin(self.page.url, Regexp(Dict('sOperation'), r'"(/.*\.pdf)')(self)) - - _num = Regexp(Field('url'), r'facture_(\d+).pdf') + _num = Dict('document/id') obj_id = Format('%s_%s', Env('subid'), _num) - obj_date = Eval(datetime.fromtimestamp, Dict('sTimestamp')) - obj_label = Format('Facture %s', _num) - obj_price = CleanDecimal(Dict('fMontant')) - obj_currency = Currency(Dict('sMontant')) - obj_type = DocumentTypes.BILL + obj_date = Eval(datetime.fromtimestamp, Dict('created_at')) + obj_label = Format('Facture %s', Field('id')) + obj_url = Dict('document/href') + obj_price = CleanDecimal(Dict('amount/amount')) + obj_currency = Currency(Dict('amount/currency')) obj_format = 'pdf'