From c54ee851dd634d71e6e9dbb0690f68156d75fa2c Mon Sep 17 00:00:00 2001 From: Mika Hietanen Date: Thu, 14 Dec 2023 10:32:45 +0200 Subject: [PATCH] Improve optional Traficom check logic --- parking_permits/admin_resolvers.py | 3 ++- parking_permits/customer_permit.py | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/parking_permits/admin_resolvers.py b/parking_permits/admin_resolvers.py index 65f7d26f..8e037e7c 100644 --- a/parking_permits/admin_resolvers.py +++ b/parking_permits/admin_resolvers.py @@ -305,7 +305,8 @@ def resolve_customers(obj, info, page_input, order_by=None, search_params=None): ) def resolve_vehicle(obj, info, reg_number, national_id_number): customer = Customer.objects.get_or_create(national_id_number=national_id_number)[0] - customer.fetch_driving_licence_detail() + if settings.TRAFICOM_CHECK: + customer.fetch_driving_licence_detail() vehicle = customer.fetch_vehicle_detail(reg_number) if not settings.TRAFICOM_CHECK: return vehicle diff --git a/parking_permits/customer_permit.py b/parking_permits/customer_permit.py index 9c65ecc0..67177c04 100644 --- a/parking_permits/customer_permit.py +++ b/parking_permits/customer_permit.py @@ -206,22 +206,24 @@ def create(self, address_id, registration): primary_vehicle = not primary_permit.primary_vehicle end_time = primary_permit.end_time - self.customer.fetch_driving_licence_detail() + if settings.TRAFICOM_CHECK: + self.customer.fetch_driving_licence_detail() vehicle = self.customer.fetch_vehicle_detail(registration) - is_user_of_vehicle = self.customer.is_user_of_vehicle(vehicle) - if not is_user_of_vehicle: - raise TraficomFetchVehicleError( - _("Owner/holder data of a vehicle could not be verified") - ) + if settings.TRAFICOM_CHECK: + is_user_of_vehicle = self.customer.is_user_of_vehicle(vehicle) + if not is_user_of_vehicle: + raise TraficomFetchVehicleError( + _("Owner/holder data of a vehicle could not be verified") + ) - has_valid_licence = self.customer.has_valid_driving_licence_for_vehicle( - vehicle - ) - if not has_valid_licence: - raise TraficomFetchVehicleError( - _("Customer does not have a valid driving licence") + has_valid_licence = self.customer.has_valid_driving_licence_for_vehicle( + vehicle ) + if not has_valid_licence: + raise TraficomFetchVehicleError( + _("Customer does not have a valid driving licence") + ) start_time = tz.now() if not end_time: