1. Home
  2. Erp
  3. Discounts
  4. ২. ডিসকাউন্ট (Discount) মডেল

২. ডিসকাউন্ট (Discount) মডেল

এরপর আইটি টিম মূল 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}"

idnamecodediscount_type_idpercentagefixed_amountbuy_quantityget_quantityscopevalid_fromvalid_untilminimum_order_amountstatuspriorityis_combinable
1Eid Festival 10% OffEID10110.000.0000GLOBAL2023-06-012023-06-300.00ACTIVE10False
2200 BDT Off on 2000+FLAT20020.00200.0000GLOBAL2023-06-01NULL2000.00ACTIVE20False
3Buy 3 Shirts Get 1 FreeSHIRT3G130.000.0031ITEM_GROUP2023-06-012023-07-310.00ACTIVE30False
4Buy More Save MoreQTYTIER40.000.0000GLOBAL2023-06-01NULL0.00ACTIVE15True
5Combo OfferCOMBO1515.000.0000GLOBAL2023-06-012023-08-310.00ACTIVE25False
6Premium Customer DiscountPREMIUM115.000.0000CUSTOMER…

How can we help?