Упрощение системы получателей доставки

- Удалено избыточное поле customer_is_recipient из модели Order
- Добавлено свойство @property is_customer_recipient для обратной совместимости
- Заменены радиокнопки recipient_mode на чекбокс 'Другой получатель' в форме
- Добавлено поле recipient_source для выбора между историей и новым получателем
- Обновлен AddressService.process_recipient_from_form() для работы с чекбоксом
- Обновлены шаблоны: order_form.html (чекбокс вместо радиокнопок) и order_detail.html
- Удалено customer_is_recipient из admin и demo команды
- Создана миграция для удаления поля customer_is_recipient

Логика упрощена: recipient is None = получатель = покупатель, иначе - отдельный получатель
This commit is contained in:
2025-12-24 17:54:57 +03:00
parent 9f4f03e340
commit d62caa924b
9 changed files with 168 additions and 82 deletions

View File

@@ -131,7 +131,7 @@
</div>
<!-- Получатель -->
{% if not order.customer_is_recipient and order.recipient %}
{% if order.recipient %}
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0">Получатель</h5>

View File

@@ -532,54 +532,74 @@
<div class="border-top pt-3 mt-3">
<h6 class="mb-3">Получатель</h6>
<!-- Режимы выбора получателя -->
<!-- Чекбокс "Другой получатель" -->
<div class="mb-3">
{% for choice in form.recipient_mode %}
<div class="form-check">
{{ choice.tag }}
<label class="form-check-label" for="{{ choice.id_for_label }}">
{{ choice.choice_label }}
{{ form.other_recipient }}
<label class="form-check-label" for="{{ form.other_recipient.id_for_label }}">
{{ form.other_recipient.label }}
</label>
{% if form.other_recipient.help_text %}
<small class="form-text text-muted">{{ form.other_recipient.help_text }}</small>
{% endif %}
</div>
{% endfor %}
{% if form.recipient_mode.errors %}
<div class="text-danger">{{ form.recipient_mode.errors }}</div>
{% if form.other_recipient.errors %}
<div class="text-danger">{{ form.other_recipient.errors }}</div>
{% endif %}
</div>
<!-- Выбор получателя из истории -->
<div class="mb-3" id="recipient-history-field" style="display: none;">
<label for="{{ form.recipient_from_history.id_for_label }}" class="form-label">
{{ form.recipient_from_history.label }}
</label>
{{ form.recipient_from_history }}
{% if form.recipient_from_history.errors %}
<div class="text-danger">{{ form.recipient_from_history.errors }}</div>
{% endif %}
</div>
<!-- Поля нового получателя -->
<div class="row" id="recipient-new-fields" style="display: none;">
<div class="col-md-6">
<div class="mb-3">
<label for="{{ form.recipient_name.id_for_label }}" class="form-label">
Имя получателя
<!-- Блок для другого получателя (показывается при включенном чекбоксе) -->
<div id="other-recipient-block" style="display: none;">
<!-- Режим выбора получателя (история или новый) -->
<div class="mb-3">
<label class="form-label d-block mb-2">{{ form.recipient_source.label }}</label>
{% for choice in form.recipient_source %}
<div class="form-check">
{{ choice.tag }}
<label class="form-check-label" for="{{ choice.id_for_label }}">
{{ choice.choice_label }}
</label>
{{ form.recipient_name }}
{% if form.recipient_name.errors %}
<div class="text-danger">{{ form.recipient_name.errors }}</div>
{% endif %}
</div>
{% endfor %}
{% if form.recipient_source.errors %}
<div class="text-danger">{{ form.recipient_source.errors }}</div>
{% endif %}
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="{{ form.recipient_phone.id_for_label }}" class="form-label">
Телефон получателя
</label>
{{ form.recipient_phone }}
{% if form.recipient_phone.errors %}
<div class="text-danger">{{ form.recipient_phone.errors }}</div>
{% endif %}
<!-- Выбор получателя из истории -->
<div class="mb-3" id="recipient-history-field" style="display: none;">
<label for="{{ form.recipient_from_history.id_for_label }}" class="form-label">
{{ form.recipient_from_history.label }}
</label>
{{ form.recipient_from_history }}
{% if form.recipient_from_history.errors %}
<div class="text-danger">{{ form.recipient_from_history.errors }}</div>
{% endif %}
</div>
<!-- Поля нового получателя -->
<div class="row" id="recipient-new-fields" style="display: none;">
<div class="col-md-6">
<div class="mb-3">
<label for="{{ form.recipient_name.id_for_label }}" class="form-label">
Имя получателя
</label>
{{ form.recipient_name }}
{% if form.recipient_name.errors %}
<div class="text-danger">{{ form.recipient_name.errors }}</div>
{% endif %}
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="{{ form.recipient_phone.id_for_label }}" class="form-label">
Телефон получателя
</label>
{{ form.recipient_phone }}
{% if form.recipient_phone.errors %}
<div class="text-danger">{{ form.recipient_phone.errors }}</div>
{% endif %}
</div>
</div>
</div>
</div>
@@ -971,31 +991,50 @@ document.addEventListener('DOMContentLoaded', function() {
syncUIFromCheckbox();
// Показ/скрытие полей получателя
const recipientModeRadios = document.querySelectorAll('input[name="recipient_mode"]');
const otherRecipientCheckbox = document.getElementById('{{ form.other_recipient.id_for_label }}');
const otherRecipientBlock = document.getElementById('other-recipient-block');
const recipientSourceRadios = document.querySelectorAll('input[name="recipient_source"]');
const recipientHistoryField = document.getElementById('recipient-history-field');
const recipientNewFields = document.getElementById('recipient-new-fields');
function toggleRecipientFields() {
const selectedMode = document.querySelector('input[name="recipient_mode"]:checked');
if (!selectedMode) return;
function toggleOtherRecipientBlock() {
if (otherRecipientCheckbox.checked) {
otherRecipientBlock.style.display = 'block';
toggleRecipientSourceFields();
} else {
otherRecipientBlock.style.display = 'none';
recipientHistoryField.style.display = 'none';
recipientNewFields.style.display = 'none';
}
}
const mode = selectedMode.value;
function toggleRecipientSourceFields() {
const selectedSource = document.querySelector('input[name="recipient_source"]:checked');
if (!selectedSource) return;
const source = selectedSource.value;
// Скрываем все поля
recipientHistoryField.style.display = 'none';
recipientNewFields.style.display = 'none';
// Показываем нужные поля
if (mode === 'history') {
if (source === 'history') {
recipientHistoryField.style.display = 'block';
} else if (mode === 'new') {
} else if (source === 'new') {
recipientNewFields.style.display = 'block';
}
// Для 'customer' ничего не показываем
}
recipientModeRadios.forEach(radio => {
radio.addEventListener('change', toggleRecipientFields);
// Обработчики событий
if (otherRecipientCheckbox) {
otherRecipientCheckbox.addEventListener('change', toggleOtherRecipientBlock);
// Инициализация при загрузке
toggleOtherRecipientBlock();
}
recipientSourceRadios.forEach(radio => {
radio.addEventListener('change', toggleRecipientSourceFields);
});
toggleRecipientFields();