feat: lots of stuff
This commit is contained in:
+47
-4
@@ -1,5 +1,7 @@
|
||||
from decimal import Decimal
|
||||
from shop.models import OrderLine, Tax, Product, Order
|
||||
from typing import Iterable
|
||||
|
||||
from shop.models import OrderLine, Tax, Product, Order, Customer
|
||||
from django.db.models import QuerySet
|
||||
|
||||
|
||||
@@ -19,10 +21,51 @@ def create_order_line_for_product(product: Product, quantity: Decimal, tax: Tax)
|
||||
)
|
||||
|
||||
|
||||
def create_order(lines: QuerySet):
|
||||
order = Order.objects.create()
|
||||
def create_order(
|
||||
customer: Customer,
|
||||
lines: Iterable,
|
||||
|
||||
for line in lines.all():
|
||||
billing_address: str,
|
||||
billing_city: str,
|
||||
billing_state: str,
|
||||
billing_country: str,
|
||||
billing_zip: str,
|
||||
|
||||
shipping_address: str = '',
|
||||
shipping_city: str = '',
|
||||
shipping_state: str = '',
|
||||
shipping_country: str = '',
|
||||
shipping_zip: str = '',
|
||||
) -> Order:
|
||||
billing_address = billing_address if billing_address else customer.address
|
||||
billing_city = billing_city if billing_city else customer.city
|
||||
billing_state = billing_state if billing_state else customer.state
|
||||
billing_country = billing_country if billing_country else customer.country
|
||||
billing_zip = billing_zip if billing_zip else customer.zip
|
||||
|
||||
shipping_address = shipping_address if shipping_address else billing_address
|
||||
shipping_city = shipping_city if shipping_city else billing_city
|
||||
shipping_state = shipping_state if shipping_state else billing_state
|
||||
shipping_country = shipping_country if shipping_country else billing_country
|
||||
shipping_zip = shipping_zip if shipping_zip else billing_zip
|
||||
|
||||
order = Order.objects.create(
|
||||
customer=customer,
|
||||
|
||||
billing_address=billing_address,
|
||||
billing_city=billing_city,
|
||||
billing_state=billing_state,
|
||||
billing_country=billing_country,
|
||||
billing_zip=billing_zip,
|
||||
|
||||
shipping_address=shipping_address,
|
||||
shipping_city=shipping_city,
|
||||
shipping_state=shipping_state,
|
||||
shipping_country=shipping_country,
|
||||
shipping_zip=shipping_zip,
|
||||
)
|
||||
|
||||
for line in lines:
|
||||
order.lines.add(line)
|
||||
|
||||
order.calculate_total_from_lines()
|
||||
|
||||
Reference in New Issue
Block a user