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; --secondary-color: #b69c80;
--highlight-color: #f5efe8; --highlight-color: #f5efe8;
--basic-color: #333; --basic-color: #333;
--label-red: #e35a57;
--label-blue: #4194bd;
--label-green: #50aa51;
--label-grey: #aaa;
--label-yellow: #fdc82a;
} }
.markdownx .row { .markdownx .row {
@ -158,6 +164,51 @@
padding-bottom: 5px; 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 { .label-right {
float: right; float: right;
margin-left: 3px; margin-left: 3px;

View File

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

View File

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

View File

@ -38,7 +38,6 @@ class BuildList(generics.ListCreateAPIView):
] ]
filter_fields = [ filter_fields = [
'part',
'sales_order', 'sales_order',
] ]
@ -48,15 +47,25 @@ class BuildList(generics.ListCreateAPIView):
as some of the fields don't natively play nicely with DRF 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? # Filter by build status?
status = self.request.query_params.get('status', None) status = self.request.query_params.get('status', None)
if status is not 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): def get_serializer(self, *args, **kwargs):

View File

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

View File

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

View File

@ -6,7 +6,7 @@
<a href="{% url 'part-detail' part.id %}">{% trans "Details" %}</a> <a href="{% url 'part-detail' part.id %}">{% trans "Details" %}</a>
</li> </li>
<li{% ifequal tab 'params' %} class='active'{% endifequal %}> <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> </li>
{% if part.is_template %} {% if part.is_template %}
<li{% ifequal tab 'variants' %} class='active'{% endifequal %}> <li{% ifequal tab 'variants' %} class='active'{% endifequal %}>
@ -25,7 +25,7 @@
<li{% ifequal tab 'bom' %} class="active"{% endifequal %}> <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> <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 %}> <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 %} {% endif %}
{% if part.component or part.used_in_count > 0 %} {% if part.component or part.used_in_count > 0 %}
<li{% ifequal tab 'used' %} class="active"{% endifequal %}> <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> <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>
<li{% ifequal tab 'notes' %} class="active"{% endifequal %}> <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> </li>
</ul> </ul>

View File

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

View File

@ -5,7 +5,7 @@ var {{ label }}Codes = {
{% for opt in options %}'{{ opt.key }}': { {% for opt in options %}'{{ opt.key }}': {
key: '{{ opt.key }}', key: '{{ opt.key }}',
value: '{{ opt.value }}',{% if opt.color %} value: '{{ opt.value }}',{% if opt.color %}
color: '{{ opt.color }}',{% endif %} label: 'label-{{ opt.color }}',{% endif %}
},{% endfor %} },{% endfor %}
}; };
@ -25,7 +25,7 @@ function {{ label }}StatusDisplay(key) {
} }
// Select the label color // 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>`;
} }