feat: added creation endpoints
This commit is contained in:
+4
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user