Vendor Coupon Create Serializer Documentation
VendorCouponCreateSerializer
Fields
- id: Integer, Auto-generated primary key.
- code: String, Unique alphanumeric coupon code (max length: 10, automatically uppercased).
- description: Text, Detailed description of the coupon (optional).
- discount_percent: Decimal, Discount percentage applied to the purchase (default: 0.00).
- money_value_off: Decimal, Fixed amount discount instead of a percentage (default: 0.00).
- total_issues: Integer, Maximum times this coupon can be issued.
- coupon_limit_per_customer: Integer, Maximum times a single customer can use this coupon.
- used_count: Integer, Number of times this coupon has been used.
- 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.
- is_active: Boolean, Status of the coupon (default: True).
- coupon_type: String, Determines if the coupon is a "Percentage Discount" or "Money Value Off".
Validations
- Code Validation:
- Must be alphanumeric (letters and numbers only).
- Cannot exceed 10 characters.
- Must be unique (case-insensitive check).
-
Automatically converted to uppercase.
-
User Role Validation:
- Only vendors can create coupons.
- Users with
vendor_rolemust have theCoupon Managementpermission. -
Vendor must have at least one shop.
-
Discount Validation:
- At least one of
discount_percentormoney_value_offmust be greater than zero. -
Cannot use both
discount_percentandmoney_value_offsimultaneously. -
Date Validation:
end_atmust be later thanstart_atif both are specified.
Create Logic
- Ensures only vendors can create coupons.
- Attaches the coupon to the vendor’s shop.
- Ensures
codeis stored in uppercase. - Sets
is_global = False(vendor-specific coupons only).
Coupon Type Determination
- If
discount_percent > 0, the coupon is categorized as "Percentage Discount". - If
money_value_off > 0, the coupon is categorized as "Money Value Off". - If neither applies, it defaults to "Unknown".
Error Handling
- Raises an error if the user is not a vendor.
- Raises an error if the vendor does not own a shop.
- Ensures coupon constraints are met before saving.
This documentation describes the VendorCouponCreateSerializer and its validation and processing logic for handling vendor coupon creation.