Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move stock table to partial template

Marcin Gębala7803af9eb9f0
diff --git a/templates/dashboard/product/_stock_table.html b/templates/dashboard/product/_stock_table.html
new file mode 100644
index 0000000000..e247640a21
--- /dev/null
+++ b/templates/dashboard/product/_stock_table.html
@@ -0,0 +1,27 @@
+{% load i18n %}
+{% load prices_i18n %}
+
+<table class="bordered highlight responsive data-table">
+ <thead>
+ <tr>
+ <th class="wide">{% trans "Location" %}</th>
+ <th>{% trans "Quantity" %}</th>
+ <th>{% trans "Allocated" %}</th>
+ <th class="right-align">{% trans "Cost" %}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for stock_item in stock %}
+ <tr class="{% if stock_item.quantity_available == 0 %}danger{% endif %}" data-action-go="{% url "dashboard:variant-stock-details" product_pk=product.pk variant_pk=variant.pk stock_pk=stock_item.pk %}">
+ <td class="wide">{{ stock_item.location }}</td>
+ <td>{{ stock_item.quantity }}</td>
+ <td>{{ stock_item.quantity_allocated }}</td>
+ <td class="right-align">{% if stock_item.cost_price %}{% gross stock_item.cost_price %}{% else %}-{% endif %}</td>
+ </tr>
+ {% empty %}
+ <tr>
+ <td colspan="4">{% trans "No stock records found" context "Dashboard variant details page" %}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+</table>
diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.html
index b290c57523..37ae280f42 100644
--- a/templates/dashboard/product/detail.html
+++ b/templates/dashboard/product/detail.html
@@ -134,30 +134,7 @@
</a>
</div>
<div class="data-table-container">
- <table class="bordered highlight responsive data-table">
- <thead>
- <tr>
- <th class="wide">{% trans "Location" %}</th>
- <th>{% trans "Quantity" %}</th>
- <th>{% trans "Allocated" %}</th>
- <th class="right-align">{% trans "Cost" %}</th>
- </tr>
- </thead>
- <tbody>
- {% for stock_item in stock %}
- <tr data-action-go="{% url "dashboard:variant-stock-details" product_pk=product.pk variant_pk=only_variant.pk stock_pk=stock_item.pk %}">
- <td class="wide">{{ stock_item.location }}</td>
- <td>{{ stock_item.quantity }}</td>
- <td>{{ stock_item.quantity_allocated }}</td>
- <td class="right-align">{% if stock_item.cost_price %}{% gross stock_item.cost_price %}{% else %}-{% endif %}</td>
- </tr>
- {% empty %}
- <tr>
- <td colspan="4">{% trans "No stock records found" context "Dashboard variant details page" %}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
+ {% include "dashboard/product/_stock_table.html" with product=product variant=only_variant stock=stock %}
</div>
</div>
{% endif %}
diff --git a/templates/dashboard/product/product_variant/detail.html b/templates/dashboard/product/product_variant/detail.html
index ec28e4d635..6b6401e357 100644
--- a/templates/dashboard/product/product_variant/detail.html
+++ b/templates/dashboard/product/product_variant/detail.html
@@ -82,30 +82,7 @@
</a>
</div>
<div class="data-table-container">
- <table class="bordered highlight responsive data-table">
- <thead>
- <tr>
- <th class="wide">{% trans "Location" %}</th>
- <th>{% trans "Quantity" %}</th>
- <th>{% trans "Allocated" %}</th>
- <th class="right-align">{% trans "Cost" %}</th>
- </tr>
- </thead>
- <tbody>
- {% for stock_item in stock %}
- <tr class="{% if stock_item.quantity_available == 0 %}danger{% endif %}" data-action-go="{% url "dashboard:variant-stock-details" product_pk=product.pk variant_pk=variant.pk stock_pk=stock_item.pk %}">
- <td class="wide">{{ stock_item.location }}</td>
- <td>{{ stock_item.quantity }}</td>
- <td>{{ stock_item.quantity_allocated }}</td>
- <td class="right-align">{% if stock_item.cost_price %}{% gross stock_item.cost_price %}{% else %}-{% endif %}</td>
- </tr>
- {% empty %}
- <tr>
- <td colspan="4">{% trans "No stock records found" context "Dashboard variant details page" %}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
+ {% include "dashboard/product/_stock_table.html" with product=product variant=variant stock=stock %}
</div>
</div>
</div>