chore: extracted product batch creation

This commit is contained in:
2024-05-24 20:55:49 +02:00
parent 4501ff8727
commit a6cf0dac93
3 changed files with 25 additions and 3 deletions
+8 -1
View File
@@ -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()