chore: extracted product batch creation
This commit is contained in:
+8
-1
@@ -1,6 +1,6 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from shop.models import OrderLine, Product, Order, Customer
|
||||
from shop.models import OrderLine, Product, Order, Customer, ProductBatch
|
||||
|
||||
|
||||
def create_order_line_for_product(product: Product, quantity: Decimal, order: Order):
|
||||
@@ -61,3 +61,10 @@ def create_order(
|
||||
)
|
||||
|
||||
return order
|
||||
|
||||
|
||||
def delete_product_batch(batch: ProductBatch):
|
||||
product = batch.product
|
||||
product.stock = max(product.stock - batch.quantity, 0)
|
||||
product.save()
|
||||
batch.delete()
|
||||
|
||||
Reference in New Issue
Block a user