belvo.resources.tax_returns
1from datetime import date 2from typing import Dict, List, Optional, Union 3 4from belvo.enums import TaxReturnType 5from belvo.resources.base import Resource 6 7 8class TaxReturns(Resource): 9 endpoint = "/api/tax-returns/" 10 11 def create( 12 self, 13 link: str, 14 year_from: str = None, 15 year_to: str = None, 16 *, 17 attach_pdf: bool = False, 18 save_data: bool = True, 19 raise_exception: bool = False, 20 type_: Optional[TaxReturnType] = None, 21 date_from: str = None, 22 date_to: str = None, 23 **kwargs: Dict, 24 ) -> Union[List[Dict], Dict]: 25 """Retrieve tax returns for a link 26 27 Retrieve yearly (annual) or monthly tax returns for a fiscal link. 28 29 Args: 30 link (str): The fiscal `link.id` you want specific tax return information for. 31 year_from (str, optional): The starting year you want to get tax returns for, in `YYYY` format. Defaults to None. 32 year_to (str, optional): The year you want to stop geting tax returns for, in `YYYY` format. Defaults to None. 33 attach_pdf (bool, optional): When this is set to `True`, you will receive the PDF as a binary string in the response.. Defaults to `False`. 34 save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to `True`. 35 raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to `False`. 36 type_ (Optional[TaxReturnType], optional): The type of tax return to return. For yearly tax returns this must be set to `yearly`. For monthly tax returns, this field must be set to `monthly`. By default, Belvo returns the **yearly** (annual) tax returns. 37 date_from (str, optional): The starting date you want to get tax returns for, in `YYYY-MM-DD` format. The value of `date_from` cannot be greater than `date_to`. Defaults to None. 38 date_to (str, optional): The date you want to stop geting tax returns for, in `YYYY-MM-DD` format. The value of `date_to` cannot be greater than today's date (in other words, no future dates). Defaults to None. 39 40 Returns: 41 Dict: The details of the object. For more information on the response from the API, see our [Tax returns API documentation](https://developers.belvo.com/reference/retrievetaxreturns). 42 """ 43 44 type_ = type_ if type_ else TaxReturnType.YEARLY 45 46 data = {"link": link, "attach_pdf": attach_pdf, "save_data": save_data, "type": type_.value} 47 48 if data["type"] == "yearly": 49 year_to = year_to or str(date.today().year) 50 data.update(year_to=year_to, year_from=year_from) 51 else: 52 data.update(date_to=date_to, date_from=date_from) 53 54 return self.session.post( 55 self.endpoint, data=data, raise_exception=raise_exception, **kwargs 56 ) 57 58 def resume( 59 self, 60 session: str, 61 token: str, 62 *, 63 link: str = None, 64 raise_exception: bool = False, 65 **kwargs: Dict, 66 ) -> Dict: 67 raise NotImplementedError()
9class TaxReturns(Resource): 10 endpoint = "/api/tax-returns/" 11 12 def create( 13 self, 14 link: str, 15 year_from: str = None, 16 year_to: str = None, 17 *, 18 attach_pdf: bool = False, 19 save_data: bool = True, 20 raise_exception: bool = False, 21 type_: Optional[TaxReturnType] = None, 22 date_from: str = None, 23 date_to: str = None, 24 **kwargs: Dict, 25 ) -> Union[List[Dict], Dict]: 26 """Retrieve tax returns for a link 27 28 Retrieve yearly (annual) or monthly tax returns for a fiscal link. 29 30 Args: 31 link (str): The fiscal `link.id` you want specific tax return information for. 32 year_from (str, optional): The starting year you want to get tax returns for, in `YYYY` format. Defaults to None. 33 year_to (str, optional): The year you want to stop geting tax returns for, in `YYYY` format. Defaults to None. 34 attach_pdf (bool, optional): When this is set to `True`, you will receive the PDF as a binary string in the response.. Defaults to `False`. 35 save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to `True`. 36 raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to `False`. 37 type_ (Optional[TaxReturnType], optional): The type of tax return to return. For yearly tax returns this must be set to `yearly`. For monthly tax returns, this field must be set to `monthly`. By default, Belvo returns the **yearly** (annual) tax returns. 38 date_from (str, optional): The starting date you want to get tax returns for, in `YYYY-MM-DD` format. The value of `date_from` cannot be greater than `date_to`. Defaults to None. 39 date_to (str, optional): The date you want to stop geting tax returns for, in `YYYY-MM-DD` format. The value of `date_to` cannot be greater than today's date (in other words, no future dates). Defaults to None. 40 41 Returns: 42 Dict: The details of the object. For more information on the response from the API, see our [Tax returns API documentation](https://developers.belvo.com/reference/retrievetaxreturns). 43 """ 44 45 type_ = type_ if type_ else TaxReturnType.YEARLY 46 47 data = {"link": link, "attach_pdf": attach_pdf, "save_data": save_data, "type": type_.value} 48 49 if data["type"] == "yearly": 50 year_to = year_to or str(date.today().year) 51 data.update(year_to=year_to, year_from=year_from) 52 else: 53 data.update(date_to=date_to, date_from=date_from) 54 55 return self.session.post( 56 self.endpoint, data=data, raise_exception=raise_exception, **kwargs 57 ) 58 59 def resume( 60 self, 61 session: str, 62 token: str, 63 *, 64 link: str = None, 65 raise_exception: bool = False, 66 **kwargs: Dict, 67 ) -> Dict: 68 raise NotImplementedError()
def
create( self, link: str, year_from: str = None, year_to: str = None, *, attach_pdf: bool = False, save_data: bool = True, raise_exception: bool = False, type_: Optional[belvo.enums.TaxReturnType] = None, date_from: str = None, date_to: str = None, **kwargs: Dict) -> Union[List[Dict], Dict]:
12 def create( 13 self, 14 link: str, 15 year_from: str = None, 16 year_to: str = None, 17 *, 18 attach_pdf: bool = False, 19 save_data: bool = True, 20 raise_exception: bool = False, 21 type_: Optional[TaxReturnType] = None, 22 date_from: str = None, 23 date_to: str = None, 24 **kwargs: Dict, 25 ) -> Union[List[Dict], Dict]: 26 """Retrieve tax returns for a link 27 28 Retrieve yearly (annual) or monthly tax returns for a fiscal link. 29 30 Args: 31 link (str): The fiscal `link.id` you want specific tax return information for. 32 year_from (str, optional): The starting year you want to get tax returns for, in `YYYY` format. Defaults to None. 33 year_to (str, optional): The year you want to stop geting tax returns for, in `YYYY` format. Defaults to None. 34 attach_pdf (bool, optional): When this is set to `True`, you will receive the PDF as a binary string in the response.. Defaults to `False`. 35 save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to `True`. 36 raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to `False`. 37 type_ (Optional[TaxReturnType], optional): The type of tax return to return. For yearly tax returns this must be set to `yearly`. For monthly tax returns, this field must be set to `monthly`. By default, Belvo returns the **yearly** (annual) tax returns. 38 date_from (str, optional): The starting date you want to get tax returns for, in `YYYY-MM-DD` format. The value of `date_from` cannot be greater than `date_to`. Defaults to None. 39 date_to (str, optional): The date you want to stop geting tax returns for, in `YYYY-MM-DD` format. The value of `date_to` cannot be greater than today's date (in other words, no future dates). Defaults to None. 40 41 Returns: 42 Dict: The details of the object. For more information on the response from the API, see our [Tax returns API documentation](https://developers.belvo.com/reference/retrievetaxreturns). 43 """ 44 45 type_ = type_ if type_ else TaxReturnType.YEARLY 46 47 data = {"link": link, "attach_pdf": attach_pdf, "save_data": save_data, "type": type_.value} 48 49 if data["type"] == "yearly": 50 year_to = year_to or str(date.today().year) 51 data.update(year_to=year_to, year_from=year_from) 52 else: 53 data.update(date_to=date_to, date_from=date_from) 54 55 return self.session.post( 56 self.endpoint, data=data, raise_exception=raise_exception, **kwargs 57 )
Retrieve tax returns for a link
Retrieve yearly (annual) or monthly tax returns for a fiscal link.
Arguments:
- link (str): The fiscal
link.idyou want specific tax return information for. - year_from (str, optional): The starting year you want to get tax returns for, in
YYYYformat. Defaults to None. - year_to (str, optional): The year you want to stop geting tax returns for, in
YYYYformat. Defaults to None. - attach_pdf (bool, optional): When this is set to
True, you will receive the PDF as a binary string in the response.. Defaults toFalse. - save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to
True. - raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to
False. - type_ (Optional[TaxReturnType], optional): The type of tax return to return. For yearly tax returns this must be set to
yearly. For monthly tax returns, this field must be set tomonthly. By default, Belvo returns the yearly (annual) tax returns. - date_from (str, optional): The starting date you want to get tax returns for, in
YYYY-MM-DDformat. The value ofdate_fromcannot be greater thandate_to. Defaults to None. - date_to (str, optional): The date you want to stop geting tax returns for, in
YYYY-MM-DDformat. The value ofdate_tocannot be greater than today's date (in other words, no future dates). Defaults to None.
Returns:
Dict: The details of the object. For more information on the response from the API, see our Tax returns API documentation.
def
resume( self, session: str, token: str, *, link: str = None, raise_exception: bool = False, **kwargs: Dict) -> Dict:
59 def resume( 60 self, 61 session: str, 62 token: str, 63 *, 64 link: str = None, 65 raise_exception: bool = False, 66 **kwargs: Dict, 67 ) -> Dict: 68 raise NotImplementedError()
Resume a resource sessions
Example:
# Login to Belvo API
client = Client("Secret Key ID", "Secret Key PASSWORD", "sandbox")
# Resume a link
link = client.Links.resume(
session="session_id",
token="token",
link="link_id"
)
Arguments:
- session (str): The session you want to resume (UUID).
- token (str): The MFA token required to continue the session.
- link (str, optional): The Link ID . Defaults to None.
- raise_exception (bool, optional): Boolean indicating whether to return an API error or to raise an exception. Defaults to False.
Returns:
Union[List[Dict], Dict]: On success, returns the resource data requests.