35 lines
826 B
Python
35 lines
826 B
Python
from decimal import Decimal
|
|
|
|
from django.utils.timezone import now
|
|
|
|
from shop.models import Product, ProductPrice, Tax
|
|
|
|
|
|
class CreateProductsMixin:
|
|
def create_product(
|
|
self,
|
|
sku="000001",
|
|
name="Producto 1",
|
|
description="Descripción",
|
|
price=Decimal("10.00"),
|
|
is_shipping=False,
|
|
) -> Product:
|
|
tax, created = Tax.objects.get_or_create(
|
|
code="IVA",
|
|
value=21,
|
|
)
|
|
product = Product.objects.create(
|
|
sku=sku,
|
|
name=name,
|
|
description=description,
|
|
is_shipping_method=is_shipping,
|
|
)
|
|
ProductPrice.objects.create(
|
|
price=price,
|
|
product=product,
|
|
date=now(),
|
|
tax=tax,
|
|
current=True,
|
|
)
|
|
return product
|