Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make cost_price less than price
oldPadavan9de14d8c4655
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex da4d53a173..7f38b78d1a 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -2,6 +2,7 @@ import itertoolsimport osimport randomimport unicodedata+from decimal import Decimalfrom django.conf import settingsfrom django.contrib.auth.models import Group, Permission@@ -301,10 +302,12 @@ def create_variant(product, **kwargs):defaults = {'product': product,'quantity': fake.random_int(1, 50),- 'cost_price': fake.money(),'quantity_allocated': fake.random_int(1, 50)}defaults.update(kwargs)variant = ProductVariant(**defaults)+ if 'cost_price' not in kwargs:+ variant.cost_price = (variant.base_price * Decimal(+ fake.random_int(10, 99) / 100)).quantize()if variant.attributes:variant.name = get_name_from_attributes(variant)variant.save()diff --git a/tests/test_core.py b/tests/test_core.pyindex db017903e5..8f3dd82a4c 100644--- a/tests/test_core.py+++ b/tests/test_core.py@@ -4,6 +4,7 @@ from unittest.mock import Mock, patchimport pytestfrom django.conf import settings+from django.db.models import Case, F, Whenfrom django.shortcuts import reversefrom django.urls import translate_urlfrom prices import Money@@ -16,7 +17,7 @@ from saleor.core.utils import (from saleor.core.utils.text import get_cleaner, strip_htmlfrom saleor.discount.models import Sale, Voucherfrom saleor.order.models import Order-from saleor.product.models import Product, ProductImage+from saleor.product.models import Product, ProductImage, ProductVariantfrom saleor.shipping.models import ShippingMethodtype_schema = {@@ -145,6 +146,11 @@ def test_create_products_by_type(how_many=how_many, create_images=True)assert Product.objects.all().count() == how_manyassert mock_create_thumbnails.called+ assert ProductVariant.objects.annotate(+ base_price=Case(+ When(price_override__lt=0, then='price_override'),+ default='product__price')).\+ filter(base_price__lt=F('cost_price')).count() == 0def test_create_fake_order(db, monkeypatch, product_image):