Compare commits

..

No commits in common. "1d50a9d2bc956c575f75035f1629d867b30bcc86" and "fb58889698ff4431c4b8eae5120dd88e0cb7f991" have entirely different histories.

5 changed files with 17 additions and 35 deletions

View File

@ -1,2 +0,0 @@
Branch: main
Commit: 29279bfd72a6fa296d1aa05a825bd88ca1f36c91

View File

@ -118,7 +118,7 @@ class CartRepository:
if now < s_date: if now < s_date:
return None, "This coupon code is not active yet." return None, "This coupon code is not active yet."
if now > e_date: if now > e_date:
return None, "This coupon code has expired." return None, "Invalid or expired coupon code."
if coupon.usage_limit > 0 and coupon.usage_count >= coupon.usage_limit: if coupon.usage_limit > 0 and coupon.usage_count >= coupon.usage_limit:
return None, "Coupon usage limit reached." return None, "Coupon usage limit reached."
metadata = getattr(coupon, "metadata_json", {}) if hasattr(coupon, "metadata_json") else {} metadata = getattr(coupon, "metadata_json", {}) if hasattr(coupon, "metadata_json") else {}
@ -127,16 +127,7 @@ class CartRepository:
currency_values = metadata.get("currency_values") if isinstance(metadata, dict) else None currency_values = metadata.get("currency_values") if isinstance(metadata, dict) else None
if isinstance(currency_values, dict) and currency.upper() in currency_values: if isinstance(currency_values, dict) and currency.upper() in currency_values:
value = Decimal(str(currency_values[currency.upper()])) value = Decimal(str(currency_values[currency.upper()]))
min_spend = Decimal(str(coupon.min_purchase_amount or 0)) return PricingCoupon(code=coupon.code, category=coupon.coupon_category, discount_type=coupon.discount_type, value=value, description=coupon.description, max_discount_limit=Decimal(coupon.max_discount_limit)), None
return PricingCoupon(
code=coupon.code,
category=coupon.coupon_category,
discount_type=coupon.discount_type,
value=value,
description=coupon.description,
max_discount_limit=Decimal(coupon.max_discount_limit or 0),
min_purchase_amount=min_spend,
), None
async def get_owned_categories(self, user_id: UUID) -> list[str]: async def get_owned_categories(self, user_id: UUID) -> list[str]:
rows = (await self.session.execute(select(UserEntitlement, Module).join(Module, Module.id == UserEntitlement.module_id).where(UserEntitlement.user_id == user_id, UserEntitlement.status == EntitlementStatus.ACTIVE))).all() rows = (await self.session.execute(select(UserEntitlement, Module).join(Module, Module.id == UserEntitlement.module_id).where(UserEntitlement.user_id == user_id, UserEntitlement.status == EntitlementStatus.ACTIVE))).all()

View File

@ -23,7 +23,6 @@ class PricingCoupon:
value: Decimal value: Decimal
description: str | None = None description: str | None = None
max_discount_limit: Decimal = Decimal("0") max_discount_limit: Decimal = Decimal("0")
min_purchase_amount: Decimal = Decimal("0")
class PricingEngine: class PricingEngine:
"""Preserves the legacy bundle/loyalty/fee rules while sourcing prices from commerce.access_plans.""" """Preserves the legacy bundle/loyalty/fee rules while sourcing prices from commerce.access_plans."""
@ -56,11 +55,6 @@ class PricingEngine:
coupon_discount = Decimal("0") coupon_discount = Decimal("0")
coupon_text = "None" coupon_text = "None"
if coupon: if coupon:
if coupon.min_purchase_amount > 0 and after_bundle < coupon.min_purchase_amount:
coupon_error = f"Minimum cart spend of {curr} {coupon.min_purchase_amount} required to use coupon {coupon.code}."
coupon_text = "None"
coupon_discount = Decimal("0")
else:
coupon_text = f"Code: {coupon.code} - {coupon.description or ''}".rstrip(" -") coupon_text = f"Code: {coupon.code} - {coupon.description or ''}".rstrip(" -")
if coupon.discount_type in {"flat", "flat_amount"}: if coupon.discount_type in {"flat", "flat_amount"}:
coupon_discount = min(coupon.value, after_bundle) coupon_discount = min(coupon.value, after_bundle)

View File

@ -17,8 +17,7 @@ dependencies = [
"uvicorn[standard]>=0.20.0", "uvicorn[standard]>=0.20.0",
"python-dotenv>=1.0.0", "python-dotenv>=1.0.0",
"PyYAML>=6.0", "PyYAML>=6.0",
"SQLAlchemy[asyncio]>=2.0.0", "SQLAlchemy>=2.0.0",
"greenlet>=3.0.0",
"asyncpg>=0.28.0", "asyncpg>=0.28.0",
"python-jose[cryptography]>=3.3.0", "python-jose[cryptography]>=3.3.0",
"passlib[bcrypt]>=1.7.4", "passlib[bcrypt]>=1.7.4",

View File

@ -57,8 +57,8 @@ class TestCartCurrencyResolution(unittest.IsolatedAsyncioTestCase):
)) ))
self.assertEqual(calc.currency, "USD") self.assertEqual(calc.currency, "USD")
self.assertEqual(calc.base_subtotal, 5.0) self.assertEqual(calc.base_subtotal, 5.0)
self.assertEqual(calc.convenience_fee, 0.0) self.assertEqual(calc.convenience_fee, 0.15)
self.assertEqual(calc.grand_total, 5.0) self.assertEqual(calc.grand_total, 5.15)
self.assertEqual(len(calc.cart_items), 1) self.assertEqual(len(calc.cart_items), 1)
self.assertEqual(calc.cart_items[0].code, "POINTS_ACU") self.assertEqual(calc.cart_items[0].code, "POINTS_ACU")
@ -69,9 +69,9 @@ class TestCartCurrencyResolution(unittest.IsolatedAsyncioTestCase):
)) ))
self.assertEqual(calc.currency, "INR") self.assertEqual(calc.currency, "INR")
self.assertEqual(calc.base_subtotal, 300.0) self.assertEqual(calc.base_subtotal, 300.0)
self.assertEqual(calc.convenience_fee, 0.0) self.assertEqual(calc.convenience_fee, 6.0)
self.assertEqual(calc.gst_amount, 0.0) self.assertEqual(calc.gst_amount, 1.08)
self.assertEqual(calc.grand_total, 300.0) self.assertEqual(calc.grand_total, 307.08)
async def test_multi_item_usd_cart(self): async def test_multi_item_usd_cart(self):
calc = await self.service.calculate(CartCalculationRequest( calc = await self.service.calculate(CartCalculationRequest(
@ -80,8 +80,8 @@ class TestCartCurrencyResolution(unittest.IsolatedAsyncioTestCase):
)) ))
self.assertEqual(calc.currency, "USD") self.assertEqual(calc.currency, "USD")
self.assertEqual(calc.base_subtotal, 8.0) self.assertEqual(calc.base_subtotal, 8.0)
self.assertEqual(calc.convenience_fee, 0.0) self.assertEqual(calc.convenience_fee, 0.24)
self.assertEqual(calc.grand_total, 8.0) self.assertEqual(calc.grand_total, 8.24)
self.assertEqual(len(calc.cart_items), 2) self.assertEqual(len(calc.cart_items), 2)
async def test_unknown_plan_raises_error(self): async def test_unknown_plan_raises_error(self):