feat: added creation endpoints

This commit is contained in:
2024-03-25 00:23:03 +01:00
parent 6b04fe7e23
commit 43338ceeec
16 changed files with 287 additions and 97 deletions
+4 -6
View File
@@ -5,12 +5,15 @@ from shop.models import OrderLine, Tax, Product, Order, Customer
from django.db.models import QuerySet
def create_order_line_for_product(product: Product, quantity: Decimal, tax: Tax):
def create_order_line_for_product(
product: Product, quantity: Decimal, tax: Tax, order: Order
):
price = product.prices.last().price
base_total = round(price * quantity, 2)
taxes = round(base_total * (tax.value / Decimal("100")), 2)
return OrderLine.objects.create(
order=order,
product=product,
quantity=quantity,
price=price,
@@ -23,7 +26,6 @@ def create_order_line_for_product(product: Product, quantity: Decimal, tax: Tax)
def create_order(
customer: Customer,
lines: Iterable,
billing_address: str,
billing_city: str,
billing_state: str,
@@ -61,8 +63,4 @@ def create_order(
shipping_zip=shipping_zip,
)
for line in lines:
order.lines.add(line)
order.calculate_total_from_lines()
return order