diff --git a/parking_permits/models/product.py b/parking_permits/models/product.py index 0d088b29..5f565312 100644 --- a/parking_permits/models/product.py +++ b/parking_permits/models/product.py @@ -186,7 +186,7 @@ def get_talpa_pricing(self, is_low_emission, is_secondary): } """ price_gross = self.get_modified_unit_price(is_low_emission, is_secondary) - price_net = price_gross / (1 + (self.vat or 0)) + price_net = price_gross / Decimal(1 + (self.vat or 0)) return { "price_gross": round_up(price_gross), diff --git a/parking_permits/tests/models/test_order.py b/parking_permits/tests/models/test_order.py index 75f4dabd..589c76f9 100644 --- a/parking_permits/tests/models/test_order.py +++ b/parking_permits/tests/models/test_order.py @@ -65,30 +65,30 @@ def test_create_for_customer_should_create_order_with_items(self): self.assertEqual(order_items[1].unit_price, Decimal(50)) self.assertEqual(order_items[1].quantity, 2) - @freeze_time("2023-03-15") def test_create_for_permits_should_create_order_items_with_start_end_date_for_open_ended_permits( self, ): - start_time = timezone.now() - permit = ParkingPermitFactory( - parking_zone=self.zone, - customer=self.customer, - contract_type=ContractType.OPEN_ENDED, - status=ParkingPermitStatus.DRAFT, - start_time=start_time, - month_count=6, - ) - order = Order.objects.create_for_permits([permit]) - order_items = order.order_items.all().order_by("-quantity") - self.assertEqual(order_items.count(), 1) - order_item = order_items[0] - self.assertEqual( - order_item.start_time.date(), timezone.localtime(start_time).date() - ) - self.assertEqual( - order_item.end_time.date(), - get_end_time(start_time, 1).date(), - ) + with freeze_time(date(CURRENT_YEAR, 3, 5)): + start_time = timezone.now() + permit = ParkingPermitFactory( + parking_zone=self.zone, + customer=self.customer, + contract_type=ContractType.OPEN_ENDED, + status=ParkingPermitStatus.DRAFT, + start_time=start_time, + month_count=6, + ) + order = Order.objects.create_for_permits([permit]) + order_items = order.order_items.all().order_by("-quantity") + self.assertEqual(order_items.count(), 1) + order_item = order_items[0] + self.assertEqual( + order_item.start_time.date(), timezone.localtime(start_time).date() + ) + self.assertEqual( + order_item.end_time.date(), + get_end_time(start_time, 1).date(), + ) def test_create_renewable_order_should_create_renewal_order(self): start_time = timezone.make_aware(datetime(CURRENT_YEAR, 3, 15)) diff --git a/parking_permits/tests/models/test_product.py b/parking_permits/tests/models/test_product.py index 422298d3..9404ba8b 100644 --- a/parking_permits/tests/models/test_product.py +++ b/parking_permits/tests/models/test_product.py @@ -114,6 +114,6 @@ def test_get_talpa_pricing_with_discount(self): pricing = product.get_talpa_pricing(True, False) assert pricing == { "price_gross": "10.00", - "price_net": "16.13", - "price_vat": "3.87", + "price_net": "8.06", + "price_vat": "1.94", } diff --git a/parking_permits/tests/test_views.py b/parking_permits/tests/test_views.py index 673a54b7..b1666e33 100644 --- a/parking_permits/tests/test_views.py +++ b/parking_permits/tests/test_views.py @@ -51,7 +51,6 @@ from ..models import Customer from ..models.common import SourceSystem -from ..utils import round_up from .keys import rsa_key @@ -180,10 +179,16 @@ class BaseResolveEndpointTestCase(APITestCase): permit_id = "80000001" def prepare_test_data( - self, permit_id, unit_price, low_emission_discount, primary_permit=True + self, + permit_id, + unit_price, + low_emission_discount, + primary_permit=True, ): - start_date = datetime.date(2023, 1, 1) - end_date = datetime.date(2023, 12, 31) + now = datetime.date.today() + start_date = datetime.date(now.year, 1, 1) + end_date = datetime.date(now.year, 12, 31) + vehicle = VehicleFactory( power_type=VehiclePowerTypeFactory(identifier="01", name="Bensin"), emission=45, @@ -198,10 +203,10 @@ def prepare_test_data( euro_min_class_limit=6, ) permit_start_time = datetime.datetime( - 2023, 9, 12, 13, 46, 0, tzinfo=datetime.timezone.utc + now.year, 9, 12, 13, 46, 0, tzinfo=datetime.timezone.utc ) permit_end_time = datetime.datetime( - 2023, 10, 11, 23, 59, 0, tzinfo=datetime.timezone.utc + now.year, 10, 11, 23, 59, 0, tzinfo=datetime.timezone.utc ) zone_a = ParkingZoneFactory(name="A") product_detail_list = [[(start_date, end_date), unit_price]] @@ -325,17 +330,13 @@ def test_resolve_price_view_for_normal_emission_vehicle(self): ) response = self.client.post(url, data, format="json") self.assertEqual(response.status_code, 200) - vat = product.vat - price_vat = unit_price * vat self.assertEqual( response.data.get("subscriptionId"), self.talpa_subscription_id ) self.assertEqual(response.data.get("userId"), self.user_id) - self.assertEqual( - response.data.get("priceNet"), round_up(float(unit_price - price_vat)) - ) - self.assertEqual(response.data.get("priceVat"), round_up(float(price_vat))) - self.assertEqual(response.data.get("priceGross"), round_up(float(unit_price))) + self.assertEqual(response.data.get("priceNet"), "48.39") + self.assertEqual(response.data.get("priceVat"), "11.61") + self.assertEqual(response.data.get("priceGross"), "60.00") def test_resolve_price_view_for_low_emission_vehicle(self): unit_price = Decimal(60) @@ -353,28 +354,15 @@ def test_resolve_price_view_for_low_emission_vehicle(self): ) response = self.client.post(url, data, format="json") self.assertEqual(response.status_code, 200) - vat = product.vat - low_emission_price = ( - unit_price - unit_price * low_emission_discount - ) # discount price - low_emission_price_vat = low_emission_price * vat self.assertEqual( response.data.get("subscriptionId"), self.talpa_subscription_id ) self.assertEqual(response.data.get("userId"), self.user_id) - self.assertEqual( - response.data.get("priceGross"), round_up(float(low_emission_price)) - ) - self.assertEqual( - response.data.get("priceVat"), round_up(float(low_emission_price_vat)) - ) - self.assertEqual( - response.data.get("priceNet"), - round_up(float(low_emission_price - low_emission_price_vat)), - ) + self.assertEqual(response.data.get("priceGross"), "45.00") + self.assertEqual(response.data.get("priceVat"), "8.71") + self.assertEqual(response.data.get("priceNet"), "36.29") def test_resolve_price_view_for_secondary_normal_emission_vehicle(self): - secondary_vehicle_increase_rate = Decimal(0.5) unit_price = Decimal(60) low_emission_discount = Decimal(0) permit, product = self.prepare_test_data( @@ -390,28 +378,15 @@ def test_resolve_price_view_for_secondary_normal_emission_vehicle(self): ) response = self.client.post(url, data, format="json") self.assertEqual(response.status_code, 200) - vat = product.vat - secondary_vehicle_price = ( - unit_price + unit_price * secondary_vehicle_increase_rate - ) # secondary vehicle price - secondary_vehicle_price_vat = secondary_vehicle_price * vat self.assertEqual( response.data.get("subscriptionId"), self.talpa_subscription_id ) self.assertEqual(response.data.get("userId"), self.user_id) - self.assertEqual( - response.data.get("priceGross"), round_up(float(secondary_vehicle_price)) - ) - self.assertEqual( - response.data.get("priceVat"), round_up(float(secondary_vehicle_price_vat)) - ) - self.assertEqual( - response.data.get("priceNet"), - round_up(float(secondary_vehicle_price - secondary_vehicle_price_vat)), - ) + self.assertEqual(response.data.get("priceGross"), "90.00") + self.assertEqual(response.data.get("priceVat"), "17.42") + self.assertEqual(response.data.get("priceNet"), "72.58") def test_resolve_price_view_for_secondary_low_emission_vehicle(self): - secondary_vehicle_increase_rate = Decimal(0.5) unit_price = Decimal(60) low_emission_discount = Decimal(0.25) permit, product = self.prepare_test_data( @@ -427,27 +402,13 @@ def test_resolve_price_view_for_secondary_low_emission_vehicle(self): ) response = self.client.post(url, data, format="json") self.assertEqual(response.status_code, 200) - vat = product.vat - - modified_price = unit_price - modified_price -= modified_price * low_emission_discount - modified_price += modified_price * secondary_vehicle_increase_rate - modified_price_vat = modified_price * vat - self.assertEqual( response.data.get("subscriptionId"), self.talpa_subscription_id ) self.assertEqual(response.data.get("userId"), self.user_id) - self.assertEqual( - response.data.get("priceGross"), round_up(float(modified_price)) - ) - self.assertEqual( - response.data.get("priceVat"), round_up(float(modified_price_vat)) - ) - self.assertEqual( - response.data.get("priceNet"), - round_up(float(modified_price - modified_price_vat)), - ) + self.assertEqual(response.data.get("priceGross"), "67.50") + self.assertEqual(response.data.get("priceVat"), "13.06") + self.assertEqual(response.data.get("priceNet"), "54.44") def test_resolve_price_view_should_return_error_if_permit_products_missing( self, diff --git a/parking_permits/views.py b/parking_permits/views.py index 1d696c92..731ec981 100644 --- a/parking_permits/views.py +++ b/parking_permits/views.py @@ -81,7 +81,6 @@ get_meta_item, get_meta_value, get_user_from_api_view_method_args, - round_up, snake_to_camel_dict, )