Удалена система лояльности из модели Customer
Удалены поля loyalty_tier, is_vip, get_loyalty_discount(), increment_total_spent(). Поле total_spent оставлено для будущего расчёта по заказам. Обновлены admin, forms, views и шаблоны. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -26,20 +26,6 @@ class Customer(models.Model):
|
||||
# Temporary field to store raw phone number during initialization
|
||||
_raw_phone = None
|
||||
|
||||
# Loyalty program
|
||||
loyalty_tier = models.CharField(
|
||||
max_length=20,
|
||||
choices=[
|
||||
('no_discount', 'Без скидки'),
|
||||
('bronze', 'Бронза'),
|
||||
('silver', 'Серебро'),
|
||||
('gold', 'Золото'),
|
||||
('platinum', 'Платина'),
|
||||
],
|
||||
default='no_discount',
|
||||
verbose_name="Уровень лояльности"
|
||||
)
|
||||
|
||||
total_spent = models.DecimalField(
|
||||
max_digits=10,
|
||||
decimal_places=2,
|
||||
@@ -77,7 +63,6 @@ class Customer(models.Model):
|
||||
models.Index(fields=['email']),
|
||||
models.Index(fields=['phone']),
|
||||
models.Index(fields=['created_at']),
|
||||
models.Index(fields=['loyalty_tier']),
|
||||
]
|
||||
ordering = ['-created_at']
|
||||
|
||||
@@ -95,22 +80,6 @@ class Customer(models.Model):
|
||||
"""Полное имя клиента"""
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def is_vip(self):
|
||||
"""Проверяет, является ли клиент VIP на основе уровня лояльности"""
|
||||
return self.loyalty_tier in ("gold", "platinum")
|
||||
|
||||
def get_loyalty_discount(self):
|
||||
"""Возвращает скидку в зависимости от уровня лояльности"""
|
||||
discounts = {
|
||||
'no_discount': 0,
|
||||
'bronze': 0,
|
||||
'silver': 5, # 5%
|
||||
'gold': 10, # 10%
|
||||
'platinum': 15 # 15%
|
||||
}
|
||||
return discounts.get(self.loyalty_tier, 0)
|
||||
|
||||
def validate_unique(self, exclude=None):
|
||||
"""Переопределение для корректной проверки уникальности телефона при обновлениях"""
|
||||
# Снова нормализуем номер телефона перед проверкой уникальности
|
||||
@@ -234,13 +203,8 @@ class Customer(models.Model):
|
||||
defaults={
|
||||
"name": "АНОНИМНЫЙ ПОКУПАТЕЛЬ (POS)",
|
||||
"is_system_customer": True,
|
||||
"loyalty_tier": "no_discount",
|
||||
"notes": "SYSTEM_CUSTOMER - автоматически созданный клиент для анонимных покупок и наличных продаж",
|
||||
}
|
||||
)
|
||||
return customer, created
|
||||
|
||||
def increment_total_spent(self, amount):
|
||||
"""Увеличивает общую сумму покупок"""
|
||||
self.total_spent = self.total_spent + amount
|
||||
self.save(update_fields=['total_spent'])
|
||||
|
||||
Reference in New Issue
Block a user