feat: add profit and special discount fields to ProductVariant model
- Updated ProductVariant model to include 'profit' and 'special_discount_percent' fields. - Added corresponding fields in the admin interface for ProductVariant. - Created migration to add new fields to the database. feat: implement special discount code functionality in cart - Added composables for submitting and deleting special discount codes. - Updated CartSummary and CartItem components to handle special discount codes. - Enhanced API endpoints to support special discount operations. - Updated global types to include special discount code details in the cart.
This commit is contained in:
@@ -61,6 +61,15 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
# def groups(self):
|
||||
# return None
|
||||
|
||||
|
||||
def generate_special_code(self):
|
||||
"""Generate and save a unique special code for the user if missing."""
|
||||
# simple deterministic code based on phone and timestamp hash
|
||||
base = f"{self.phone}-{timezone.now().timestamp()}"
|
||||
code = hashlib.sha256(base.encode()).hexdigest()[:12].upper()
|
||||
|
||||
return code
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
if self.first_name and self.last_name:
|
||||
@@ -120,6 +129,14 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
return self.phone
|
||||
|
||||
|
||||
class SpecialDiscountCode(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.PROTECT, related_name='spital_code')
|
||||
code = models.CharField(max_length=12, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.user} - {self.code}'
|
||||
|
||||
|
||||
|
||||
class ShopModel(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='shop', verbose_name='کاربر')
|
||||
|
||||
Reference in New Issue
Block a user