Исправление проблем с сохранением адреса, получателя и даты доставки

- Исправлено: адрес теперь сохраняется для черновиков заказов
- Исправлено: получатель корректно предзаполняется при редактировании заказа
- Исправлено: адрес при редактировании отображается в режиме 'новый' для возможности редактирования
- Исправлено: дата доставки корректно предзаполняется при редактировании заказа
- Исправлено: при редактировании получателя обновляется существующий объект вместо создания нового
- Улучшена логика обработки Delivery для черновиков (создание с опциональными полями)
- Улучшена логика обновления получателя через загрузку заказа из БД с select_related
This commit is contained in:
2025-12-25 00:30:27 +03:00
parent 98470c83af
commit 298d797286
5 changed files with 192 additions and 91 deletions

View File

@@ -585,25 +585,6 @@
</div>
</div>
<!-- Дополнительно -->
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-three-dots"></i> Дополнительно</h5>
</div>
<div class="card-body">
<div class="mb-3 form-check">
{{ form.is_anonymous }}
<label class="form-check-label" for="{{ form.is_anonymous.id_for_label }}">
Анонимная доставка
</label>
</div>
<div class="mb-3">
<label for="{{ form.special_instructions.id_for_label }}" class="form-label">Особые пожелания</label>
{{ form.special_instructions }}
</div>
</div>
</div>
<!-- Получатель -->
<div class="card mb-3">
<div class="card-header">
@@ -613,7 +594,10 @@
<!-- Чекбокс "Другой получатель" -->
<div class="mb-3">
<div class="form-check">
{{ form.other_recipient }}
<input type="checkbox" class="form-check-input"
id="{{ form.other_recipient.id_for_label }}"
name="{{ form.other_recipient.html_name }}"
{% if form.other_recipient.value or form.other_recipient.field.initial %}checked{% endif %}>
<label class="form-check-label" for="{{ form.other_recipient.id_for_label }}">
{{ form.other_recipient.label }}
</label>
@@ -683,6 +667,25 @@
</div>
</div>
</div>
<!-- Дополнительно -->
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-three-dots"></i> Дополнительно</h5>
</div>
<div class="card-body">
<div class="mb-3 form-check">
{{ form.is_anonymous }}
<label class="form-check-label" for="{{ form.is_anonymous.id_for_label }}">
Анонимная доставка
</label>
</div>
<div class="mb-3">
<label for="{{ form.special_instructions.id_for_label }}" class="form-label">Особые пожелания</label>
{{ form.special_instructions }}
</div>
</div>
</div>
</form>
</div>
<!-- Конец левой колонки -->
@@ -935,6 +938,22 @@ document.addEventListener('DOMContentLoaded', function() {
<!-- Delivery Date/Time Widget -->
<script src="{% static 'orders/js/delivery_datetime.js' %}"></script>
<script>
// Убеждаемся, что дата доставки правильно отображается при редактировании
document.addEventListener('DOMContentLoaded', function() {
const deliveryDateField = document.getElementById('{{ form.delivery_date.id_for_label }}');
{% if form.delivery_date.initial %}
if (deliveryDateField && !deliveryDateField.value) {
// Если поле пустое, но есть initial значение, устанавливаем его
const initialDate = '{{ form.delivery_date.initial|date:"Y-m-d" }}';
if (initialDate && initialDate !== 'None') {
deliveryDateField.value = initialDate;
console.log('[Delivery Date] Установлена дата из initial:', initialDate);
}
}
{% endif %}
});
</script>
<!-- Unified Transaction Form -->
<script src="{% static 'orders/js/unified_transaction_form.js' %}"></script>
@@ -1099,8 +1118,17 @@ document.addEventListener('DOMContentLoaded', function() {
// Обработчики событий
if (otherRecipientCheckbox) {
otherRecipientCheckbox.addEventListener('change', toggleOtherRecipientBlock);
// Инициализация при загрузке
toggleOtherRecipientBlock();
// Инициализация при загрузке - проверяем checked состояние
// Используем DOMContentLoaded чтобы убедиться, что DOM полностью загружен
// Но также проверяем сразу, если DOM уже загружен
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
toggleOtherRecipientBlock();
});
} else {
// DOM уже загружен
toggleOtherRecipientBlock();
}
}
recipientSourceRadios.forEach(radio => {