Commit 725e8677 authored by Florian Duguet's avatar Florian Duguet Committed by Vincent A

[infomaniak] fix iter_document after documents page has changed

Closes: 11548@zendesk
Closes: 35074@sibi
parent 0716bc2a
......@@ -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<subid>.*)/invoices', DocumentsPage)
def do_login(self):
self.login.go(data={'login': self.username, 'password': self.password})
......@@ -47,29 +45,12 @@ class InfomaniakBrowser(LoginBrowser):
@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)
......@@ -21,14 +21,13 @@ from __future__ import unicode_literals
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 SubscriptionsPage(LoggedPage, JsonPage):
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'&quot;(/.*\.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'
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