Checkout Serializer Documentation
CouponCode
Fields:
- id: Integer, Auto-generated primary key.
- code: String, Unique code for the coupon (max length: 255, automatically uppercased).
- description: Text, Detailed description of the coupon (optional).
- discount_percent: Decimal, Discount percentage offered by the coupon (default: 0.00).
- money_value_off: Decimal, Fixed amount discount instead of a percentage (default: 0.00).
- total_issues: Integer, Total number of times the coupon can be issued (default: 0).
- coupon_limit_per_customer: Integer, Maximum times a single customer can use this coupon (default: 1).
- used_count: Integer, Number of times this coupon has been used (default: 0).
- total_used: Integer, Total times the coupon has been applied across all users.
- start_at: DateTime, Start date of coupon validity (optional).
- end_at: DateTime, End date of coupon validity (optional).
- min_purchase: Decimal, Minimum purchase amount required to apply the coupon (default: 0.00).
- is_active: Boolean, Status of the coupon (default: True).
- shop: Foreign Key (nullable), Links to the Shop model if the coupon is vendor-specific.
- is_global: Boolean, Indicates if the coupon is available for all shops (default: False).
- created_at: DateTime, Timestamp of coupon creation (auto-generated).
- updated_at: DateTime, Timestamp of last update (auto-generated).
Validations:
- Coupon must be active.
- Today's date must fall between
start_at and end_at if specified.
CouponClaim
Fields:
- id: Integer, Auto-generated primary key.
- code: ForeignKey, Related to
CouponCode.
- user: ForeignKey, Related to
User (read-only email).
- is_claimed: Boolean, Claim status (default: False).
- claimed_at: DateTime, Timestamp of when the coupon was claimed (auto-generated).
Validations:
- A user cannot claim the same coupon twice.
- Coupon must be active.
- Coupon's
end_at must not be exceeded.
Create Logic:
- Automatically sets
is_claimed to True during creation.
ApplyCoupon
Fields:
- id: Integer, Auto-generated primary key.
- user: ForeignKey, Related to
User (read-only email).
- applied_coupon: ForeignKey, Related to
CouponClaim (tracks the claimed coupon).
- shop: ForeignKey (nullable), Related to
Shop, if the coupon is shop-specific.
- coupon_code: String, Coupon code entered by the user (write-only).
- total_purchased: Decimal, Total purchase amount before applying the coupon.
- discounted_amount: Decimal, Calculated discount amount applied to the order.
- grand_total: Decimal, Final payable amount after applying the discount.
- has_applied: Boolean, Indicates if the coupon has been successfully applied (default: False).
- applied_at: DateTime, Timestamp of when the coupon was applied (auto-generated).
Validations:
- Coupon code must exist.
- The user must claim the coupon before applying.
- Coupon must not be expired.
- Total purchase amount must meet or exceed the minimum purchase required.
Create Logic:
- Updates an existing record or creates a new one.
- Calculates
discounted_amount and net_amount based on the coupon's discount percentage.
ProductPurchased
Fields:
- id: Integer, Auto-generated primary key.
- user: ForeignKey, Related to
User.
- applied_coupon: ForeignKey (nullable), Related to
ApplyCoupon, tracking the applied coupon.
- shop: ForeignKey (nullable), Related to
Shop, if the purchase is vendor-specific.
- total_purchased: Decimal, Total purchase amount before any discounts.
- discounted_amount: Decimal, Discount amount applied to the order.
- grand_total: Decimal, Final amount payable after applying discounts.
- payment_status: Boolean, Indicates if the payment was successful (default: False).
- has_purchased_succeed: Boolean, Indicates if the purchase was successfully completed (default: False).
- purchased_at: DateTime, Timestamp of when the purchase was completed (auto-generated).
Validations:
- The coupon must be claimed.
- Total purchase must meet the coupon's minimum requirement.
Create Logic:
- Updates or creates purchase records.
- Calculates
discounted_amount and net_amount based on the coupon.
PurchasedCartItem
Fields:
- id: Integer, Auto-generated primary key.
- purchased_product: ForeignKey, Related to
ProductPurchased.
- cart_item: ForeignKey, Related to
CartItem.
- status: Boolean, Indicates if the item has been purchased (default: False).
- created_at: DateTime, Creation timestamp.
- updated_at: DateTime, Last updated timestamp.
- variant_details: Nested field containing product name, size, and image.
Validations:
- Cart item must belong to the requesting user.
- Product variant must have sufficient stock.
- Purchased product must not be marked as successfully purchased.
- Existing purchased items cannot be modified.
Create Logic:
- Updates an existing purchased cart item or creates a new one.
- Generates unique order IDs for new purchases.