From 93120d43b2ce0d5e17963ad048160636ede57aed Mon Sep 17 00:00:00 2001 From: Johan Le Baut Date: Mon, 6 Mar 2023 15:53:31 +0100 Subject: [PATCH] fix netwo --- webapp/main.py | 8 +++++++- webapp/netwo/netwo.py | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/webapp/main.py b/webapp/main.py index 9b9b62e..16ad48e 100644 --- a/webapp/main.py +++ b/webapp/main.py @@ -22,6 +22,7 @@ class Config(TypedDict): arcep_ipe_path: str arcep_ipe_db_name: str netwo_api_key: str + netwo_aquilenet_fixed_recurring_price: float def parseConfig() -> Config: @@ -35,6 +36,9 @@ def parseConfig() -> Config: "arcep_ipe_path": cfg.get("DB", "arcep_ipe_path"), "arcep_ipe_db_name": cfg.get("DB", "arcep_ipe_db_name"), "netwo_api_key": cfg.get("NETWO", "api_key"), + "netwo_aquilenet_fixed_recurring_price": float( + cfg.get("NETWO", "aquilenet_fixed_recurring_price") or 0.00 + ), } @@ -44,7 +48,9 @@ cfg: Config = parseConfig() axione = Axione(cfg.get("axione_ipe_path"), cfg.get("axione_ipe_db_name")) arcep = Arcep(cfg.get("arcep_ipe_path"), cfg.get("arcep_ipe_db_name")) liazo = Liazo() -netwo = Netwo(cfg.get("netwo_api_key")) +netwo = Netwo( + cfg.get("netwo_api_key"), cfg.get("netwo_aquilenet_fixed_recurring_price") +) elig_api_routes = EligibilityApiRoutes(app, axione, netwo) elig_api_routes.add_routes() elig_api_exceptions = FlaskExceptions(app) diff --git a/webapp/netwo/netwo.py b/webapp/netwo/netwo.py index f98b073..cbd43c7 100644 --- a/webapp/netwo/netwo.py +++ b/webapp/netwo/netwo.py @@ -9,6 +9,7 @@ from eligibility_api.elig_api_exceptions import NetwoApiErrorException from ipe_fetcher import FAIEligibilityStatus NETWO_DEPLOYED_STATUS = "Deployed" +TVA_INCREASE_COEFF = 1.2 class NetwooEligibility(TypedDict): @@ -25,12 +26,13 @@ class NetwooEligibility(TypedDict): class Netwo: - def __init__(self, netwo_api_key: str): + def __init__(self, netwo_api_key: str, aquilenet_fixed_recurring_price: float): self.netwo_api_headers = { "x-actor-slug": "aquilenet", "x-api-key": netwo_api_key, "Accept": "application/json", } + self.aquilenet_fixed_recurring_price = aquilenet_fixed_recurring_price def get_netwo_imb_coordinates(self, ref_imb: str) -> dict: """ @@ -45,15 +47,14 @@ class Netwo: headers=self.netwo_api_headers, ) status_code = response.status_code - if status_code != 200: + if status_code != 200 or not response.json(): raise NetwoApiErrorException( f"Could not GET netwo imb ref {ref_imb}", status_code ) imb_payload = response.json() return imb_payload - @staticmethod - def _filter_netwo_raw_elig_results(raw_elig: dict, search_ftto: bool) -> list: + def _filter_netwo_raw_elig_results(self, raw_elig: dict, search_ftto: bool) -> list: filtered_elig = [] inf_search = ["ftth"] if search_ftto: @@ -72,6 +73,14 @@ class Netwo: access_fee = offer.get("access_fee") or 0.00 recurring_price = offer.get("recurring_price") or 0.00 commitment_duration = offer.get("commitment_duration") or 0 + access_fee_ttc = round( + access_fee * TVA_INCREASE_COEFF, + ) + total_recurring_price_ttc = round( + recurring_price * TVA_INCREASE_COEFF + + self.aquilenet_fixed_recurring_price, + 2, + ) filtered_elig.append( { "entity_id": entity_id, @@ -81,15 +90,19 @@ class Netwo: "infrastructure_type": inf_type, "debit": debit, "access_fee": access_fee, + "access_fee_ttc": access_fee_ttc, "recurring_price": recurring_price, + "total_recurring_price_ttc": total_recurring_price_ttc, "commitment_duration": commitment_duration, - "per_month_price_one_year": round( - access_fee / 12 + recurring_price, 2 + "per_month_price_one_year_ttc": round( + access_fee_ttc / 12 + total_recurring_price_ttc, 2 ), } ) sort_elig = sorted( - filtered_elig, key=lambda x: x["per_month_price_one_year"], reverse=False + filtered_elig, + key=lambda x: x["per_month_price_one_year_ttc"], + reverse=False, ) return sort_elig