From 54a5d550502055ea750445343d9de6a3b3d07851 Mon Sep 17 00:00:00 2001 From: Lymar Volodymyr Date: Sat, 8 Jun 2024 22:34:04 +0200 Subject: [PATCH] Added new methods get_delivery_cost, get_city, get_rw for DataService class --- makedoc/data_service.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/makedoc/data_service.py b/makedoc/data_service.py index a7077dd..31cefc6 100644 --- a/makedoc/data_service.py +++ b/makedoc/data_service.py @@ -1,6 +1,6 @@ from clients.models import Client from goods.models import Product -from logistics.models import Factory +from logistics.models import Factory, RailwayStation class DataService: @@ -75,3 +75,32 @@ def get_factory(processed_data): return factory_data except Factory.DoesNotExist: raise Exception("Factory not found") + + @staticmethod + def get_delivery_cost(processed_data): + delivery_cost = processed_data.get("delivery_cost") + if delivery_cost is None: + raise Exception("Delivery cost not found") + return delivery_cost + + @staticmethod + def get_city(processed_data): + city = processed_data.get("destination") + if city is None: + raise Exception("City not found") + return city + + @staticmethod + def get_rw(processed_data): + try: + rw_id = processed_data.get("destination") + rw = RailwayStation.objects.get(id=rw_id) + rw_data = { + "id": int(rw.id), + "station_name": str(rw.station_name), + "station_id": int(rw.station_id), + "station_branch": str(rw.station_branch), + } + return rw_data + except RailwayStation.DoesNotExist: + raise Exception("Railway station not found")