এরপর আইটি টিম মূল Discount মডেল তৈরি করল, যা বিভিন্ন ধরনের ডিসকাউন্ট নিয়ম সংজ্ঞায়িত করে:
class Discount(models.Model):
name = models.CharField(max_length=255, verbose_name="Discount Name")
code = models.CharField(max_length=50, verbose_name="Discount Code")
discount_type = models.ForeignKey(
DiscountType,
on_delete=models.CASCADE,
related_name='discounts',
verbose_name="Discount Type"
)
value = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Discount Value")
calculation_method = models.CharField(
max_length=10,
choices=[
('fixed', 'Fixed Amount'),
('percentage', 'Percentage'),
],
verbose_name="Calculation Method"
)
scope = models.CharField(
max_length=20,
choices=[
('product', 'Product'),
('category', 'Category'),
('all', 'All Products'),
],
verbose_name="Discount Scope"
)
valid_from = models.DateTimeField(verbose_name="Valid From")
valid_until = models.DateTimeField(verbose_name="Valid Until")
status = models.BooleanField(default=True, verbose_name="Is Active")
priority = models.IntegerField(default=0, verbose_name="Priority")
usage_limit = models.IntegerField(null=True, blank=True, verbose_name="Usage Limit")
min_purchase_amount = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name="Minimum Purchase Amount")
class Meta:
verbose_name = "Discount"
verbose_name_plural = "Discounts"
ordering = ['-priority', 'valid_from']
def __str__(self):
return f"{self.name} - {self.get_calculation_method_display()} {self.value}"
| id | name | code | discount_type_id | percentage | fixed_amount | buy_quantity | get_quantity | scope | valid_from | valid_until | minimum_order_amount | status | priority | is_combinable |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Eid Festival 10% Off | EID10 | 1 | 10.00 | 0.00 | 0 | 0 | GLOBAL | 2023-06-01 | 2023-06-30 | 0.00 | ACTIVE | 10 | False |
| 2 | 200 BDT Off on 2000+ | FLAT200 | 2 | 0.00 | 200.00 | 0 | 0 | GLOBAL | 2023-06-01 | NULL | 2000.00 | ACTIVE | 20 | False |
| 3 | Buy 3 Shirts Get 1 Free | SHIRT3G1 | 3 | 0.00 | 0.00 | 3 | 1 | ITEM_GROUP | 2023-06-01 | 2023-07-31 | 0.00 | ACTIVE | 30 | False |
| 4 | Buy More Save More | QTYTIER | 4 | 0.00 | 0.00 | 0 | 0 | GLOBAL | 2023-06-01 | NULL | 0.00 | ACTIVE | 15 | True |
| 5 | Combo Offer | COMBO1 | 5 | 15.00 | 0.00 | 0 | 0 | GLOBAL | 2023-06-01 | 2023-08-31 | 0.00 | ACTIVE | 25 | False |
| 6 | Premium Customer Discount | PREMIUM | 1 | 15.00 | 0.00 | 0 | 0 | CUSTOMER… | … | … | … | … | … | … |