diff --git a/modules/impotsgouvfrpar/browser.py b/modules/impotsgouvfrpar/browser.py index 2dbd181d62bad523f0b13a652dec97e974a2f84d..7bb2ae57db1b3f1988b17b7b608a6d4139e496ea 100644 --- a/modules/impotsgouvfrpar/browser.py +++ b/modules/impotsgouvfrpar/browser.py @@ -22,7 +22,7 @@ from weboob.browser import AbstractBrowser, URL, need_login from weboob.exceptions import BrowserIncorrectPassword -from .pages import LoginAccessPage, LoginAELPage, ProfilePage, DocumentsPage +from .pages import LoginAccessPage, LoginAELPage, ProfilePage, DocumentsPage, ThirdPartyDocPage class ImpotsParBrowser(AbstractBrowser): @@ -31,6 +31,7 @@ class ImpotsParBrowser(AbstractBrowser): login_access = URL(r'/LoginAccess', LoginAccessPage) login_ael = URL(r'/LoginAEL', LoginAELPage) + third_party_doc_page = URL(r'/enp/ensu/dpr.do', ThirdPartyDocPage) # affichageadresse.do is pretty similar to chargementprofil.do but display address profile = URL( @@ -94,9 +95,14 @@ def iter_subscription(self): @need_login def iter_documents(self, subscription): + # it's a document json which is used in the event of a declaration by a third party + self.third_party_doc_page.go() + yield self.page.get_third_party_doc() + # put ?n=0, else website return an error page self.documents.go(params={'n': 0}) - return self.page.iter_documents(subid=subscription.id) + for doc in self.page.iter_documents(subid=subscription.id): + yield doc @need_login def get_profile(self): diff --git a/modules/impotsgouvfrpar/module.py b/modules/impotsgouvfrpar/module.py index 30e8bc3fe02245995941f38518bb028087896eff..1080c1ddecb98c94c1db478c6e7958b597ad3409 100644 --- a/modules/impotsgouvfrpar/module.py +++ b/modules/impotsgouvfrpar/module.py @@ -52,7 +52,7 @@ class ImpotsGouvFrParModule(AbstractModule, CapDocument, CapProfile): BROWSER = ImpotsParBrowser - accepted_document_types = (DocumentTypes.INCOME_TAX,) + accepted_document_types = (DocumentTypes.INCOME_TAX, DocumentTypes.OTHER) def create_default_browser(self): return self.create_browser( diff --git a/modules/impotsgouvfrpar/pages.py b/modules/impotsgouvfrpar/pages.py index bda6c4696686678d0017e4a94de0e57c09646e02..05500c1a64acd71fcdc001d11c2d8578f9c47f39 100644 --- a/modules/impotsgouvfrpar/pages.py +++ b/modules/impotsgouvfrpar/pages.py @@ -22,10 +22,11 @@ import hashlib import re -from weboob.browser.pages import HTMLPage, LoggedPage, pagination +from weboob.browser.pages import HTMLPage, LoggedPage, pagination, JsonPage from weboob.browser.filters.standard import ( CleanText, Env, Field, Regexp, Format, Date, ) +from weboob.browser.filters.json import Dict from weboob.browser.elements import ListElement, ItemElement, method from weboob.browser.filters.html import Attr from weboob.capabilities.address import PostalAddress @@ -58,6 +59,20 @@ def get_redirect_url(self): return Regexp(CleanText('//body/script'), r"postMessage\('ok,(.*)',")(self.doc) +class ThirdPartyDocPage(LoggedPage, JsonPage): + @method + class get_third_party_doc(ItemElement): + klass = Document + + obj_id = Format('%s_%s', Dict('spiDec1'), Dict('dateNaisDec1')) + obj_format = 'json' + obj_label = 'Déclaration par un tiers' + obj_type = DocumentTypes.OTHER + + def obj_url(self): + return self.page.url + + class ProfilePage(LoggedPage, HTMLPage): def get_documents_link(self): return self.doc.xpath('//a[contains(@title, "déclarations")]/@href')[0]