diff --git a/myproject/customers/admin.py b/myproject/customers/admin.py index 4f98903..23249ab 100644 --- a/myproject/customers/admin.py +++ b/myproject/customers/admin.py @@ -3,24 +3,6 @@ from django.db import models from .models import Customer -class IsVipFilter(admin.SimpleListFilter): - title = 'VIP статус' - parameter_name = 'is_vip' - - def lookups(self, request, model_admin): - return ( - ('yes', 'VIP'), - ('no', 'Не VIP'), - ) - - def queryset(self, request, queryset): - if self.value() == 'yes': - return queryset.filter(loyalty_tier__in=['gold', 'platinum']) - if self.value() == 'no': - return queryset.exclude(loyalty_tier__in=['gold', 'platinum']) - return queryset - - class IsSystemCustomerFilter(admin.SimpleListFilter): title = 'Системный клиент' parameter_name = 'is_system_customer' @@ -46,15 +28,11 @@ class CustomerAdmin(admin.ModelAdmin): 'full_name', 'email', 'phone', - 'loyalty_tier', 'total_spent', - 'is_vip', 'is_system_customer', 'created_at' ) list_filter = ( - 'loyalty_tier', - IsVipFilter, IsSystemCustomerFilter, 'created_at' ) @@ -65,14 +43,14 @@ class CustomerAdmin(admin.ModelAdmin): ) date_hierarchy = 'created_at' ordering = ('-created_at',) - readonly_fields = ('created_at', 'updated_at', 'total_spent', 'is_vip', 'is_system_customer') + readonly_fields = ('created_at', 'updated_at', 'total_spent', 'is_system_customer') fieldsets = ( ('Основная информация', { 'fields': ('name', 'email', 'phone', 'is_system_customer') }), - ('Программа лояльности', { - 'fields': ('loyalty_tier', 'total_spent', 'is_vip'), + ('Статистика покупок', { + 'fields': ('total_spent',), 'classes': ('collapse',) }), ('Заметки', { @@ -88,7 +66,7 @@ class CustomerAdmin(admin.ModelAdmin): """Делаем все поля read-only для системного клиента""" if obj and obj.is_system_customer: # Для системного клиента все поля только для чтения - return ['name', 'email', 'phone', 'loyalty_tier', 'total_spent', 'is_vip', 'is_system_customer', 'notes', 'created_at', 'updated_at'] + return ['name', 'email', 'phone', 'total_spent', 'is_system_customer', 'notes', 'created_at', 'updated_at'] return self.readonly_fields def has_delete_permission(self, request, obj=None): diff --git a/myproject/customers/forms.py b/myproject/customers/forms.py index e0b6f98..55ba3c9 100644 --- a/myproject/customers/forms.py +++ b/myproject/customers/forms.py @@ -14,7 +14,7 @@ class CustomerForm(forms.ModelForm): class Meta: model = Customer - fields = ['name', 'email', 'phone', 'loyalty_tier', 'notes'] + fields = ['name', 'email', 'phone', 'notes'] exclude = ['is_system_customer'] widgets = { 'notes': forms.Textarea(attrs={'rows': 3}), @@ -30,12 +30,6 @@ class CustomerForm(forms.ModelForm): if field_name == 'notes': # Textarea already has rows=3 from widget, just add class field.widget.attrs.update({'class': 'form-control'}) - elif field_name == 'loyalty_tier': - # Select fields need form-select class - field.widget.attrs.update({'class': 'form-select'}) - elif field_name == 'phone': - # Phone field gets form-control class - field.widget.attrs.update({'class': 'form-control'}) else: # Regular input fields get form-control class field.widget.attrs.update({'class': 'form-control'}) diff --git a/myproject/customers/models.py b/myproject/customers/models.py index 444f651..8405c87 100644 --- a/myproject/customers/models.py +++ b/myproject/customers/models.py @@ -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']) diff --git a/myproject/customers/templates/customers/customer_detail.html b/myproject/customers/templates/customers/customer_detail.html index 2bb82fe..643ac1b 100644 --- a/myproject/customers/templates/customers/customer_detail.html +++ b/myproject/customers/templates/customers/customer_detail.html @@ -38,34 +38,10 @@ Телефон: {{ customer.phone|default:"Не указано" }} - - Уровень лояльности: - - ({{ customer.get_loyalty_discount }}% скидка) - - {{ customer.get_loyalty_tier_display }} - - - Сумма покупок: {{ customer.total_spent|floatformat:2 }} руб. - - VIP: - - {% if customer.is_vip %} - Да - {% else %} - Нет - {% endif %} - - Заметки: {{ customer.notes|default:"Нет" }} diff --git a/myproject/customers/templates/customers/customer_list.html b/myproject/customers/templates/customers/customer_list.html index 55aeaf5..ada842c 100644 --- a/myproject/customers/templates/customers/customer_list.html +++ b/myproject/customers/templates/customers/customer_list.html @@ -81,16 +81,13 @@ Имя Email Телефон - Уровень лояльности Сумма покупок - VIP Действия {% for customer in page_obj %} - @@ -98,33 +95,12 @@ {{ customer.email|default:'—' }} {{ customer.phone|default:'—' }} - - - {{ customer.get_loyalty_tier_display }} - - - {{ customer.total_spent|default:0|floatformat:2 }} руб. - - {% if customer.is_vip %} - Да - {% else %} - Нет - {% endif %} - - - 👁 - diff --git a/myproject/customers/views.py b/myproject/customers/views.py index 97d4a33..ccedc4f 100644 --- a/myproject/customers/views.py +++ b/myproject/customers/views.py @@ -413,7 +413,6 @@ def api_create_customer(request): 'name': name, 'phone': phone if phone else None, 'email': email if email else None, - 'loyalty_tier': 'no_discount', # Значение по умолчанию для новых клиентов } # Используем форму для валидации и создания