Убраны лишние нули в отображении количества товаров

- Используется фильтр smart_quantity вместо floatformat
- Целые числа отображаются без дробной части: 2 вместо 2,000
- Дробные числа без лишних нулей: 2,5 вместо 2,500
- Запятая используется вместо точки (русский формат)
- JavaScript также форматирует количество после сохранения
- Улучшена читаемость для работы с цветами и штучными товарами
This commit is contained in:
2025-12-11 00:17:45 +03:00
parent e9fb776b6f
commit b2a29bf1aa

View File

@@ -1,5 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %} {% load static %}
{% load inventory_filters %}
{% block title %}Документ списания {{ document.document_number }}{% endblock %} {% block title %}Документ списания {{ document.document_number }}{% endblock %}
@@ -194,7 +195,7 @@
<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 text-end"> <td class="px-3 py-2 text-end">
<span class="item-quantity-display">{{ item.quantity }}</span> <span class="item-quantity-display">{{ item.quantity|smart_quantity }}</span>
{% if document.can_edit %} {% if document.can_edit %}
<input type="number" class="form-control form-control-sm item-quantity-input" <input type="number" class="form-control form-control-sm item-quantity-input"
value="{{ item.quantity }}" step="0.001" min="0.001" value="{{ item.quantity }}" step="0.001" min="0.001"
@@ -260,7 +261,7 @@
<tfoot class="table-light"> <tfoot class="table-light">
<tr> <tr>
<td class="px-3 py-2 fw-semibold">Итого:</td> <td class="px-3 py-2 fw-semibold">Итого:</td>
<td class="px-3 py-2 text-end fw-semibold">{{ document.total_quantity }}</td> <td class="px-3 py-2 fw-semibold">{{ document.total_quantity|smart_quantity }}</td>
<td colspan="{% if document.can_edit %}3{% else %}2{% endif %}"></td> <td colspan="{% if document.can_edit %}3{% else %}2{% endif %}"></td>
</tr> </tr>
</tfoot> </tfoot>
@@ -465,7 +466,16 @@ document.addEventListener('DOMContentLoaded', function() {
.then(data => { .then(data => {
if (data.success) { if (data.success) {
// Обновляем отображение // Обновляем отображение
row.querySelector('.item-quantity-display').textContent = quantity; // Форматируем количество: убираем лишние нули, целые без дробной части
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;
const reasonSelect = row.querySelector('.item-reason-input'); const reasonSelect = row.querySelector('.item-reason-input');
const reasonLabel = reasonSelect.options[reasonSelect.selectedIndex].text; const reasonLabel = reasonSelect.options[reasonSelect.selectedIndex].text;
row.querySelector('.item-reason-display').innerHTML = `<span class="badge bg-light text-dark">${reasonLabel}</span>`; row.querySelector('.item-reason-display').innerHTML = `<span class="badge bg-light text-dark">${reasonLabel}</span>`;