Добавлено отображение единиц продажи на странице товара
На странице детализации товара теперь отображается таблица с единицами продажи: название, единица измерения, коэффициент, цена, мин. количество и шаг. Единица по умолчанию выделена зелёным. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -142,11 +142,11 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Остаток:</th>
|
<th>Остаток:</th>
|
||||||
<td>
|
<td>
|
||||||
<strong class="fs-5 {% if product.total_free > 0 %}text-success{% else %}text-danger{% endif %}">{{ product.total_free|floatformat:0 }}</strong> <span class="text-muted">свободно</span>
|
<strong class="fs-5 {% if product.total_free > 0 %}text-success{% else %}text-danger{% endif %}">{{ product.total_free|floatformat:-2 }}</strong> <span class="text-muted">свободно</span>
|
||||||
{% if product.total_reserved > 0 %}
|
{% if product.total_reserved > 0 %}
|
||||||
<a href="{% url 'inventory:reservation-list' %}?product={{ product.pk }}" class="ms-2 text-warning text-decoration-none" target="_blank" title="Посмотреть резервы"><i class="bi bi-lock"></i> {{ product.total_reserved|floatformat:0 }} в резерве <i class="bi bi-box-arrow-up-right small"></i></a>
|
<a href="{% url 'inventory:reservation-list' %}?product={{ product.pk }}" class="ms-2 text-warning text-decoration-none" target="_blank" title="Посмотреть резервы"><i class="bi bi-lock"></i> {{ product.total_reserved|floatformat:-2 }} в резерве <i class="bi bi-box-arrow-up-right small"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="ms-2 text-muted small">(всего: {{ product.total_available|floatformat:0 }})</span>
|
<span class="ms-2 text-muted small">(всего: {{ product.total_available|floatformat:-2 }})</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -283,6 +283,51 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if sales_units %}
|
||||||
|
<tr>
|
||||||
|
<th>Единицы продажи:</th>
|
||||||
|
<td>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-sm table-bordered mb-0">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Название</th>
|
||||||
|
<th>Единица</th>
|
||||||
|
<th class="text-end">Коэфф.</th>
|
||||||
|
<th class="text-end">Цена</th>
|
||||||
|
<th class="text-center">Мин. кол-во</th>
|
||||||
|
<th class="text-center">Шаг</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for su in sales_units %}
|
||||||
|
<tr{% if su.is_default %} class="table-success"{% endif %}>
|
||||||
|
<td>
|
||||||
|
{{ su.name }}
|
||||||
|
{% if su.is_default %}<span class="badge bg-success ms-1">По умолчанию</span>{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-secondary">{{ su.unit.short_name }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-end">{{ su.conversion_factor }}</td>
|
||||||
|
<td class="text-end">
|
||||||
|
{% if su.sale_price %}
|
||||||
|
<span class="text-decoration-line-through text-muted">{{ su.price }}</span>
|
||||||
|
<strong class="text-danger">{{ su.sale_price }}</strong> руб.
|
||||||
|
{% else %}
|
||||||
|
<strong>{{ su.price }}</strong> руб.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="text-center">{{ su.min_quantity }}</td>
|
||||||
|
<td class="text-center">{{ su.quantity_step }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Статус:</th>
|
<th>Статус:</th>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ class ProductDetailView(LoginRequiredMixin, ManagerOwnerRequiredMixin, DetailVie
|
|||||||
return super().get_queryset().prefetch_related(
|
return super().get_queryset().prefetch_related(
|
||||||
'photos',
|
'photos',
|
||||||
'categories',
|
'categories',
|
||||||
'tags'
|
'tags',
|
||||||
|
'sales_units__unit'
|
||||||
).annotate(
|
).annotate(
|
||||||
total_available=total_available,
|
total_available=total_available,
|
||||||
total_reserved=total_reserved,
|
total_reserved=total_reserved,
|
||||||
@@ -185,7 +186,10 @@ class ProductDetailView(LoginRequiredMixin, ManagerOwnerRequiredMixin, DetailVie
|
|||||||
# Кешируем cost_price_details, чтобы не делать множественные запросы к БД
|
# Кешируем cost_price_details, чтобы не делать множественные запросы к БД
|
||||||
from ..services.cost_calculator import ProductCostCalculator
|
from ..services.cost_calculator import ProductCostCalculator
|
||||||
context['cost_price_details'] = ProductCostCalculator.get_cost_details(self.object)
|
context['cost_price_details'] = ProductCostCalculator.get_cost_details(self.object)
|
||||||
|
|
||||||
|
# Единицы продажи (активные, отсортированные)
|
||||||
|
context['sales_units'] = self.object.sales_units.filter(is_active=True).order_by('position', 'name')
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user