From 4310705600403c0acd275cd9cd414ebf91e1933a Mon Sep 17 00:00:00 2001 From: thibault douge Date: Mon, 11 May 2020 15:37:40 +0200 Subject: [PATCH] [impotsgouvfrpar] add third party document --- modules/impotsgouvfrpar/browser.py | 10 ++++++++-- modules/impotsgouvfrpar/module.py | 2 +- modules/impotsgouvfrpar/pages.py | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/modules/impotsgouvfrpar/browser.py b/modules/impotsgouvfrpar/browser.py index 2dbd181d62..7bb2ae57db 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 30e8bc3fe0..1080c1ddec 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 bda6c46966..05500c1a64 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] -- GitLab