feat: Реализовать систему поступления товаров с партиями (IncomingBatch)
Основные изменения: - Создана модель IncomingBatch для группировки товаров по документам - Каждое поступление (Incoming) связано с одной батчем поступления - Автоматическое создание StockBatch для каждого товара в приходе - Реализована система нумерации партий (IN-XXXX-XXXX) с поиском максимума в БД - Обновлены все представления (views) для работы с новой архитектурой - Добавлены детальные страницы просмотра партий поступлений - Обновлены шаблоны для отображения информации о партиях и их товарах - Исправлена логика сигналов для создания StockBatch при приходе товара - Обновлены формы для работы с новой структурой IncomingBatch Архитектура FIFO: - IncomingBatch: одна партия поступления (номер IN-XXXX-XXXX) - Incoming: товар в партии поступления - StockBatch: одна партия товара на складе (создается для каждого товара) Это позволяет системе правильно применять FIFO при продаже товаров. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,475 @@
|
||||
{% extends 'inventory/base_inventory.html' %}
|
||||
{% block inventory_title %}Массовое поступление товара{% endblock %}
|
||||
{% block inventory_content %}
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="mb-0">Поступление товара от поставщика</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Ошибки общей формы -->
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<strong>❌ Ошибка:</strong>
|
||||
{% for error in form.non_field_errors %}
|
||||
<div>{{ error }}</div>
|
||||
{% endfor %}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" novalidate id="bulkIncomingForm">
|
||||
{% csrf_token %}
|
||||
|
||||
<!-- ============== HEADER ИНФОРМАЦИЯ ============== -->
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">{{ form.warehouse.label }} <span class="text-danger">*</span></label>
|
||||
{{ form.warehouse }}
|
||||
{% if form.warehouse.errors %}
|
||||
<div class="text-danger small">{{ form.warehouse.errors.0 }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">{{ form.document_number.label }}</label>
|
||||
{{ form.document_number }}
|
||||
{% if form.document_number.errors %}
|
||||
<div class="text-danger small">{{ form.document_number.errors.0 }}</div>
|
||||
{% endif %}
|
||||
<small class="text-muted d-block mt-1">
|
||||
Оставьте пустым для автогенерации свободного номера (формат: IN-XXXX-XXXX). Номера, начинающиеся с IN-, зарезервированы для системы.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">{{ form.supplier_name.label }}</label>
|
||||
{{ form.supplier_name }}
|
||||
{% if form.supplier_name.errors %}
|
||||
<div class="text-danger small">{{ form.supplier_name.errors.0 }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">{{ form.notes.label }}</label>
|
||||
{{ form.notes }}
|
||||
{% if form.notes.errors %}
|
||||
<div class="text-danger small">{{ form.notes.errors.0 }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<!-- ============== ТАБЛИЦА ТОВАРОВ ============== -->
|
||||
<div class="mb-3">
|
||||
<h5>Товары в поступлении</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-bordered" id="productsTable">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 45%;">Товар</th>
|
||||
<th style="width: 15%;">Кол-во (шт)</th>
|
||||
<th style="width: 15%;">Цена закупки</th>
|
||||
<th style="width: 15%;">Сумма</th>
|
||||
<th style="width: 10%;">Действие</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="productsBody">
|
||||
<!-- Строки будут добавлены через JavaScript -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" id="addRowBtn">
|
||||
<i class="bi bi-plus-circle"></i> Добавить товар
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ============== ИТОГО ============== -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6"></div>
|
||||
<div class="col-md-6">
|
||||
<div class="card bg-light">
|
||||
<div class="card-body">
|
||||
<div class="row mb-2">
|
||||
<div class="col-6"><strong>Кол-во позиций:</strong></div>
|
||||
<div class="col-6 text-end"><span id="totalItems">0</span></div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col-6"><strong>Общее количество:</strong></div>
|
||||
<div class="col-6 text-end"><span id="totalQuantity">0</span> шт</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6"><strong>Сумма поступления:</strong></div>
|
||||
<div class="col-6 text-end text-primary"><strong><span id="totalSum">0.00</span> руб</strong></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden input для JSON данных товаров -->
|
||||
<input type="hidden" id="productsJson" name="products_json" value="[]">
|
||||
|
||||
<!-- ============== КНОПКИ ============== -->
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary" id="submitBtn">
|
||||
<i class="bi bi-check-circle"></i> Создать поступление
|
||||
</button>
|
||||
<a href="{% url 'inventory:incoming-list' %}" class="btn btn-secondary">
|
||||
<i class="bi bi-x-circle"></i> Отмена
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
select, textarea, input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.table-responsive {
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.btn-remove-row {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
input[readonly] {
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
|
||||
.row-error {
|
||||
background-color: #fff5f5;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #dc3545;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const form = document.getElementById('bulkIncomingForm');
|
||||
const productsBody = document.getElementById('productsBody');
|
||||
const addRowBtn = document.getElementById('addRowBtn');
|
||||
const productsJsonInput = document.getElementById('productsJson');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
// Список всех доступных товаров (преобразуем QuerySet в JSON)
|
||||
const products = [
|
||||
{% for product in products %}
|
||||
{ id: {{ product.id }}, name: "{{ product.name }}" },
|
||||
{% endfor %}
|
||||
];
|
||||
const productOptions = products.map(p => `<option value="${p.id}">${p.name}</option>`).join('');
|
||||
|
||||
let rowCounter = 0;
|
||||
|
||||
// Добавление новой строки товара
|
||||
addRowBtn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
addProductRow();
|
||||
});
|
||||
|
||||
function addProductRow() {
|
||||
rowCounter++;
|
||||
const rowId = `row-${rowCounter}`;
|
||||
|
||||
const row = document.createElement('tr');
|
||||
row.id = rowId;
|
||||
row.innerHTML = `
|
||||
<td>
|
||||
<select class="form-control form-control-sm product-select" data-row-id="${rowId}">
|
||||
<option value="">Выберите товар...</option>
|
||||
${productOptions}
|
||||
</select>
|
||||
<div class="error-message" style="display:none;"></div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" class="form-control form-control-sm quantity-input"
|
||||
data-row-id="${rowId}" step="0.001" placeholder="0" min="0">
|
||||
<div class="error-message" style="display:none;"></div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" class="form-control form-control-sm price-input"
|
||||
data-row-id="${rowId}" step="0.01" placeholder="0.00" min="0">
|
||||
<div class="error-message" style="display:none;"></div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control form-control-sm sum-display"
|
||||
data-row-id="${rowId}" readonly style="text-align:right;">
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-danger btn-remove-row" data-row-id="${rowId}">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
`;
|
||||
|
||||
productsBody.appendChild(row);
|
||||
|
||||
// Добавляем event listeners для новой строки
|
||||
const quantityInput = row.querySelector('.quantity-input');
|
||||
const priceInput = row.querySelector('.price-input');
|
||||
const removeBtn = row.querySelector('.btn-remove-row');
|
||||
|
||||
quantityInput.addEventListener('input', updateTotals);
|
||||
priceInput.addEventListener('input', updateTotals);
|
||||
removeBtn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
row.remove();
|
||||
updateTotals();
|
||||
});
|
||||
|
||||
updateTotals();
|
||||
}
|
||||
|
||||
function updateTotals() {
|
||||
let totalItems = 0;
|
||||
let totalQuantity = 0;
|
||||
let totalSum = 0;
|
||||
const productsData = [];
|
||||
|
||||
productsBody.querySelectorAll('tr').forEach(row => {
|
||||
const productSelect = row.querySelector('.product-select');
|
||||
const quantityInput = row.querySelector('.quantity-input');
|
||||
const priceInput = row.querySelector('.price-input');
|
||||
const sumDisplay = row.querySelector('.sum-display');
|
||||
|
||||
const productId = productSelect.value;
|
||||
const quantity = parseFloat(quantityInput.value) || 0;
|
||||
const price = parseFloat(priceInput.value) || 0;
|
||||
const sum = quantity * price;
|
||||
|
||||
// Обновляем дисплей суммы
|
||||
sumDisplay.value = sum.toFixed(2);
|
||||
|
||||
// Только считаем если данные заполнены
|
||||
if (productId && quantity > 0 && price >= 0) {
|
||||
totalItems++;
|
||||
totalQuantity += quantity;
|
||||
totalSum += sum;
|
||||
|
||||
productsData.push({
|
||||
product_id: parseInt(productId),
|
||||
quantity: quantity,
|
||||
cost_price: price
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Обновляем итоги
|
||||
document.getElementById('totalItems').textContent = totalItems;
|
||||
document.getElementById('totalQuantity').textContent = totalQuantity.toFixed(3);
|
||||
document.getElementById('totalSum').textContent = totalSum.toFixed(2);
|
||||
|
||||
// Обновляем JSON данные
|
||||
productsJsonInput.value = JSON.stringify(productsData);
|
||||
|
||||
// Отключаем кнопку отправки если нет товаров
|
||||
submitBtn.disabled = totalItems === 0;
|
||||
}
|
||||
|
||||
// Добавляем первую пустую строку
|
||||
addProductRow();
|
||||
|
||||
// Восстанавливаем товары из JSON если была ошибка (сохранение данных при ошибке)
|
||||
const savedProductsJson = '{{ products_json|escapejs }}';
|
||||
if (savedProductsJson && savedProductsJson.trim() !== '[]' && savedProductsJson.trim() !== '') {
|
||||
try {
|
||||
const savedProducts = JSON.parse(savedProductsJson);
|
||||
if (savedProducts && savedProducts.length > 0) {
|
||||
// Удаляем пустую первую строку
|
||||
productsBody.innerHTML = '';
|
||||
rowCounter = 0;
|
||||
|
||||
// Добавляем восстановленные товары
|
||||
savedProducts.forEach(item => {
|
||||
const product = products.find(p => p.id === item.product_id);
|
||||
if (product) {
|
||||
addProductRow();
|
||||
const lastRow = productsBody.querySelector('tr:last-child');
|
||||
|
||||
lastRow.querySelector('.product-select').value = item.product_id;
|
||||
lastRow.querySelector('.quantity-input').value = item.quantity;
|
||||
lastRow.querySelector('.price-input').value = item.cost_price;
|
||||
}
|
||||
});
|
||||
|
||||
// Обновляем итоги
|
||||
updateTotals();
|
||||
|
||||
// Очищаем поле номера документа для автогенерации
|
||||
const documentNumberInput = document.querySelector('[name="document_number"]');
|
||||
if (documentNumberInput) {
|
||||
documentNumberInput.value = '';
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Ошибка восстановления товаров:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Получаем элемент поля номера документа
|
||||
const documentNumberInput = document.querySelector('[name="document_number"]');
|
||||
|
||||
// Валидация номера документа (запретить номера, начинающиеся с "IN-" только для заполненного поля)
|
||||
documentNumberInput.addEventListener('change', function() {
|
||||
const value = this.value.trim().toUpperCase();
|
||||
const container = this.closest('.mb-3');
|
||||
let errorDiv = container.querySelector('.document-number-error');
|
||||
|
||||
// Проверяем IN-* ТОЛЬКО если поле НЕ пусто
|
||||
if (value && value.startsWith('IN-')) {
|
||||
// Показать ошибку
|
||||
this.classList.add('is-invalid');
|
||||
if (!errorDiv) {
|
||||
errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'document-number-error text-danger small mt-2';
|
||||
container.appendChild(errorDiv);
|
||||
}
|
||||
errorDiv.textContent = 'Номера, начинающиеся с "IN-", зарезервированы для системы. Если хотите автогенерацию, оставьте поле пустым.';
|
||||
} else {
|
||||
// Очистить ошибку (пусто или другой формат - это ОК)
|
||||
this.classList.remove('is-invalid');
|
||||
if (errorDiv) {
|
||||
errorDiv.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Валидация перед отправкой
|
||||
form.addEventListener('submit', function(e) {
|
||||
// Проверка номера документа - запретить IN-* только если поле ЗАПОЛНЕНО
|
||||
const docNumberValue = documentNumberInput.value.trim().toUpperCase();
|
||||
const docNumberContainer = documentNumberInput.closest('.mb-3');
|
||||
|
||||
if (docNumberValue && docNumberValue.startsWith('IN-')) {
|
||||
e.preventDefault();
|
||||
|
||||
documentNumberInput.classList.add('is-invalid');
|
||||
let errorDiv = docNumberContainer.querySelector('.document-number-error');
|
||||
if (!errorDiv) {
|
||||
errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'document-number-error text-danger small mt-2';
|
||||
docNumberContainer.appendChild(errorDiv);
|
||||
}
|
||||
errorDiv.textContent = 'Номера, начинающиеся с "IN-", зарезервированы для системы. Оставьте пустым для автогенерации.';
|
||||
|
||||
alert('Номера, начинающиеся с "IN-", зарезервированы для системы. Оставьте пустым для автогенерации.');
|
||||
documentNumberInput.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверка склада
|
||||
const warehouseSelect = document.querySelector('[name="warehouse"]');
|
||||
const warehouseContainer = warehouseSelect.closest('.mb-3');
|
||||
|
||||
if (!warehouseSelect.value) {
|
||||
e.preventDefault();
|
||||
|
||||
// Добавляем класс ошибки если его нет
|
||||
if (!warehouseSelect.classList.contains('is-invalid')) {
|
||||
warehouseSelect.classList.add('is-invalid');
|
||||
warehouseContainer.classList.add('has-validation');
|
||||
}
|
||||
|
||||
// Создаём или обновляем сообщение об ошибке
|
||||
let errorDiv = warehouseContainer.querySelector('.warehouse-error');
|
||||
if (!errorDiv) {
|
||||
errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'warehouse-error text-danger small mt-2';
|
||||
warehouseContainer.appendChild(errorDiv);
|
||||
}
|
||||
errorDiv.textContent = 'Пожалуйста, выберите склад перед отправкой.';
|
||||
|
||||
alert('Пожалуйста, выберите склад перед отправкой.');
|
||||
warehouseSelect.focus();
|
||||
return false;
|
||||
} else {
|
||||
// Очищаем ошибку если склад выбран
|
||||
warehouseSelect.classList.remove('is-invalid');
|
||||
const errorDiv = warehouseContainer.querySelector('.warehouse-error');
|
||||
if (errorDiv) {
|
||||
errorDiv.remove();
|
||||
}
|
||||
}
|
||||
|
||||
const productsData = JSON.parse(productsJsonInput.value);
|
||||
|
||||
if (productsData.length === 0) {
|
||||
e.preventDefault();
|
||||
alert('Пожалуйста, добавьте хотя бы один товар.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем что все товары корректно заполнены
|
||||
let hasErrors = false;
|
||||
productsBody.querySelectorAll('tr').forEach(row => {
|
||||
const productSelect = row.querySelector('.product-select');
|
||||
const quantityInput = row.querySelector('.quantity-input');
|
||||
const priceInput = row.querySelector('.price-input');
|
||||
|
||||
const productError = row.querySelector('td:nth-child(1) .error-message');
|
||||
const quantityError = row.querySelector('td:nth-child(2) .error-message');
|
||||
const priceError = row.querySelector('td:nth-child(3) .error-message');
|
||||
|
||||
let rowHasError = false;
|
||||
|
||||
if (!productSelect.value) {
|
||||
productError.textContent = 'Выберите товар';
|
||||
productError.style.display = 'block';
|
||||
hasErrors = true;
|
||||
rowHasError = true;
|
||||
} else {
|
||||
productError.style.display = 'none';
|
||||
}
|
||||
|
||||
const quantity = parseFloat(quantityInput.value) || 0;
|
||||
if (quantity <= 0) {
|
||||
quantityError.textContent = 'Количество должно быть > 0';
|
||||
quantityError.style.display = 'block';
|
||||
hasErrors = true;
|
||||
rowHasError = true;
|
||||
} else {
|
||||
quantityError.style.display = 'none';
|
||||
}
|
||||
|
||||
const price = parseFloat(priceInput.value) || 0;
|
||||
if (price < 0) {
|
||||
priceError.textContent = 'Цена не может быть отрицательной';
|
||||
priceError.style.display = 'block';
|
||||
hasErrors = true;
|
||||
rowHasError = true;
|
||||
} else {
|
||||
priceError.style.display = 'none';
|
||||
}
|
||||
|
||||
if (rowHasError) {
|
||||
row.classList.add('row-error');
|
||||
} else {
|
||||
row.classList.remove('row-error');
|
||||
}
|
||||
});
|
||||
|
||||
if (hasErrors) {
|
||||
e.preventDefault();
|
||||
alert('Пожалуйста, исправьте ошибки в форме.');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,48 @@
|
||||
{% extends 'inventory/base_inventory.html' %}
|
||||
|
||||
{% block inventory_title %}Отмена приходу товара{% endblock %}
|
||||
|
||||
{% block inventory_content %}
|
||||
<div class="card border-danger">
|
||||
<div class="card-header bg-danger text-white">
|
||||
<h4 class="mb-0">Подтверждение отмены</h4>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="alert alert-warning">
|
||||
<i class="bi bi-exclamation-triangle"></i>
|
||||
<strong>Внимание!</strong> Вы собираетесь отменить приход товара.
|
||||
</div>
|
||||
|
||||
<p class="text-muted">
|
||||
Это действие удалит запись о приходе товара и может повлиять на остатки на складе.
|
||||
</p>
|
||||
|
||||
<div class="alert alert-info">
|
||||
<h5>Информация о приходе:</h5>
|
||||
<ul class="mb-0">
|
||||
<li><strong>Товар:</strong> {{ incoming.product.name }}</li>
|
||||
<li><strong>Склад:</strong> {{ incoming.warehouse.name }}</li>
|
||||
<li><strong>Количество:</strong> {{ incoming.quantity }} шт</li>
|
||||
<li><strong>Цена закупки:</strong> {{ incoming.cost_price }} ₽</li>
|
||||
{% if incoming.document_number %}
|
||||
<li><strong>Номер документа:</strong> {{ incoming.document_number }}</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<form method="post" class="mt-4">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-danger">
|
||||
<i class="bi bi-trash"></i> Подтвердить отмену
|
||||
</button>
|
||||
<a href="{% url 'inventory:incoming-list' %}" class="btn btn-secondary">
|
||||
<i class="bi bi-x-circle"></i> Вернуться
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,125 @@
|
||||
{% extends 'inventory/base_inventory.html' %}
|
||||
|
||||
{% block inventory_title %}
|
||||
{% if form.instance.pk %}
|
||||
Редактирование приходу товара
|
||||
{% else %}
|
||||
Новый приход товара
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block inventory_content %}
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="mb-0">
|
||||
{% if form.instance.pk %}
|
||||
Редактирование приходу
|
||||
{% else %}
|
||||
Регистрация нового поступления
|
||||
{% endif %}
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form method="post" class="form">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="{{ form.product.id_for_label }}" class="form-label">
|
||||
{{ form.product.label }} <span class="text-danger">*</span>
|
||||
</label>
|
||||
{{ form.product }}
|
||||
{% if form.product.errors %}
|
||||
<div class="invalid-feedback d-block">
|
||||
{% for error in form.product.errors %}{{ error }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="{{ form.warehouse.id_for_label }}" class="form-label">
|
||||
{{ form.warehouse.label }} <span class="text-danger">*</span>
|
||||
</label>
|
||||
{{ form.warehouse }}
|
||||
{% if form.warehouse.errors %}
|
||||
<div class="invalid-feedback d-block">
|
||||
{% for error in form.warehouse.errors %}{{ error }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="{{ form.quantity.id_for_label }}" class="form-label">
|
||||
{{ form.quantity.label }} <span class="text-danger">*</span>
|
||||
</label>
|
||||
{{ form.quantity }}
|
||||
{% if form.quantity.errors %}
|
||||
<div class="invalid-feedback d-block">
|
||||
{% for error in form.quantity.errors %}{{ error }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="{{ form.cost_price.id_for_label }}" class="form-label">
|
||||
{{ form.cost_price.label }} <span class="text-danger">*</span>
|
||||
</label>
|
||||
{{ form.cost_price }}
|
||||
{% if form.cost_price.errors %}
|
||||
<div class="invalid-feedback d-block">
|
||||
{% for error in form.cost_price.errors %}{{ error }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="{{ form.document_number.id_for_label }}" class="form-label">
|
||||
{{ form.document_number.label }}
|
||||
</label>
|
||||
{{ form.document_number }}
|
||||
{% if form.document_number.errors %}
|
||||
<div class="invalid-feedback d-block">
|
||||
{% for error in form.document_number.errors %}{{ error }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="{{ form.notes.id_for_label }}" class="form-label">
|
||||
{{ form.notes.label }}
|
||||
</label>
|
||||
{{ form.notes }}
|
||||
{% if form.notes.errors %}
|
||||
<div class="invalid-feedback d-block">
|
||||
{% for error in form.notes.errors %}{{ error }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-circle"></i>
|
||||
{% if form.instance.pk %}
|
||||
Сохранить
|
||||
{% else %}
|
||||
Создать
|
||||
{% endif %}
|
||||
</button>
|
||||
<a href="{% url 'inventory:incoming-list' %}" class="btn btn-secondary">
|
||||
<i class="bi bi-x-circle"></i> Отменить
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
select, textarea, input {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,112 @@
|
||||
{% extends 'inventory/base_inventory.html' %}
|
||||
|
||||
{% block inventory_title %}История приходов товара{% endblock %}
|
||||
|
||||
{% block inventory_content %}
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h4 class="mb-0">Приходы товара</h4>
|
||||
<a href="{% url 'inventory:incoming-create' %}" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-plus-circle"></i> Новый приход
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
{% if incomings %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Товар</th>
|
||||
<th>Склад</th>
|
||||
<th>Количество</th>
|
||||
<th>Цена закупки</th>
|
||||
<th>Номер документа</th>
|
||||
<th>Партия</th>
|
||||
<th>Дата</th>
|
||||
<th class="text-end">Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for incoming in incomings %}
|
||||
<tr>
|
||||
<td><strong>{{ incoming.product.name }}</strong></td>
|
||||
<td>{{ incoming.batch.warehouse.name }}</td>
|
||||
<td>{{ incoming.quantity }} шт</td>
|
||||
<td>{{ incoming.cost_price }} ₽</td>
|
||||
<td>
|
||||
{% if incoming.batch.document_number %}
|
||||
<code>{{ incoming.batch.document_number }}</code>
|
||||
{% else %}
|
||||
<span class="text-muted">—</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if incoming.stock_batch %}
|
||||
<a href="{% url 'inventory:batch-detail' incoming.stock_batch.pk %}" title="Перейти к партии на складе">
|
||||
<strong>#{{ incoming.stock_batch.pk }}</strong>
|
||||
</a>
|
||||
{% else %}
|
||||
<span class="badge bg-warning">Не назначена</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ incoming.created_at|date:"d.m.Y H:i" }}</td>
|
||||
<td class="text-end">
|
||||
<a href="{% url 'inventory:incoming-update' incoming.pk %}" class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</a>
|
||||
<a href="{% url 'inventory:incoming-delete' incoming.pk %}" class="btn btn-sm btn-outline-danger">
|
||||
<i class="bi bi-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Пагинация -->
|
||||
{% if is_paginated %}
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
{% if page_obj.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page=1">Первая</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">Предыдущая</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% for num in page_obj.paginator.page_range %}
|
||||
{% if page_obj.number == num %}
|
||||
<li class="page-item active">
|
||||
<span class="page-link">{{ num }}</span>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ num }}">{{ num }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.next_page_number }}">Следующая</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">Последняя</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="alert alert-info">
|
||||
<i class="bi bi-info-circle"></i> Приходов не найдено.
|
||||
<a href="{% url 'inventory:incoming-create' %}" class="alert-link">Зарегистрировать новый приход</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user