Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("ecommerce", "0043_refund_request_status"),
]

operations = [
migrations.RemoveConstraint(
model_name="product",
name="unique_purchasable_object",
),
migrations.AddConstraint(
model_name="product",
constraint=models.UniqueConstraint(
fields=("object_id", "content_type"),
name="unique_purchasable_object",
),
),
]
3 changes: 1 addition & 2 deletions ecommerce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class Product(TimestampedModel):
class Meta:
constraints = [
models.UniqueConstraint(
fields=["object_id", "is_active", "content_type"],
condition=models.Q(is_active=True),
fields=["object_id", "content_type"],
name="unique_purchasable_object",
)
]
Expand Down
16 changes: 13 additions & 3 deletions ecommerce/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ def test_product_managers():
)


def test_product_multiple_active_for_single_purchasable_object():
"""Test that creating multiple Products with the same course/program
and are active is not allowed
def test_product_multiple_for_single_purchasable_object():
"""Test that creating multiple Products with the same course/program is not allowed,
regardless of active state.
"""
first_product = ProductFactory.create()
try:
Expand All @@ -341,6 +341,16 @@ def test_product_multiple_active_for_single_purchasable_object():
except IntegrityError:
pass

first_product.delete()
try:
with transaction.atomic():
ProductFactory.create(purchasable_object=first_product.purchasable_object)
pytest.fail(
"A Product was created for a purchasable_object that already has an inactive Product."
)
except IntegrityError:
pass


def test_order_update_reference_number(user):
"""Test when order is created/updated, reference_number is updated in db"""
Expand Down