Compare commits
10 Commits
5a66d492c8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dc397b3ce | |||
| 9a7c0728f0 | |||
| 67ad0e50ee | |||
| 32bc0d2c39 | |||
| f140469a56 | |||
| d947f4eee7 | |||
| 5700314b10 | |||
| b24a0d9f21 | |||
| 034be20a5a | |||
| f75e861bb8 |
@@ -162,8 +162,6 @@ class ShowcaseManager:
|
|||||||
Raises:
|
Raises:
|
||||||
IntegrityError: если экземпляр уже был продан (защита на уровне БД)
|
IntegrityError: если экземпляр уже был продан (защита на уровне БД)
|
||||||
"""
|
"""
|
||||||
from inventory.services.sale_processor import SaleProcessor
|
|
||||||
|
|
||||||
sold_count = 0
|
sold_count = 0
|
||||||
order = order_item.order
|
order = order_item.order
|
||||||
|
|
||||||
@@ -207,17 +205,9 @@ class ShowcaseManager:
|
|||||||
|
|
||||||
# Сначала устанавливаем order_item для правильного определения цены
|
# Сначала устанавливаем order_item для правильного определения цены
|
||||||
reservation.order_item = order_item
|
reservation.order_item = order_item
|
||||||
reservation.save()
|
# ВАЖНО: Мы НЕ создаём продажу (Sale) здесь и НЕ меняем статус на 'converted_to_sale'.
|
||||||
|
# Это сделает сигнал create_sale_on_order_completion автоматически.
|
||||||
# Теперь создаём продажу с правильной ценой из OrderItem
|
# Таким образом обеспечивается единая точка создания продаж для всех типов товаров.
|
||||||
SaleProcessor.create_sale_from_reservation(
|
|
||||||
reservation=reservation,
|
|
||||||
order=order
|
|
||||||
)
|
|
||||||
|
|
||||||
# Обновляем статус резерва
|
|
||||||
reservation.status = 'converted_to_sale'
|
|
||||||
reservation.converted_at = timezone.now()
|
|
||||||
reservation.save()
|
reservation.save()
|
||||||
|
|
||||||
sold_count += 1
|
sold_count += 1
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs):
|
|||||||
# === ЗАЩИТА ОТ ПРЕЖДЕВРЕМЕННОГО СОЗДАНИЯ SALE ===
|
# === ЗАЩИТА ОТ ПРЕЖДЕВРЕМЕННОГО СОЗДАНИЯ SALE ===
|
||||||
# Проверяем, есть ли уже Sale для этого заказа
|
# Проверяем, есть ли уже Sale для этого заказа
|
||||||
if Sale.objects.filter(order=instance).exists():
|
if Sale.objects.filter(order=instance).exists():
|
||||||
logger.info(f"✓ Заказ {instance.order_number}: Sale уже существуют, пропускаем")
|
logger.info(f"Заказ {instance.order_number}: Sale уже существуют, пропускаем")
|
||||||
update_is_returned_flag(instance)
|
update_is_returned_flag(instance)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs):
|
|||||||
previous_status = getattr(instance, '_previous_status', None)
|
previous_status = getattr(instance, '_previous_status', None)
|
||||||
if previous_status and previous_status.is_positive_end:
|
if previous_status and previous_status.is_positive_end:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"🔄 Заказ {instance.order_number}: повторный переход в положительный статус "
|
f"Заказ {instance.order_number}: повторный переход в положительный статус "
|
||||||
f"({previous_status.name} → {instance.status.name}). Проверяем Sale..."
|
f"({previous_status.name} → {instance.status.name}). Проверяем Sale..."
|
||||||
)
|
)
|
||||||
if Sale.objects.filter(order=instance).exists():
|
if Sale.objects.filter(order=instance).exists():
|
||||||
@@ -454,13 +454,66 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs):
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# === РАСЧЕТ ЦЕНЫ ===
|
||||||
|
# Рассчитываем фактическую стоимость продажи всего комплекта с учетом скидок
|
||||||
|
# 1. Базовая стоимость позиции
|
||||||
|
item_subtotal = Decimal(str(item.price)) * Decimal(str(item.quantity))
|
||||||
|
|
||||||
|
# 2. Скидки
|
||||||
|
item_discount = Decimal(str(item.discount_amount)) if item.discount_amount is not None else Decimal('0')
|
||||||
|
|
||||||
|
# Скидка на заказ (распределенная)
|
||||||
|
instance.refresh_from_db()
|
||||||
|
order_total = instance.subtotal if hasattr(instance, 'subtotal') else Decimal('0')
|
||||||
|
delivery_cost = Decimal(str(instance.delivery.cost)) if hasattr(instance, 'delivery') and instance.delivery else Decimal('0')
|
||||||
|
order_discount_amount = (order_total - (Decimal(str(instance.total_amount)) - delivery_cost)) if order_total > 0 else Decimal('0')
|
||||||
|
|
||||||
|
if order_total > 0 and order_discount_amount > 0:
|
||||||
|
item_order_discount = order_discount_amount * (item_subtotal / order_total)
|
||||||
|
else:
|
||||||
|
item_order_discount = Decimal('0')
|
||||||
|
|
||||||
|
kit_net_total = item_subtotal - item_discount - item_order_discount
|
||||||
|
if kit_net_total < 0:
|
||||||
|
kit_net_total = Decimal('0')
|
||||||
|
|
||||||
|
# 3. Суммарная каталожная стоимость всех компонентов (для пропорции)
|
||||||
|
total_catalog_price = Decimal('0')
|
||||||
|
for reservation in kit_reservations:
|
||||||
|
qty = reservation.quantity_base or reservation.quantity
|
||||||
|
price = reservation.product.actual_price or Decimal('0')
|
||||||
|
total_catalog_price += price * qty
|
||||||
|
|
||||||
|
# 4. Коэффициент распределения
|
||||||
|
if total_catalog_price > 0:
|
||||||
|
ratio = kit_net_total / total_catalog_price
|
||||||
|
else:
|
||||||
|
# Если каталожная цена 0, распределяем просто по количеству или 0
|
||||||
|
ratio = Decimal('0')
|
||||||
|
|
||||||
# Создаем Sale для каждого компонента комплекта
|
# Создаем Sale для каждого компонента комплекта
|
||||||
for reservation in kit_reservations:
|
for reservation in kit_reservations:
|
||||||
try:
|
try:
|
||||||
# Рассчитываем цену продажи компонента пропорционально цене комплекта
|
# Рассчитываем цену продажи компонента пропорционально
|
||||||
# Используем actual_price компонента как цену продажи
|
catalog_price = reservation.product.actual_price or Decimal('0')
|
||||||
component_sale_price = reservation.product.actual_price
|
|
||||||
|
|
||||||
|
if ratio > 0:
|
||||||
|
# Распределяем реальную выручку
|
||||||
|
component_sale_price = catalog_price * ratio
|
||||||
|
else:
|
||||||
|
# Если выручка 0 или каталожные цены 0
|
||||||
|
if total_catalog_price == 0 and kit_net_total > 0:
|
||||||
|
# Крайний случай: товаров на 0 руб, а продали за деньги (услуга?)
|
||||||
|
# Распределяем равномерно
|
||||||
|
count = kit_reservations.count()
|
||||||
|
component_qty = reservation.quantity_base or reservation.quantity
|
||||||
|
if count > 0 and component_qty > 0:
|
||||||
|
component_sale_price = (kit_net_total / count) / component_qty
|
||||||
|
else:
|
||||||
|
component_sale_price = Decimal('0')
|
||||||
|
else:
|
||||||
|
component_sale_price = Decimal('0')
|
||||||
|
|
||||||
sale = SaleProcessor.create_sale(
|
sale = SaleProcessor.create_sale(
|
||||||
product=reservation.product,
|
product=reservation.product,
|
||||||
warehouse=warehouse,
|
warehouse=warehouse,
|
||||||
@@ -472,7 +525,8 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs):
|
|||||||
sales_created.append(sale)
|
sales_created.append(sale)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"✓ Sale создан для компонента комплекта '{kit.name}': "
|
f"✓ Sale создан для компонента комплекта '{kit.name}': "
|
||||||
f"{reservation.product.name} - {reservation.quantity_base or reservation.quantity} шт. (базовых единиц)"
|
f"{reservation.product.name} - {reservation.quantity_base or reservation.quantity} шт. "
|
||||||
|
f"(цена: {component_sale_price})"
|
||||||
)
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -548,6 +602,21 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs):
|
|||||||
else:
|
else:
|
||||||
base_price = price_with_discount
|
base_price = price_with_discount
|
||||||
|
|
||||||
|
# LOGGING DEBUG INFO
|
||||||
|
# print(f"DEBUG SALE PRICE CALCULATION for Item #{item.id} ({product.name}):")
|
||||||
|
# print(f" Price: {item.price}, Qty: {item.quantity}, Subtotal: {item_subtotal}")
|
||||||
|
# print(f" Item Discount: {item_discount}, Order Discount Share: {item_order_discount}, Total Discount: {total_discount}")
|
||||||
|
# print(f" Price w/ Discount: {price_with_discount}")
|
||||||
|
# print(f" Sales Unit: {item.sales_unit}, Conversion: {item.conversion_factor_snapshot}")
|
||||||
|
# print(f" FINAL BASE PRICE: {base_price}")
|
||||||
|
# print(f" Sales Unit Object: {item.sales_unit}")
|
||||||
|
# if item.sales_unit:
|
||||||
|
# print(f" Sales Unit Conversion: {item.sales_unit.conversion_factor}")
|
||||||
|
|
||||||
|
logger.info(f"DEBUG SALE PRICE CALCULATION for Item #{item.id} ({product.name}):")
|
||||||
|
logger.info(f" Price: {item.price}, Qty: {item.quantity}, Subtotal: {item_subtotal}")
|
||||||
|
logger.info(f" FINAL BASE PRICE: {base_price}")
|
||||||
|
|
||||||
# Создаем Sale (с автоматическим FIFO-списанием)
|
# Создаем Sale (с автоматическим FIFO-списанием)
|
||||||
sale = SaleProcessor.create_sale(
|
sale = SaleProcessor.create_sale(
|
||||||
product=product,
|
product=product,
|
||||||
|
|||||||
@@ -394,14 +394,21 @@
|
|||||||
const emptyMessage = document.getElementById('empty-lines-message');
|
const emptyMessage = document.getElementById('empty-lines-message');
|
||||||
if (emptyMessage) emptyMessage.remove();
|
if (emptyMessage) emptyMessage.remove();
|
||||||
|
|
||||||
// Добавляем новую строку
|
// Добавляем новую строку в начало таблицы
|
||||||
const newRow = self.createLineRow(data.line);
|
const newRow = self.createLineRow(data.line);
|
||||||
tbody.appendChild(newRow);
|
tbody.insertBefore(newRow, tbody.firstChild);
|
||||||
|
|
||||||
// Включаем кнопку завершения
|
// Включаем кнопку завершения
|
||||||
const completeBtn = document.getElementById('complete-inventory-btn');
|
const completeBtn = document.getElementById('complete-inventory-btn');
|
||||||
if (completeBtn) completeBtn.disabled = false;
|
if (completeBtn) completeBtn.disabled = false;
|
||||||
|
|
||||||
|
// Фокус на поле ввода количества в новой строке
|
||||||
|
const quantityInput = newRow.querySelector('.quantity-fact-input');
|
||||||
|
if (quantityInput) {
|
||||||
|
quantityInput.focus();
|
||||||
|
quantityInput.select();
|
||||||
|
}
|
||||||
|
|
||||||
this.showNotification('Товар добавлен', 'success');
|
this.showNotification('Товар добавлен', 'success');
|
||||||
} else {
|
} else {
|
||||||
this.showNotification('Ошибка: ' + (data.error || 'Не удалось добавить товар'), 'error');
|
this.showNotification('Ошибка: ' + (data.error || 'Не удалось добавить товар'), 'error');
|
||||||
|
|||||||
@@ -20,19 +20,22 @@
|
|||||||
<div class="row g-3">
|
<div class="row g-3">
|
||||||
<!-- Основной контент - одна колонка -->
|
<!-- Основной контент - одна колонка -->
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<!-- Информация о документе -->
|
<!-- Информация о документе - свернута по умолчанию -->
|
||||||
<div class="card border-0 shadow-sm mb-3">
|
<div class="card border-0 shadow-sm mb-3">
|
||||||
<div class="card-header bg-light py-3 d-flex justify-content-between align-items-center">
|
<div class="card-header bg-light py-2 d-flex justify-content-between align-items-center">
|
||||||
<h5 class="mb-0">
|
<button class="btn btn-outline-primary btn-sm d-flex align-items-center gap-2" type="button" data-bs-toggle="collapse" data-bs-target="#document-info-collapse" aria-expanded="false" aria-controls="document-info-collapse">
|
||||||
<i class="bi bi-file-earmark-plus me-2"></i>{{ document.document_number }}
|
<i class="bi bi-chevron-down" id="document-info-collapse-icon"></i>
|
||||||
{% if document.status == 'draft' %}
|
<span>
|
||||||
<span class="badge bg-warning text-dark ms-2">Черновик</span>
|
<i class="bi bi-file-earmark-plus me-2"></i>{{ document.document_number }}
|
||||||
{% elif document.status == 'confirmed' %}
|
{% if document.status == 'draft' %}
|
||||||
<span class="badge bg-success ms-2">Проведён</span>
|
<span class="badge bg-warning text-dark ms-2">Черновик</span>
|
||||||
{% elif document.status == 'cancelled' %}
|
{% elif document.status == 'confirmed' %}
|
||||||
<span class="badge bg-secondary ms-2">Отменён</span>
|
<span class="badge bg-success ms-2">Проведён</span>
|
||||||
{% endif %}
|
{% elif document.status == 'cancelled' %}
|
||||||
</h5>
|
<span class="badge bg-secondary ms-2">Отменён</span>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
{% if document.can_edit %}
|
{% if document.can_edit %}
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<form method="post" action="{% url 'inventory:incoming-confirm' document.pk %}" class="d-inline">
|
<form method="post" action="{% url 'inventory:incoming-confirm' document.pk %}" class="d-inline">
|
||||||
@@ -50,65 +53,67 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="collapse" id="document-info-collapse">
|
||||||
<div class="row mb-3">
|
<div class="card-body">
|
||||||
<div class="col-md-3">
|
<div class="row mb-3">
|
||||||
<p class="text-muted small mb-1">Склад</p>
|
<div class="col-md-3">
|
||||||
<p class="fw-semibold">{{ document.warehouse.name }}</p>
|
<p class="text-muted small mb-1">Склад</p>
|
||||||
|
<p class="fw-semibold">{{ document.warehouse.name }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<p class="text-muted small mb-1">Дата документа</p>
|
||||||
|
<p class="fw-semibold">{{ document.date|date:"d.m.Y" }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<p class="text-muted small mb-1">Тип поступления</p>
|
||||||
|
<p class="fw-semibold">{{ document.get_receipt_type_display }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<p class="text-muted small mb-1">Создан</p>
|
||||||
|
<p class="fw-semibold">{{ document.created_at|date:"d.m.Y H:i" }}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
|
||||||
<p class="text-muted small mb-1">Дата документа</p>
|
|
||||||
<p class="fw-semibold">{{ document.date|date:"d.m.Y" }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<p class="text-muted small mb-1">Тип поступления</p>
|
|
||||||
<p class="fw-semibold">{{ document.get_receipt_type_display }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<p class="text-muted small mb-1">Создан</p>
|
|
||||||
<p class="fw-semibold">{{ document.created_at|date:"d.m.Y H:i" }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if document.supplier_name %}
|
{% if document.supplier_name %}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<p class="text-muted small mb-1">Поставщик</p>
|
<p class="text-muted small mb-1">Поставщик</p>
|
||||||
<p class="fw-semibold">{{ document.supplier_name }}</p>
|
<p class="fw-semibold">{{ document.supplier_name }}</p>
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if document.notes %}
|
|
||||||
<div class="mb-3">
|
|
||||||
<p class="text-muted small mb-1">Примечания</p>
|
|
||||||
<p>{{ document.notes }}</p>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if document.confirmed_at %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<p class="text-muted small mb-1">Проведён</p>
|
|
||||||
<p class="fw-semibold">{{ document.confirmed_at|date:"d.m.Y H:i" }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
{% endif %}
|
||||||
<p class="text-muted small mb-1">Провёл</p>
|
|
||||||
<p class="fw-semibold">{% if document.confirmed_by %}{{ document.confirmed_by.name|default:document.confirmed_by.email }}{% else %}-{% endif %}</p>
|
{% if document.notes %}
|
||||||
|
<div class="mb-3">
|
||||||
|
<p class="text-muted small mb-1">Примечания</p>
|
||||||
|
<p>{{ document.notes }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if document.confirmed_at %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<p class="text-muted small mb-1">Проведён</p>
|
||||||
|
<p class="fw-semibold">{{ document.confirmed_at|date:"d.m.Y H:i" }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<p class="text-muted small mb-1">Провёл</p>
|
||||||
|
<p class="fw-semibold">{% if document.confirmed_by %}{{ document.confirmed_by.name|default:document.confirmed_by.email }}{% else %}-{% endif %}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Добавление позиции -->
|
<!-- Добавление позиции -->
|
||||||
{% if document.can_edit %}
|
{% if document.can_edit %}
|
||||||
<div class="card border-0 shadow-sm mb-3">
|
<div class="card border-0 shadow-sm mb-3">
|
||||||
<div class="card-header bg-light py-3">
|
<div class="card-header bg-light py-1">
|
||||||
<h6 class="mb-0"><i class="bi bi-plus-square me-2"></i>Добавить позицию в документ</h6>
|
<h6 class="mb-0"><i class="bi bi-plus-square me-2"></i>Добавить позицию в документ</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body p-2">
|
||||||
<!-- Компонент поиска товаров -->
|
<!-- Компонент поиска товаров - компактный -->
|
||||||
<div class="mb-3">
|
<div class="mb-2">
|
||||||
{% include 'products/components/product_search_picker.html' with container_id='incoming-picker' title='Найти товар для поступления' warehouse_id=document.warehouse.id filter_in_stock_only=False skip_stock_filter=True categories=categories tags=tags add_button_text='Выбрать товар' content_height='250px' %}
|
{% include 'products/components/product_search_picker.html' with container_id='incoming-picker' title='Найти товар...' warehouse_id=document.warehouse.id filter_in_stock_only=False skip_stock_filter=True categories=categories tags=tags add_button_text='Выбрать' content_height='150px' %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Информация о выбранном товаре -->
|
<!-- Информация о выбранном товаре -->
|
||||||
@@ -217,11 +222,19 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-3 py-2 text-end" style="width: 120px;">
|
<td class="px-3 py-2 text-end" style="width: 120px;">
|
||||||
<span class="item-cost-price-display">{{ item.cost_price|floatformat:2 }}</span>
|
|
||||||
{% if document.can_edit %}
|
{% if document.can_edit %}
|
||||||
<input type="number" class="form-control form-control-sm item-cost-price-input"
|
<span class="editable-cost-price"
|
||||||
value="{{ item.cost_price|stringformat:'g' }}" step="0.01" min="0"
|
data-item-id="{{ item.id }}"
|
||||||
style="display: none; width: 100px; text-align: right; margin-left: auto;">
|
data-current-value="{{ item.cost_price }}"
|
||||||
|
title="Закупочная цена (клик для редактирования)"
|
||||||
|
style="cursor: pointer;">
|
||||||
|
{{ item.cost_price|floatformat:2 }}
|
||||||
|
</span>
|
||||||
|
<input type="number" class="form-control form-control-sm item-cost-price-input"
|
||||||
|
value="{{ item.cost_price|stringformat:'g' }}" step="0.01" min="0"
|
||||||
|
style="display: none; width: 100px; text-align: right; margin-left: auto;">
|
||||||
|
{% else %}
|
||||||
|
<span>{{ item.cost_price|floatformat:2 }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-3 py-2 text-end" style="width: 120px;">
|
<td class="px-3 py-2 text-end" style="width: 120px;">
|
||||||
@@ -271,24 +284,13 @@
|
|||||||
</td>
|
</td>
|
||||||
{% if document.can_edit %}
|
{% if document.can_edit %}
|
||||||
<td class="px-3 py-2 text-end" style="width: 100px;">
|
<td class="px-3 py-2 text-end" style="width: 100px;">
|
||||||
<div class="btn-group btn-group-sm item-action-buttons">
|
<div class="btn-group btn-group-sm">
|
||||||
<button type="button" class="btn btn-outline-primary btn-edit-item" title="Редактировать">
|
|
||||||
<i class="bi bi-pencil"></i>
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn btn-outline-danger"
|
<button type="button" class="btn btn-outline-danger"
|
||||||
onclick="if(confirm('Удалить позицию?')) document.getElementById('delete-form-{{ item.id }}').submit();"
|
onclick="if(confirm('Удалить позицию?')) document.getElementById('delete-form-{{ item.id }}').submit();"
|
||||||
title="Удалить">
|
title="Удалить">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group btn-group-sm item-edit-buttons" style="display: none;">
|
|
||||||
<button type="button" class="btn btn-success btn-save-item" title="Сохранить">
|
|
||||||
<i class="bi bi-check-lg"></i>
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn btn-secondary btn-cancel-edit" title="Отменить">
|
|
||||||
<i class="bi bi-x-lg"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<form id="delete-form-{{ item.id }}" method="post"
|
<form id="delete-form-{{ item.id }}" method="post"
|
||||||
action="{% url 'inventory:incoming-remove-item' document.pk item.pk %}"
|
action="{% url 'inventory:incoming-remove-item' document.pk item.pk %}"
|
||||||
style="display: none;">
|
style="display: none;">
|
||||||
@@ -351,6 +353,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Анимация для иконки сворачивания/разворачивания информации о документе
|
||||||
|
const documentInfoCollapse = document.getElementById('document-info-collapse');
|
||||||
|
const documentInfoCollapseIcon = document.getElementById('document-info-collapse-icon');
|
||||||
|
|
||||||
|
if (documentInfoCollapse && documentInfoCollapseIcon) {
|
||||||
|
documentInfoCollapse.addEventListener('show.bs.collapse', function() {
|
||||||
|
documentInfoCollapseIcon.classList.remove('bi-chevron-down');
|
||||||
|
documentInfoCollapseIcon.classList.add('bi-chevron-up');
|
||||||
|
});
|
||||||
|
|
||||||
|
documentInfoCollapse.addEventListener('hide.bs.collapse', function() {
|
||||||
|
documentInfoCollapseIcon.classList.remove('bi-chevron-up');
|
||||||
|
documentInfoCollapseIcon.classList.add('bi-chevron-down');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Функция выбора товара
|
// Функция выбора товара
|
||||||
function selectProduct(product) {
|
function selectProduct(product) {
|
||||||
const productId = String(product.id).replace('product_', '');
|
const productId = String(product.id).replace('product_', '');
|
||||||
@@ -416,160 +434,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
clearSelectedBtn.addEventListener('click', clearSelectedProduct);
|
clearSelectedBtn.addEventListener('click', clearSelectedProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// Inline редактирование позиций в таблице
|
|
||||||
// ============================================
|
|
||||||
|
|
||||||
// Хранилище оригинальных значений при редактировании
|
|
||||||
const originalValues = {};
|
|
||||||
|
|
||||||
// Обработчики для кнопок редактирования
|
|
||||||
document.querySelectorAll('.btn-edit-item').forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
const row = this.closest('tr');
|
|
||||||
const itemId = row.dataset.itemId;
|
|
||||||
|
|
||||||
// Сохраняем оригинальные значения
|
|
||||||
originalValues[itemId] = {
|
|
||||||
quantity: row.querySelector('.item-quantity-input').value,
|
|
||||||
cost_price: row.querySelector('.item-cost-price-input').value,
|
|
||||||
notes: row.querySelector('.item-notes-input').value
|
|
||||||
};
|
|
||||||
|
|
||||||
// Переключаем в режим редактирования
|
|
||||||
toggleEditMode(row, true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Обработчики для кнопок сохранения
|
|
||||||
document.querySelectorAll('.btn-save-item').forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
const row = this.closest('tr');
|
|
||||||
const itemId = row.dataset.itemId;
|
|
||||||
saveItemChanges(itemId, row);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Обработчики для кнопок отмены
|
|
||||||
document.querySelectorAll('.btn-cancel-edit').forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
const row = this.closest('tr');
|
|
||||||
const itemId = row.dataset.itemId;
|
|
||||||
|
|
||||||
// Восстанавливаем оригинальные значения
|
|
||||||
if (originalValues[itemId]) {
|
|
||||||
row.querySelector('.item-quantity-input').value = originalValues[itemId].quantity;
|
|
||||||
row.querySelector('.item-cost-price-input').value = originalValues[itemId].cost_price;
|
|
||||||
row.querySelector('.item-notes-input').value = originalValues[itemId].notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Выходим из режима редактирования
|
|
||||||
toggleEditMode(row, false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Переключение режима редактирования строки
|
|
||||||
*/
|
|
||||||
function toggleEditMode(row, isEditing) {
|
|
||||||
// Переключаем видимость полей отображения/ввода
|
|
||||||
row.querySelectorAll('.item-quantity-display, .item-cost-price-display, .item-notes-display').forEach(el => {
|
|
||||||
el.style.display = isEditing ? 'none' : '';
|
|
||||||
});
|
|
||||||
row.querySelectorAll('.item-quantity-input, .item-cost-price-input, .item-notes-input').forEach(el => {
|
|
||||||
el.style.display = isEditing ? '' : 'none';
|
|
||||||
});
|
|
||||||
|
|
||||||
// Переключаем видимость кнопок
|
|
||||||
row.querySelector('.item-action-buttons').style.display = isEditing ? 'none' : '';
|
|
||||||
row.querySelector('.item-edit-buttons').style.display = isEditing ? '' : 'none';
|
|
||||||
|
|
||||||
// Фокус на поле количества при входе в режим редактирования
|
|
||||||
if (isEditing) {
|
|
||||||
const qtyInput = row.querySelector('.item-quantity-input');
|
|
||||||
if (qtyInput) {
|
|
||||||
qtyInput.focus();
|
|
||||||
qtyInput.select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сохранение изменений позиции
|
|
||||||
*/
|
|
||||||
function saveItemChanges(itemId, row) {
|
|
||||||
const quantity = row.querySelector('.item-quantity-input').value;
|
|
||||||
const costPrice = row.querySelector('.item-cost-price-input').value;
|
|
||||||
const notes = row.querySelector('.item-notes-input').value;
|
|
||||||
|
|
||||||
// Валидация
|
|
||||||
if (!quantity || parseFloat(quantity) <= 0) {
|
|
||||||
alert('Количество должно быть больше нуля');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!costPrice || parseFloat(costPrice) < 0) {
|
|
||||||
alert('Закупочная цена не может быть отрицательной');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Отправляем на сервер
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('quantity', quantity);
|
|
||||||
formData.append('cost_price', costPrice);
|
|
||||||
formData.append('notes', notes);
|
|
||||||
formData.append('csrfmiddlewaretoken', document.querySelector('[name=csrfmiddlewaretoken]').value);
|
|
||||||
|
|
||||||
// Блокируем кнопки во время сохранения
|
|
||||||
const saveBtn = row.querySelector('.btn-save-item');
|
|
||||||
const cancelBtn = row.querySelector('.btn-cancel-edit');
|
|
||||||
saveBtn.disabled = true;
|
|
||||||
cancelBtn.disabled = true;
|
|
||||||
saveBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status"></span>';
|
|
||||||
|
|
||||||
fetch(`/inventory/incoming-documents/{{ document.pk }}/update-item/${itemId}/`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
headers: {
|
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.success) {
|
|
||||||
// Обновляем отображение
|
|
||||||
let formattedQty = parseFloat(quantity);
|
|
||||||
if (formattedQty === Math.floor(formattedQty)) {
|
|
||||||
formattedQty = Math.floor(formattedQty).toString();
|
|
||||||
} else {
|
|
||||||
formattedQty = formattedQty.toString().replace('.', ',');
|
|
||||||
}
|
|
||||||
row.querySelector('.item-quantity-display').textContent = formattedQty;
|
|
||||||
row.querySelector('.item-cost-price-display').textContent = parseFloat(costPrice).toFixed(2);
|
|
||||||
row.querySelector('.item-notes-display').textContent = notes || '-';
|
|
||||||
|
|
||||||
// Пересчитываем сумму
|
|
||||||
const totalCost = (parseFloat(quantity) * parseFloat(costPrice)).toFixed(2);
|
|
||||||
row.querySelector('td:nth-child(4) strong').textContent = totalCost;
|
|
||||||
|
|
||||||
// Выходим из режима редактирования
|
|
||||||
toggleEditMode(row, false);
|
|
||||||
} else {
|
|
||||||
alert('Ошибка: ' + data.error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
alert('Произошла ошибка при сохранении');
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
saveBtn.disabled = false;
|
|
||||||
cancelBtn.disabled = false;
|
|
||||||
saveBtn.innerHTML = '<i class="bi bi-check-lg"></i>';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Inline редактирование количества
|
// Inline редактирование количества и цены
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
function initInlineQuantityEdit() {
|
function initInlineQuantityEdit() {
|
||||||
@@ -708,14 +576,146 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initInlineCostPriceEdit() {
|
||||||
|
// Проверяем, есть ли на странице редактируемые цены
|
||||||
|
const editableCostPrices = document.querySelectorAll('.editable-cost-price');
|
||||||
|
if (editableCostPrices.length === 0) {
|
||||||
|
return; // Нет элементов для редактирования
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработчик клика на редактируемую цену
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
const costPriceSpan = e.target.closest('.editable-cost-price');
|
||||||
|
if (!costPriceSpan) return;
|
||||||
|
|
||||||
|
// Предотвращаем повторное срабатывание, если уже редактируем
|
||||||
|
if (costPriceSpan.querySelector('input')) return;
|
||||||
|
|
||||||
|
const itemId = costPriceSpan.dataset.itemId;
|
||||||
|
const currentValue = costPriceSpan.dataset.currentValue;
|
||||||
|
|
||||||
|
// Сохраняем оригинальный HTML
|
||||||
|
const originalHTML = costPriceSpan.innerHTML;
|
||||||
|
|
||||||
|
// Создаем input для редактирования
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'number';
|
||||||
|
input.className = 'form-control form-control-sm';
|
||||||
|
input.style.width = '100px';
|
||||||
|
input.style.textAlign = 'right';
|
||||||
|
input.value = parseFloat(currentValue).toFixed(2);
|
||||||
|
input.step = '0.01';
|
||||||
|
input.min = '0';
|
||||||
|
input.placeholder = 'Цена';
|
||||||
|
|
||||||
|
// Заменяем содержимое на input
|
||||||
|
costPriceSpan.innerHTML = '';
|
||||||
|
costPriceSpan.appendChild(input);
|
||||||
|
input.focus();
|
||||||
|
input.select();
|
||||||
|
|
||||||
|
// Функция сохранения
|
||||||
|
const saveCostPrice = async () => {
|
||||||
|
let newValue = input.value.trim();
|
||||||
|
|
||||||
|
// Валидация
|
||||||
|
if (!newValue || parseFloat(newValue) < 0) {
|
||||||
|
alert('Закупочная цена не может быть отрицательной');
|
||||||
|
costPriceSpan.innerHTML = originalHTML;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, изменилось ли значение
|
||||||
|
if (parseFloat(newValue) === parseFloat(currentValue)) {
|
||||||
|
// Значение не изменилось
|
||||||
|
costPriceSpan.innerHTML = originalHTML;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Показываем загрузку
|
||||||
|
input.disabled = true;
|
||||||
|
input.style.opacity = '0.5';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Получаем текущие значения других полей
|
||||||
|
const row = costPriceSpan.closest('tr');
|
||||||
|
const quantity = row.querySelector('.item-quantity-input').value;
|
||||||
|
const notes = row.querySelector('.item-notes-input').value;
|
||||||
|
|
||||||
|
const response = await fetch(`/inventory/incoming-documents/{{ document.pk }}/update-item/${itemId}/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
|
||||||
|
},
|
||||||
|
body: new URLSearchParams({
|
||||||
|
quantity: quantity,
|
||||||
|
cost_price: newValue,
|
||||||
|
notes: notes
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
// Обновляем отображение
|
||||||
|
const formattedPrice = parseFloat(newValue).toFixed(2);
|
||||||
|
costPriceSpan.textContent = formattedPrice;
|
||||||
|
costPriceSpan.dataset.currentValue = newValue;
|
||||||
|
|
||||||
|
// Пересчитываем сумму
|
||||||
|
const totalCost = (parseFloat(quantity) * parseFloat(newValue)).toFixed(2);
|
||||||
|
row.querySelector('td:nth-child(4) strong').textContent = totalCost;
|
||||||
|
|
||||||
|
// Обновляем итого
|
||||||
|
updateTotals();
|
||||||
|
} else {
|
||||||
|
alert(data.error || 'Ошибка при обновлении цены');
|
||||||
|
costPriceSpan.innerHTML = originalHTML;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('Ошибка сети при обновлении цены');
|
||||||
|
costPriceSpan.innerHTML = originalHTML;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Функция отмены
|
||||||
|
const cancelEdit = () => {
|
||||||
|
costPriceSpan.innerHTML = originalHTML;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enter - сохранить
|
||||||
|
input.addEventListener('keydown', function(e) {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
saveCostPrice();
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
e.preventDefault();
|
||||||
|
cancelEdit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Потеря фокуса - сохранить
|
||||||
|
input.addEventListener('blur', function() {
|
||||||
|
setTimeout(saveCostPrice, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Функция обновления итоговых сумм
|
// Функция обновления итоговых сумм
|
||||||
function updateTotals() {
|
function updateTotals() {
|
||||||
// Можно реализовать пересчет итогов, если нужно
|
// Можно реализовать пересчет итогов, если нужно
|
||||||
// Пока оставим как есть, так как сервер возвращает обновленные данные
|
// Пока оставим как есть, так как сервер возвращает обновленные данные
|
||||||
}
|
}
|
||||||
|
|
||||||
// Инициализация inline редактирования количества
|
// Инициализация inline редактирования
|
||||||
initInlineQuantityEdit();
|
initInlineQuantityEdit();
|
||||||
|
initInlineCostPriceEdit();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -745,6 +745,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
color: #0d6efd !important;
|
color: #0d6efd !important;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Стили для редактируемой цены */
|
||||||
|
.editable-cost-price {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editable-cost-price:hover {
|
||||||
|
color: #0d6efd !important;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -19,52 +19,76 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<!-- Информация об инвентаризации - свернута по умолчанию -->
|
||||||
<div class="row mb-4">
|
<div class="row mb-4">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h5>Информация</h5>
|
<button class="btn btn-outline-primary btn-sm d-flex align-items-center gap-2 mb-2" type="button" data-bs-toggle="collapse" data-bs-target="#inventory-info-collapse" aria-expanded="false" aria-controls="inventory-info-collapse">
|
||||||
<table class="table table-borderless">
|
<i class="bi bi-chevron-down" id="info-collapse-icon"></i>
|
||||||
{% if inventory.document_number %}
|
<span>Информация</span>
|
||||||
<tr>
|
</button>
|
||||||
<th>Номер документа:</th>
|
<div class="collapse" id="inventory-info-collapse">
|
||||||
<td><strong>{{ inventory.document_number }}</strong></td>
|
<table class="table table-borderless">
|
||||||
</tr>
|
{% if inventory.document_number %}
|
||||||
{% endif %}
|
<tr>
|
||||||
<tr>
|
<th>Номер документа:</th>
|
||||||
<th>Склад:</th>
|
<td><strong>{{ inventory.document_number }}</strong></td>
|
||||||
<td><strong>{{ inventory.warehouse.name }}</strong></td>
|
</tr>
|
||||||
</tr>
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Статус:</th>
|
<th>Склад:</th>
|
||||||
<td>
|
<td><strong>{{ inventory.warehouse.name }}</strong></td>
|
||||||
{% if inventory.status == 'draft' %}
|
</tr>
|
||||||
<span class="badge bg-secondary fs-6 px-3 py-2">
|
<tr>
|
||||||
<i class="bi bi-file-earmark"></i> Черновик
|
<th>Статус:</th>
|
||||||
</span>
|
<td>
|
||||||
{% elif inventory.status == 'processing' %}
|
{% if inventory.status == 'draft' %}
|
||||||
<span class="badge bg-warning text-dark fs-6 px-3 py-2">
|
<span class="badge bg-secondary fs-6 px-3 py-2">
|
||||||
<i class="bi bi-hourglass-split"></i> В обработке
|
<i class="bi bi-file-earmark"></i> Черновик
|
||||||
</span>
|
</span>
|
||||||
{% else %}
|
{% elif inventory.status == 'processing' %}
|
||||||
<span class="badge bg-success fs-6 px-3 py-2">
|
<span class="badge bg-warning text-dark fs-6 px-3 py-2">
|
||||||
<i class="bi bi-check-circle-fill"></i> Завершена
|
<i class="bi bi-hourglass-split"></i> В обработке
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% else %}
|
||||||
</td>
|
<span class="badge bg-success fs-6 px-3 py-2">
|
||||||
</tr>
|
<i class="bi bi-check-circle-fill"></i> Завершена
|
||||||
<tr>
|
</span>
|
||||||
<th>Дата:</th>
|
{% endif %}
|
||||||
<td>{{ inventory.date|date:"d.m.Y H:i" }}</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if inventory.conducted_by %}
|
<tr>
|
||||||
<tr>
|
<th>Дата:</th>
|
||||||
<th>Провёл:</th>
|
<td>{{ inventory.date|date:"d.m.Y H:i" }}</td>
|
||||||
<td>{{ inventory.conducted_by }}</td>
|
</tr>
|
||||||
</tr>
|
{% if inventory.conducted_by %}
|
||||||
{% endif %}
|
<tr>
|
||||||
</table>
|
<th>Провёл:</th>
|
||||||
|
<td>{{ inventory.conducted_by }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Добавляем простую анимацию для иконки при сворачивании/разворачивании
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const collapseElement = document.getElementById('inventory-info-collapse');
|
||||||
|
const collapseIcon = document.getElementById('info-collapse-icon');
|
||||||
|
|
||||||
|
collapseElement.addEventListener('show.bs.collapse', function() {
|
||||||
|
collapseIcon.classList.remove('bi-chevron-down');
|
||||||
|
collapseIcon.classList.add('bi-chevron-up');
|
||||||
|
});
|
||||||
|
|
||||||
|
collapseElement.addEventListener('hide.bs.collapse', function() {
|
||||||
|
collapseIcon.classList.remove('bi-chevron-up');
|
||||||
|
collapseIcon.classList.add('bi-chevron-down');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
{% if inventory.status == 'completed' %}
|
{% if inventory.status == 'completed' %}
|
||||||
<!-- Информация о созданных документах -->
|
<!-- Информация о созданных документах -->
|
||||||
<div class="alert alert-info mb-4">
|
<div class="alert alert-info mb-4">
|
||||||
@@ -100,14 +124,14 @@
|
|||||||
|
|
||||||
<h5>Строки инвентаризации</h5>
|
<h5>Строки инвентаризации</h5>
|
||||||
|
|
||||||
<!-- Компонент поиска товаров (только если не завершена) -->
|
<!-- Компонент поиска товаров - открыт по умолчанию, компактный -->
|
||||||
{% if inventory.status != 'completed' %}
|
{% if inventory.status != 'completed' %}
|
||||||
<div class="card border-primary mb-4" id="product-search-section">
|
<div class="card border-primary mb-4" id="product-search-section">
|
||||||
<div class="card-header bg-light">
|
<div class="card-header bg-light py-1">
|
||||||
<h6 class="mb-0"><i class="bi bi-plus-square me-2"></i>Добавить товар в инвентаризацию</h6>
|
<h6 class="mb-0"><i class="bi bi-plus-square me-2"></i>Добавить товар в инвентаризацию</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body p-2">
|
||||||
{% include 'products/components/product_search_picker.html' with container_id='inventory-product-picker' title='Поиск товара для инвентаризации...' warehouse_id=inventory.warehouse.id filter_in_stock_only=False categories=categories tags=tags add_button_text='Добавить товар' content_height='250px' skip_stock_filter=True %}
|
{% include 'products/components/product_search_picker.html' with container_id='inventory-product-picker' title='Поиск товара...' warehouse_id=inventory.warehouse.id filter_in_stock_only=False categories=categories tags=tags add_button_text='Добавить' content_height='150px' skip_stock_filter=True %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -74,10 +74,12 @@
|
|||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="px-3 py-2">
|
<td class="px-3 py-2">
|
||||||
<a href="{% url 'products:product-detail' item.product.id %}">{{ item.product.name }}</a>
|
<a href="{% url 'products:product-detail' item.product.id %}">{{
|
||||||
|
item.product.name }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-3 py-2" style="text-align: right;">{{ item.quantity }}</td>
|
<td class="px-3 py-2" style="text-align: right;">{{ item.quantity }}</td>
|
||||||
<td class="px-3 py-2" style="text-align: right;">{{ item.batch.cost_price }} ₽/ед.</td>
|
<td class="px-3 py-2" style="text-align: right;">{{ item.batch.cost_price }} ₽/ед.
|
||||||
|
</td>
|
||||||
<td class="px-3 py-2">
|
<td class="px-3 py-2">
|
||||||
<span class="badge bg-secondary">{{ item.batch.id }}</span>
|
<span class="badge bg-secondary">{{ item.batch.id }}</span>
|
||||||
</td>
|
</td>
|
||||||
@@ -132,9 +134,11 @@
|
|||||||
<a href="{% url 'inventory:transfer-list' %}" class="btn btn-outline-secondary btn-sm">
|
<a href="{% url 'inventory:transfer-list' %}" class="btn btn-outline-secondary btn-sm">
|
||||||
<i class="bi bi-arrow-left me-1"></i>Вернуться к списку
|
<i class="bi bi-arrow-left me-1"></i>Вернуться к списку
|
||||||
</a>
|
</a>
|
||||||
|
<!--
|
||||||
<a href="{% url 'inventory:transfer-delete' transfer_document.id %}" class="btn btn-outline-danger btn-sm">
|
<a href="{% url 'inventory:transfer-delete' transfer_document.id %}" class="btn btn-outline-danger btn-sm">
|
||||||
<i class="bi bi-trash me-1"></i>Удалить
|
<i class="bi bi-trash me-1"></i>Удалить
|
||||||
</a>
|
</a>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -143,13 +147,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.breadcrumb-sm {
|
.breadcrumb-sm {
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
padding: 0.5rem 0;
|
padding: 0.5rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table-hover tbody tr:hover {
|
.table-hover tbody tr:hover {
|
||||||
background-color: #f8f9fa;
|
background-color: #f8f9fa;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -39,9 +39,11 @@
|
|||||||
<a href="{% url 'inventory:transfer-detail' t.pk %}" class="btn btn-sm btn-outline-info" title="Просмотр">
|
<a href="{% url 'inventory:transfer-detail' t.pk %}" class="btn btn-sm btn-outline-info" title="Просмотр">
|
||||||
<i class="bi bi-eye"></i>
|
<i class="bi bi-eye"></i>
|
||||||
</a>
|
</a>
|
||||||
|
<!--
|
||||||
<a href="{% url 'inventory:transfer-delete' t.pk %}" class="btn btn-sm btn-outline-danger" title="Удалить">
|
<a href="{% url 'inventory:transfer-delete' t.pk %}" class="btn btn-sm btn-outline-danger" title="Удалить">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
|
-->
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -631,3 +631,5 @@ if not DEBUG and not ENCRYPTION_KEY:
|
|||||||
"ENCRYPTION_KEY not set! Encrypted fields will fail. "
|
"ENCRYPTION_KEY not set! Encrypted fields will fail. "
|
||||||
"Generate with: python -c \"from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())\""
|
"Generate with: python -c \"from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())\""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,18 @@ from inventory.models import Reservation
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from django.utils import timezone # Added for default date filter
|
||||||
|
|
||||||
def order_list(request):
|
def order_list(request):
|
||||||
"""
|
"""
|
||||||
Список всех заказов с фильтрацией и поиском
|
Список всех заказов с фильтрацией и поиском
|
||||||
Использует django-filter для фильтрации данных
|
Использует django-filter для фильтрации данных
|
||||||
"""
|
"""
|
||||||
|
# Если параметров нет вообще (первый заход), редиректим на "Сегодня"
|
||||||
|
if not request.GET:
|
||||||
|
today = timezone.localdate().isoformat()
|
||||||
|
return redirect(f'{request.path}?delivery_date_after={today}&delivery_date_before={today}')
|
||||||
|
|
||||||
# Базовый queryset с оптимизацией запросов
|
# Базовый queryset с оптимизацией запросов
|
||||||
orders = Order.objects.select_related(
|
orders = Order.objects.select_related(
|
||||||
'customer', 'delivery', 'delivery__address', 'delivery__pickup_warehouse', 'status' # Добавлен 'status' для избежания N+1
|
'customer', 'delivery', 'delivery__address', 'delivery__pickup_warehouse', 'status' # Добавлен 'status' для избежания N+1
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -729,6 +729,28 @@
|
|||||||
|
|
||||||
<!-- Модалка редактирования товара в корзине -->
|
<!-- Модалка редактирования товара в корзине -->
|
||||||
{% include 'pos/components/edit_cart_item_modal.html' %}
|
{% include 'pos/components/edit_cart_item_modal.html' %}
|
||||||
|
|
||||||
|
<!-- Toast Container для уведомлений -->
|
||||||
|
<div class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1060;">
|
||||||
|
<div id="orderSuccessToast" class="toast align-items-center border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
|
<div class="d-flex">
|
||||||
|
<div class="toast-body">
|
||||||
|
<i class="bi bi-check-circle-fill text-success me-2 fs-5"></i>
|
||||||
|
<span id="toastMessage"></span>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close" style="display: none;"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="orderErrorToast" class="toast align-items-center border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
|
<div class="d-flex">
|
||||||
|
<div class="toast-body">
|
||||||
|
<i class="bi bi-exclamation-circle-fill text-danger me-2 fs-5"></i>
|
||||||
|
<span id="errorMessage"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
|
|||||||
@@ -1163,15 +1163,20 @@ def create_temp_kit_to_showcase(request):
|
|||||||
}, status=400)
|
}, status=400)
|
||||||
|
|
||||||
# Агрегируем дубликаты (если один товар добавлен несколько раз)
|
# Агрегируем дубликаты (если один товар добавлен несколько раз)
|
||||||
|
# Сохраняем также цену из корзины (unit_price)
|
||||||
aggregated_items = {}
|
aggregated_items = {}
|
||||||
for item in items:
|
for item in items:
|
||||||
product_id = item['product_id']
|
product_id = item['product_id']
|
||||||
quantity = Decimal(str(item['quantity']))
|
quantity = Decimal(str(item['quantity']))
|
||||||
|
unit_price = item.get('unit_price') # Цена из корзины (может быть изменена пользователем)
|
||||||
|
|
||||||
if product_id in aggregated_items:
|
if product_id in aggregated_items:
|
||||||
aggregated_items[product_id] += quantity
|
aggregated_items[product_id]['quantity'] += quantity
|
||||||
else:
|
else:
|
||||||
aggregated_items[product_id] = quantity
|
aggregated_items[product_id] = {
|
||||||
|
'quantity': quantity,
|
||||||
|
'unit_price': Decimal(str(unit_price)) if unit_price is not None else None
|
||||||
|
}
|
||||||
|
|
||||||
# Создаём временный комплект и резервируем на витрину
|
# Создаём временный комплект и резервируем на витрину
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
@@ -1189,15 +1194,17 @@ def create_temp_kit_to_showcase(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 2. Создаём KitItem для каждого товара из корзины
|
# 2. Создаём KitItem для каждого товара из корзины
|
||||||
for product_id, quantity in aggregated_items.items():
|
for product_id, item_data in aggregated_items.items():
|
||||||
product = products[product_id]
|
product = products[product_id]
|
||||||
|
# Используем цену из корзины, если передана, иначе из каталога
|
||||||
|
final_price = item_data['unit_price'] if item_data['unit_price'] is not None else product.actual_price
|
||||||
KitItem.objects.create(
|
KitItem.objects.create(
|
||||||
kit=kit,
|
kit=kit,
|
||||||
product=product,
|
product=product,
|
||||||
quantity=quantity,
|
quantity=item_data['quantity'],
|
||||||
unit_price=product.actual_price # Фиксируем цену для временного комплекта
|
unit_price=final_price # Фиксируем цену из корзины (с учётом изменений пользователя)
|
||||||
)
|
)
|
||||||
|
|
||||||
# 3. Пересчитываем цену комплекта
|
# 3. Пересчитываем цену комплекта
|
||||||
kit.recalculate_base_price()
|
kit.recalculate_base_price()
|
||||||
|
|
||||||
@@ -1264,7 +1271,7 @@ def create_temp_kit_to_showcase(request):
|
|||||||
f' Название: {request.POST.get("kit_name")}\n'
|
f' Название: {request.POST.get("kit_name")}\n'
|
||||||
f' Витрина ID: {request.POST.get("showcase_id")}\n'
|
f' Витрина ID: {request.POST.get("showcase_id")}\n'
|
||||||
f' Товары: {request.POST.get("items")}\n'
|
f' Товары: {request.POST.get("items")}\n'
|
||||||
f' Пользователь: {request.user.username}\n'
|
f' Пользователь: {str(request.user)}\n'
|
||||||
f' Ошибка: {str(e)}',
|
f' Ошибка: {str(e)}',
|
||||||
exc_info=True
|
exc_info=True
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -230,7 +230,11 @@ class ProductKit(BaseProductEntity):
|
|||||||
qty = item.quantity or Decimal('1')
|
qty = item.quantity or Decimal('1')
|
||||||
total += actual_price * qty
|
total += actual_price * qty
|
||||||
elif item.product:
|
elif item.product:
|
||||||
actual_price = item.product.actual_price or Decimal('0')
|
# Используем зафиксированную цену (unit_price) если задана, иначе актуальную цену товара
|
||||||
|
if item.unit_price is not None:
|
||||||
|
actual_price = item.unit_price
|
||||||
|
else:
|
||||||
|
actual_price = item.product.actual_price or Decimal('0')
|
||||||
qty = item.quantity or Decimal('1')
|
qty = item.quantity or Decimal('1')
|
||||||
total += actual_price * qty
|
total += actual_price * qty
|
||||||
elif item.variant_group:
|
elif item.variant_group:
|
||||||
|
|||||||
@@ -207,6 +207,18 @@
|
|||||||
self._toggleProduct(productId);
|
self._toggleProduct(productId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Двойной клик по товару - сразу добавляет в документ
|
||||||
|
this.elements.grid.addEventListener('dblclick', function(e) {
|
||||||
|
var productCard = e.target.closest('.product-picker-item');
|
||||||
|
if (productCard && self.options.onAddSelected) {
|
||||||
|
var productId = productCard.dataset.productId;
|
||||||
|
var product = self._findProductById(productId);
|
||||||
|
if (product) {
|
||||||
|
self.options.onAddSelected(product, self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Добавить выбранный
|
// Добавить выбранный
|
||||||
@@ -435,17 +447,7 @@
|
|||||||
*/
|
*/
|
||||||
ProductSearchPicker.prototype._toggleProduct = function(productId) {
|
ProductSearchPicker.prototype._toggleProduct = function(productId) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var product = null;
|
var product = this._findProductById(productId);
|
||||||
|
|
||||||
// Находим товар в списке
|
|
||||||
for (var i = 0; i < this.state.products.length; i++) {
|
|
||||||
var p = this.state.products[i];
|
|
||||||
if (String(p.id).replace('product_', '') === productId) {
|
|
||||||
product = p;
|
|
||||||
product.id = productId; // Сохраняем очищенный ID
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!product) return;
|
if (!product) return;
|
||||||
|
|
||||||
@@ -473,6 +475,21 @@
|
|||||||
this._updateSelectionUI();
|
this._updateSelectionUI();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Поиск товара по ID в загруженном списке
|
||||||
|
*/
|
||||||
|
ProductSearchPicker.prototype._findProductById = function(productId) {
|
||||||
|
for (var i = 0; i < this.state.products.length; i++) {
|
||||||
|
var p = this.state.products[i];
|
||||||
|
if (String(p.id).replace('product_', '') === productId) {
|
||||||
|
var product = Object.assign({}, p);
|
||||||
|
product.id = productId; // Сохраняем очищенный ID
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Принудительно снять выделение со всех товаров
|
* Принудительно снять выделение со всех товаров
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -48,27 +48,27 @@ ProductSearchPicker.init('#writeoff-products', {
|
|||||||
{% if skip_stock_filter %}data-skip-stock-filter="true"{% endif %}>
|
{% if skip_stock_filter %}data-skip-stock-filter="true"{% endif %}>
|
||||||
|
|
||||||
<div class="card shadow-sm">
|
<div class="card shadow-sm">
|
||||||
<!-- Строка поиска -->
|
<!-- Строка поиска - компактный размер -->
|
||||||
<div class="card-header bg-white py-3">
|
<div class="card-header bg-white py-1">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text bg-light border-end-0">
|
<span class="input-group-text bg-light border-end-0">
|
||||||
<i class="bi bi-search text-primary"></i>
|
<i class="bi bi-search text-primary"></i>
|
||||||
</span>
|
</span>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control form-control-lg border-start-0 product-picker-search"
|
class="form-control form-control-sm border-start-0 product-picker-search"
|
||||||
placeholder="{{ title|default:'Поиск товара по названию, артикулу...' }}"
|
placeholder="{{ title|default:'Поиск товара по названию, артикулу...' }}"
|
||||||
style="box-shadow: none;">
|
style="box-shadow: none;">
|
||||||
<button class="btn btn-outline-secondary product-picker-search-clear"
|
<button class="btn btn-outline-secondary btn-sm product-picker-search-clear"
|
||||||
type="button" style="display: none;">
|
type="button" style="display: none;">
|
||||||
<i class="bi bi-x-lg"></i>
|
<i class="bi bi-x"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if show_filters|default:True %}
|
{% if show_filters|default:True %}
|
||||||
<!-- Фильтры -->
|
<!-- Фильтры - компактный вид -->
|
||||||
<div class="card-body border-bottom py-2">
|
<div class="card-body border-bottom py-1">
|
||||||
<div class="d-flex gap-2 align-items-center flex-wrap">
|
<div class="d-flex gap-1 align-items-center flex-wrap">
|
||||||
{% if categories %}
|
{% if categories %}
|
||||||
<!-- Фильтр по категории -->
|
<!-- Фильтр по категории -->
|
||||||
<select class="form-select form-select-sm product-picker-category" style="width: auto;">
|
<select class="form-select form-select-sm product-picker-category" style="width: auto;">
|
||||||
@@ -113,29 +113,29 @@ ProductSearchPicker.init('#writeoff-products', {
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Контент: сетка/список товаров -->
|
<!-- Контент: сетка/список товаров - компактный -->
|
||||||
<div class="card-body product-picker-content" style="max-height: {{ content_height|default:'400px' }}; overflow-y: auto;">
|
<div class="card-body product-picker-content p-1" style="max-height: {{ content_height|default:'400px' }}; overflow-y: auto;">
|
||||||
<!-- Индикатор загрузки -->
|
<!-- Индикатор загрузки -->
|
||||||
<div class="product-picker-loading text-center py-4" style="display: none;">
|
<div class="product-picker-loading text-center py-2" style="display: none;">
|
||||||
<div class="spinner-border text-primary" role="status">
|
<div class="spinner-border spinner-border-sm text-primary" role="status">
|
||||||
<span class="visually-hidden">Загрузка...</span>
|
<span class="visually-hidden">Загрузка...</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Сетка товаров -->
|
<!-- Сетка товаров -->
|
||||||
<div class="row g-2 product-picker-grid" data-view="{{ initial_view|default:'list' }}">
|
<div class="row g-1 product-picker-grid" data-view="{{ initial_view|default:'list' }}">
|
||||||
<!-- Товары загружаются через AJAX -->
|
<!-- Товары загружаются через AJAX -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Пустой результат -->
|
<!-- Пустой результат -->
|
||||||
<div class="product-picker-empty text-center py-4 text-muted" style="display: none;">
|
<div class="product-picker-empty text-center py-2 text-muted" style="display: none;">
|
||||||
<i class="bi bi-search fs-1 opacity-25"></i>
|
<i class="bi bi-search fs-5 opacity-25"></i>
|
||||||
<p class="mb-0 mt-2">Товары не найдены</p>
|
<p class="mb-0 mt-1 small">Товары не найдены</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Футер с кнопкой действия -->
|
<!-- Футер с кнопкой действия - компактный -->
|
||||||
<div class="card-footer bg-white py-2 d-flex justify-content-between align-items-center flex-wrap gap-2">
|
<div class="card-footer bg-white py-1 d-flex justify-content-between align-items-center flex-wrap gap-1">
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
<button class="btn btn-primary btn-sm product-picker-add-selected" disabled>
|
<button class="btn btn-primary btn-sm product-picker-add-selected" disabled>
|
||||||
|
|||||||
120
myproject/reproduce_issue.py
Normal file
120
myproject/reproduce_issue.py
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import django
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
# Setup Django
|
||||||
|
sys.path.append(os.getcwd())
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
from django.test import RequestFactory
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.db import connection
|
||||||
|
|
||||||
|
from customers.models import Customer
|
||||||
|
from inventory.models import Warehouse, Sale
|
||||||
|
from products.models import Product, UnitOfMeasure
|
||||||
|
from pos.views import pos_checkout
|
||||||
|
from orders.models import OrderStatus
|
||||||
|
|
||||||
|
def run():
|
||||||
|
# Setup Data
|
||||||
|
User = get_user_model()
|
||||||
|
user = User.objects.first()
|
||||||
|
if not user:
|
||||||
|
print("No user found")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create/Get Customer
|
||||||
|
customer, _ = Customer.objects.get_or_create(
|
||||||
|
name="Test Customer",
|
||||||
|
defaults={'phone': '+375291112233'}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create/Get Warehouse
|
||||||
|
warehouse, _ = Warehouse.objects.get_or_create(
|
||||||
|
name="Test Warehouse",
|
||||||
|
defaults={'is_active': True}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create product
|
||||||
|
product, _ = Product.objects.get_or_create(
|
||||||
|
name="Test Product Debug",
|
||||||
|
defaults={
|
||||||
|
'sku': 'DEBUG001',
|
||||||
|
'buying_price': 10,
|
||||||
|
'actual_price': 50,
|
||||||
|
'warehouse': warehouse
|
||||||
|
}
|
||||||
|
)
|
||||||
|
product.actual_price = 50
|
||||||
|
product.save()
|
||||||
|
|
||||||
|
# Ensure OrderStatus exists
|
||||||
|
OrderStatus.objects.get_or_create(code='completed', is_system=True, defaults={'name': 'Completed', 'is_positive_end': True})
|
||||||
|
OrderStatus.objects.get_or_create(code='draft', is_system=True, defaults={'name': 'Draft'})
|
||||||
|
|
||||||
|
# Prepare Request
|
||||||
|
factory = RequestFactory()
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"customer_id": customer.id,
|
||||||
|
"warehouse_id": warehouse.id,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "product",
|
||||||
|
"id": product.id,
|
||||||
|
"quantity": 1,
|
||||||
|
"price": 100.00, # Custom price
|
||||||
|
"quantity_base": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payments": [
|
||||||
|
{"payment_method": "cash", "amount": 100.00}
|
||||||
|
],
|
||||||
|
"notes": "Debug Sale"
|
||||||
|
}
|
||||||
|
|
||||||
|
request = factory.post(
|
||||||
|
'/pos/api/checkout/',
|
||||||
|
data=json.dumps(payload),
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
request.user = user
|
||||||
|
|
||||||
|
print("Executing pos_checkout...")
|
||||||
|
response = pos_checkout(request)
|
||||||
|
print(f"Response: {response.content}")
|
||||||
|
|
||||||
|
# Verify Sale
|
||||||
|
sales = Sale.objects.filter(product=product).order_by('-id')[:1]
|
||||||
|
if sales:
|
||||||
|
sale = sales[0]
|
||||||
|
print(f"Sale created. ID: {sale.id}")
|
||||||
|
print(f"Sale Quantity: {sale.quantity}")
|
||||||
|
print(f"Sale Price: {sale.sale_price}")
|
||||||
|
if sale.sale_price == 0:
|
||||||
|
print("FAILURE: Sale price is 0!")
|
||||||
|
else:
|
||||||
|
print(f"SUCCESS: Sale price is {sale.sale_price}")
|
||||||
|
else:
|
||||||
|
print("FAILURE: No Sale created!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from django_tenants.utils import schema_context
|
||||||
|
# Replace with actual schema name if needed, assuming 'public' for now or the default tenant
|
||||||
|
# Since I don't know the tenant, I'll try to run in the current context.
|
||||||
|
# But usually need to set schema.
|
||||||
|
# Let's try to find a tenant.
|
||||||
|
from tenants.models import Client
|
||||||
|
tenant = Client.objects.first()
|
||||||
|
if tenant:
|
||||||
|
print(f"Running in tenant: {tenant.schema_name}")
|
||||||
|
with schema_context(tenant.schema_name):
|
||||||
|
run()
|
||||||
|
else:
|
||||||
|
print("No tenant found, running in public?")
|
||||||
|
run()
|
||||||
Reference in New Issue
Block a user