Feature: Добавлены методы получения суммы заказов клиента

Добавлены методы в модель Customer для расчета суммы успешных заказов:
- get_successful_orders_total() - гибкий метод с фильтрацией по датам
- get_last_year_orders_total() - сумма за последний год

Удалено устаревшее поле total_spent:
- Методы предоставляют более точные и актуальные данные
- Используют агрегацию на уровне БД для производительности

Обновлен UI карточки клиента:
- Отображается сумма всех успешных заказов
- Отображается сумма заказов за последний год
- Убрана колонка total_spent из списка клиентов

Изменения:
- customers/models.py: добавлены методы, удалено поле total_spent
- customers/views.py: добавлен расчет сумм в контекст
- customers/templates: обновлены шаблоны
- customers/admin.py: удалены упоминания total_spent
- Создана миграция 0005_remove_total_spent

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-06 00:21:45 +03:00
parent 2f7fed4a1a
commit 8d50613876
6 changed files with 83 additions and 19 deletions

View File

@@ -39,8 +39,12 @@
<td>{{ customer.phone|default:"Не указано" }}</td>
</tr>
<tr>
<th>Сумма покупок:</th>
<td>{{ customer.total_spent|floatformat:2 }} руб.</td>
<th>Сумма всех успешных заказов:</th>
<td><strong>{{ total_orders_sum|floatformat:2 }} руб.</strong></td>
</tr>
<tr>
<th>Сумма заказов за последний год:</th>
<td><strong>{{ last_year_orders_sum|floatformat:2 }} руб.</strong></td>
</tr>
<tr>
<th>Общий долг по активным заказам:</th>

View File

@@ -81,7 +81,6 @@
<th>Имя</th>
<th>Email</th>
<th>Телефон</th>
<th>Сумма покупок</th>
<th class="text-end">Действия</th>
</tr>
</thead>
@@ -95,8 +94,6 @@
<td>{{ customer.email|default:'—' }}</td>
<td>{{ customer.phone|default:'—' }}</td>
<td>{{ customer.total_spent|default:0|floatformat:2 }} руб.</td>
<td class="text-end" onclick="event.stopPropagation();">
<a href="{% url 'customers:customer-detail' customer.pk %}"
class="btn btn-sm btn-outline-primary">👁</a>