chore: formatted stuff

This commit is contained in:
2024-05-13 17:34:56 +02:00
parent a49fb5e885
commit aa80c58628
6 changed files with 51 additions and 46 deletions
+10 -5
View File
@@ -107,13 +107,13 @@ class OrderLineViewSet(ModelViewSet):
def perform_create(self, serializer):
with transaction.atomic():
order = get_object_or_404(Order, uuid=self.kwargs.get('order_id'))
product = serializer.validated_data.get('product')
order = get_object_or_404(Order, uuid=self.kwargs.get("order_id"))
product = serializer.validated_data.get("product")
price = product.prices.last()
tax = price.tax.value
quantity = serializer.validated_data.get('quantity')
quantity = serializer.validated_data.get("quantity")
base_total = quantity * price.price
taxes = base_total * (tax / Decimal('100'))
taxes = base_total * (tax / Decimal("100"))
total = base_total + taxes
instance = serializer.save(
@@ -139,4 +139,9 @@ class OrderLineViewSet(ModelViewSet):
order.save()
def get_queryset(self):
return super().get_queryset().select_related('order').filter(order__uuid=self.kwargs.get("order_id"))
return (
super()
.get_queryset()
.select_related("order")
.filter(order__uuid=self.kwargs.get("order_id"))
)
+25 -21
View File
@@ -61,11 +61,11 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
"shipping_country": self.customer.country,
"shipping_zip": self.customer.zip,
"contact_phone": "612345678",
}
},
)
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get('uuid')
pk = response.data.get("uuid")
response = self.client.get(f"/api/v1/shop/orders/{pk}/")
assert response.status_code == status.HTTP_200_OK
@@ -88,34 +88,36 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
"shipping_country": self.customer.country,
"shipping_zip": self.customer.zip,
"contact_phone": "612345678",
}
},
)
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get('uuid')
pk = response.data.get("uuid")
response = self.client.get(f"/api/v1/shop/orders/{pk}/")
assert response.status_code == status.HTTP_200_OK
assert Decimal(response.data.get('base_total')) == Decimal('0.00')
assert Decimal(response.data.get('total')) == Decimal('0.00')
assert Decimal(response.data.get("base_total")) == Decimal("0.00")
assert Decimal(response.data.get("total")) == Decimal("0.00")
response = self.client.post(
f"/api/v1/shop/orders/{pk}/lines/",
{
"product": self.product.pk,
"quantity": "5",
}
},
)
assert response.status_code == status.HTTP_201_CREATED
response = self.client.get(f"/api/v1/shop/orders/{pk}/lines/")
assert len(response.data.get('results')) == 1
assert len(response.data.get("results")) == 1
response = self.client.get(f"/api/v1/shop/orders/{pk}/")
assert response.status_code == status.HTTP_200_OK
assert Decimal(response.data.get('base_total')) == Decimal('6.00')
assert Decimal(response.data.get('total')) == Decimal('6.00') + (Decimal('6.00') * Decimal('0.21'))
assert Decimal(response.data.get("base_total")) == Decimal("6.00")
assert Decimal(response.data.get("total")) == Decimal("6.00") + (
Decimal("6.00") * Decimal("0.21")
)
def test_create_delete_order_with_lines(self):
self.login()
@@ -136,18 +138,18 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
"shipping_country": self.customer.country,
"shipping_zip": self.customer.zip,
"contact_phone": "612345678",
}
},
)
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get('uuid')
pk = response.data.get("uuid")
response = self.client.get(f"/api/v1/shop/orders/{pk}/")
assert response.status_code == status.HTTP_200_OK
# Assert order is created with 0.00€
assert Decimal(response.data.get('base_total')) == Decimal('0.00')
assert Decimal(response.data.get('total')) == Decimal('0.00')
assert Decimal(response.data.get("base_total")) == Decimal("0.00")
assert Decimal(response.data.get("total")) == Decimal("0.00")
# Create order line
response = self.client.post(
@@ -155,21 +157,23 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
{
"product": self.product.pk,
"quantity": "5",
}
},
)
line_pk = response.data.get('id')
line_pk = response.data.get("id")
assert response.status_code == status.HTTP_201_CREATED
response = self.client.get(f"/api/v1/shop/orders/{pk}/lines/")
assert len(response.data.get('results')) == 1
assert len(response.data.get("results")) == 1
response = self.client.get(f"/api/v1/shop/orders/{pk}/")
assert response.status_code == status.HTTP_200_OK
# Assert order totals are set
assert Decimal(response.data.get('base_total')) == Decimal('6.00')
assert Decimal(response.data.get('total')) == Decimal('6.00') + (Decimal('6.00') * Decimal('0.21'))
assert Decimal(response.data.get("base_total")) == Decimal("6.00")
assert Decimal(response.data.get("total")) == Decimal("6.00") + (
Decimal("6.00") * Decimal("0.21")
)
# Delete line
response = self.client.delete(f"/api/v1/shop/orders/{pk}/lines/{line_pk}/")
@@ -179,5 +183,5 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
assert response.status_code == status.HTTP_200_OK
# Assert order totals are 0.00
assert Decimal(response.data.get('base_total')) == Decimal('0.00')
assert Decimal(response.data.get('total')) == Decimal('0.00')
assert Decimal(response.data.get("base_total")) == Decimal("0.00")
assert Decimal(response.data.get("total")) == Decimal("0.00")