Improve status code label rendering

This commit is contained in:
Oliver Walters 2020-04-26 15:29:21 +10:00
parent 0892b160c6
commit 4147163418
9 changed files with 122 additions and 53 deletions

View File

@ -3,6 +3,12 @@
--secondary-color: #b69c80;
--highlight-color: #f5efe8;
--basic-color: #333;
--label-red: #e35a57;
--label-blue: #4194bd;
--label-green: #50aa51;
--label-grey: #aaa;
--label-yellow: #fdc82a;
}
.markdownx .row {
@ -158,6 +164,51 @@
padding-bottom: 5px;
}
.label-large-red {
color: var(--label-red);
border-color: var(--label-red);
}
.label-red {
background: var(--label-red);
}
.label-large-blue {
color: var(--label-blue);
border-color: var(--label-blue);
}
.label-blue {
background: var(--label-blue);
}
.label-large-green {
color: var(--label-green);
border-color: var(--label-green);
}
.label-green {
background: var(--label-green);
}
.label-large-grey {
color: var(--label-grey);
border-color: var(--label-grey);
}
.label-grey {
background: var(--label-grey);
}
.label-large-yellow {
color: var(--label-yellow);
border-color: var(--label-yellow);
}
.label-yellow {
background: var(--label-yellow);
}
.label-right {
float: right;
margin-left: 3px;

View File

@ -238,7 +238,12 @@ function loadSalesOrderTable(table, options) {
{
sortable: true,
field: 'creation_date',
title: 'Date',
title: 'Creation Date',
},
{
sortable: true,
field: 'shipment_date',
title: "Shipment Date",
},
{
sortable: true,

View File

@ -7,14 +7,6 @@ class StatusCode:
This is used to map a set of integer values to text.
"""
# Colors used for label rendering
LBL_WHITE = '#FFF'
LBL_GREY = "#AAA"
LBL_GREEN = "#50aa51"
LBL_BLUE = "#4194bd"
LBL_YELLOW = "#fdc82a"
LBL_RED = "#e35a57"
@classmethod
def render(cls, key, large=False):
"""
@ -26,18 +18,15 @@ class StatusCode:
return key
value = cls.options.get(key, key)
color = cls.colors.get(key, StatusCode.LBL_GREY)
color = cls.colors.get(key, 'grey')
if large:
span_class = 'label label-large'
style = 'color: {c}; border-color: {c}; background: none;'.format(c=color)
span_class = 'label label-large label-large-{c}'.format(c=color)
else:
span_class = 'label'
style = 'color: {w}; background: {c}'.format(w=StatusCode.LBL_WHITE, c=color)
span_class = 'label label-{c}'.format(c=color)
return "<span class='{cl}' style='{st}'>{value}</span>".format(
return "<span class='{cl}'>{value}</span>".format(
cl=span_class,
st=style,
value=value
)
@ -107,12 +96,12 @@ class PurchaseOrderStatus(StatusCode):
}
colors = {
PENDING: StatusCode.LBL_BLUE,
PLACED: StatusCode.LBL_BLUE,
COMPLETE: StatusCode.LBL_GREEN,
CANCELLED: StatusCode.LBL_RED,
LOST: StatusCode.LBL_YELLOW,
RETURNED: StatusCode.LBL_YELLOW,
PENDING: 'blue',
PLACED: 'blue',
COMPLETE: 'green',
CANCELLED: 'red',
LOST: 'yellow',
RETURNED: 'yellow',
}
# Open orders
@ -147,11 +136,11 @@ class SalesOrderStatus(StatusCode):
}
colors = {
PENDING: StatusCode.LBL_BLUE,
SHIPPED: StatusCode.LBL_GREEN,
CANCELLED: StatusCode.LBL_RED,
LOST: StatusCode.LBL_YELLOW,
RETURNED: StatusCode.LBL_YELLOW,
PENDING: 'blue',
SHIPPED: 'green',
CANCELLED: 'red',
LOST: 'yellow',
RETURNED: 'yellow',
}
@ -168,7 +157,7 @@ class StockStatus(StatusCode):
# This can be used as a quick check for filtering
NOT_IN_STOCK = 100
SENT_TO_CUSTOMER = 110 # Item has been shipped to a customer
SHIPPED = 110 # Item has been shipped to a customer
ASSIGNED_TO_BUILD = 120
ASSIGNED_TO_OTHER_ITEM = 130
@ -179,13 +168,19 @@ class StockStatus(StatusCode):
DESTROYED: _("Destroyed"),
LOST: _("Lost"),
RETURNED: _("Returned"),
SHIPPED: _('Shipped'),
ASSIGNED_TO_BUILD: _("Used for Build"),
ASSIGNED_TO_OTHER_ITEM: _("Installed in Stock Item")
}
colors = {
OK: StatusCode.LBL_GREEN,
ATTENTION: StatusCode.LBL_YELLOW,
DAMAGED: StatusCode.LBL_RED,
DESTROYED: StatusCode.LBL_RED,
OK: 'green',
ATTENTION: 'yellow',
DAMAGED: 'red',
DESTROYED: 'red',
SHIPPED: 'green',
ASSIGNED_TO_BUILD: 'blue',
ASSIGNED_TO_OTHER_ITEM: 'blue',
}
# The following codes correspond to parts that are 'available' or 'in stock'
@ -201,6 +196,8 @@ class StockStatus(StatusCode):
DESTROYED,
LOST,
SHIPPED,
ASSIGNED_TO_BUILD,
ASSIGNED_TO_OTHER_ITEM,
]
@ -220,10 +217,10 @@ class BuildStatus(StatusCode):
}
colors = {
PENDING: StatusCode.LBL_BLUE,
ALLOCATED: StatusCode.LBL_BLUE,
COMPLETE: StatusCode.LBL_GREEN,
CANCELLED: StatusCode.LBL_RED,
PENDING: 'blue',
ALLOCATED: 'blue',
COMPLETE: 'green',
CANCELLED: 'red',
}
ACTIVE_CODES = [

View File

@ -38,7 +38,6 @@ class BuildList(generics.ListCreateAPIView):
]
filter_fields = [
'part',
'sales_order',
]
@ -48,15 +47,25 @@ class BuildList(generics.ListCreateAPIView):
as some of the fields don't natively play nicely with DRF
"""
build_list = super().get_queryset()
queryset = super().get_queryset().prefetch_related('part')
return queryset
def filter_queryset(self, queryset):
# Filter by build status?
status = self.request.query_params.get('status', None)
if status is not None:
build_list = build_list.filter(status=status)
queryset = queryset.filter(status=status)
return build_list
# Filter by associated part?
part = self.request.query_params.get('part', None)
if part is not None:
queryset = queryset.filter(part=part)
return queryset
def get_serializer(self, *args, **kwargs):

View File

@ -583,6 +583,6 @@ class SalesOrderAllocation(models.Model):
# Clear the location
item.location = None
item.status = StockStatus.SENT_TO_CUSTOMER
item.status = StockStatus.SHIPPED
item.save()

View File

@ -152,6 +152,7 @@ class SalesOrderSerializer(InvenTreeModelSerializer):
'customer_reference',
'status',
'status_text',
'shipment_date',
'notes',
]

View File

@ -6,7 +6,7 @@
<a href="{% url 'part-detail' part.id %}">{% trans "Details" %}</a>
</li>
<li{% ifequal tab 'params' %} class='active'{% endifequal %}>
<a href="{% url 'part-params' part.id %}">{% trans "Parameters" %} <span class='badge'>{{ part.parameters.count }}</span></a>
<a href="{% url 'part-params' part.id %}">{% trans "Parameters" %}<span class='badge'>{{ part.parameters.count }}</span></a>
</li>
{% if part.is_template %}
<li{% ifequal tab 'variants' %} class='active'{% endifequal %}>
@ -25,7 +25,7 @@
<li{% ifequal tab 'bom' %} class="active"{% endifequal %}>
<a href="{% url 'part-bom' part.id %}">{% trans "BOM" %}<span class="badge{% if part.is_bom_valid == False %} badge-alert{% endif %}">{{ part.bom_count }}</span></a></li>
<li{% ifequal tab 'build' %} class="active"{% endifequal %}>
<a href="{% url 'part-build' part.id %}">{% trans "Build Orders" %}<span class='badge'>{{ part.active_builds|length }}</span></a></li>
<a href="{% url 'part-build' part.id %}">{% trans "Build Orders" %}<span class='badge'>{{ part.builds.count }}</span></a></li>
{% endif %}
{% if part.component or part.used_in_count > 0 %}
<li{% ifequal tab 'used' %} class="active"{% endifequal %}>
@ -60,6 +60,6 @@
<a href="{% url 'part-attachments' part.id %}">{% trans "Attachments" %} {% if part.attachment_count > 0 %}<span class="badge">{{ part.attachment_count }}</span>{% endif %}</a>
</li>
<li{% ifequal tab 'notes' %} class="active"{% endifequal %}>
<a href="{% url 'part-notes' part.id %}">{% trans "Notes" %}{% if part.notes %} <span class='glyphicon glyphicon-small glyphicon-info-sign'></span>{% endif %}</a>
<a href="{% url 'part-notes' part.id %}">{% trans "Notes" %}{% if part.notes %} <span class='fas fa-info-circle'></span>{% endif %}</a>
</li>
</ul>

View File

@ -41,7 +41,7 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<div class='alert alert-block alert-warning'>
{% trans "This stock item cannot be deleted as it has child items" %}
</div>
{% elif item.delete_on_deplete %}
{% elif item.delete_on_deplete and item.can_delete %}
<div class='alert alert-block alert-warning'>
{% trans "This stock item will be automatically deleted when all stock is depleted." %}
</div>
@ -59,7 +59,7 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
{% endblock %}
{% block page_data %}
<h3>{% trans "Stock Item" %}</h3>
<h3>{% trans "Stock Item" %}{% if item.status in StockStatus.UNAVAILABLE_CODES %}{% stock_status_label item.status large=True %}{% endif %}</h3>
<hr>
<h4>
{% if item.serialized %}
@ -125,6 +125,12 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<td>{% trans "Belongs To" %}</td>
<td><a href="{% url 'stock-item-detail' item.belongs_to.id %}">{{ item.belongs_to }}</a></td>
</tr>
{% elif item.customer %}
<tr>
<td><span class='fas fa-user-tie'></span></td>
<td>{% trans "Customer" %}</td>
<td><a href="{% url 'company-detail' item.customer.id %}">{{ item.customer.name }}</a></td>
</tr>
{% elif item.location %}
<tr>
<td><span class='fas fa-map-marker-alt'></span></td>
@ -173,11 +179,11 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<td><a href="{% url 'po-detail' item.purchase_order.id %}">{{ item.purchase_order }}</a></td>
</tr>
{% endif %}
{% if item.customer %}
{% if item.parent %}
<tr>
<td></td>
<td>{% trans "Customer" %}</td>
<td>{{ item.customer.name }}</td>
<td><span class='fas fa-sitemap'></span></td>
<td>{% trans "Parent Item" %}</td>
<td><a href="{% url 'stock-item-detail' item.parent.id %}">{{ item.parent }}</a></td>
</tr>
{% endif %}
{% if item.link %}

View File

@ -5,7 +5,7 @@ var {{ label }}Codes = {
{% for opt in options %}'{{ opt.key }}': {
key: '{{ opt.key }}',
value: '{{ opt.value }}',{% if opt.color %}
color: '{{ opt.color }}',{% endif %}
label: 'label-{{ opt.color }}',{% endif %}
},{% endfor %}
};
@ -25,7 +25,7 @@ function {{ label }}StatusDisplay(key) {
}
// Select the label color
var color = {{ label }}Codes[key].color ?? '#AAA';
var label = {{ label }}Codes[key].label ?? '';
return `<span class='label' style='background: ${color};'>${value}</span>`;
return `<span class='label ${label}'>${value}</span>`;
}