Build order barcodes (#4581)

* Adds barcode support for BuildOrder model

* Add barcode_hash to serializer

* Add assign functionality for build

* Add UI elements
This commit is contained in:
Oliver 2023-04-05 00:00:24 +10:00 committed by GitHub
parent 7656f30d02
commit 508dd5425d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 2 deletions

View File

@ -11,6 +11,7 @@ v107 -> 2023-04-04 : https://github.com/inventree/InvenTree/pull/4575
- Adds barcode support for PurchaseOrder model - Adds barcode support for PurchaseOrder model
- Adds barcode support for ReturnOrder model - Adds barcode support for ReturnOrder model
- Adds barcode support for SalesOrder model - Adds barcode support for SalesOrder model
- Adds barcode support for BuildOrder model
v106 -> 2023-04-03 : https://github.com/inventree/InvenTree/pull/4566 v106 -> 2023-04-03 : https://github.com/inventree/InvenTree/pull/4566
- Adds 'search_regex' parameter to all searchable API endpoints - Adds 'search_regex' parameter to all searchable API endpoints

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.18 on 2023-04-04 13:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('build', '0039_auto_20230317_0816'),
]
operations = [
migrations.AddField(
model_name='build',
name='barcode_data',
field=models.CharField(blank=True, help_text='Third party barcode data', max_length=500, verbose_name='Barcode Data'),
),
migrations.AddField(
model_name='build',
name='barcode_hash',
field=models.CharField(blank=True, help_text='Unique hash of barcode data', max_length=128, verbose_name='Barcode Hash'),
),
]

View File

@ -23,7 +23,7 @@ from rest_framework import serializers
from InvenTree.status_codes import BuildStatus, StockStatus, StockHistoryCode from InvenTree.status_codes import BuildStatus, StockStatus, StockHistoryCode
from InvenTree.helpers import increment, normalize, notify_responsible from InvenTree.helpers import increment, normalize, notify_responsible
from InvenTree.models import InvenTreeAttachment, ReferenceIndexingMixin from InvenTree.models import InvenTreeAttachment, InvenTreeBarcodeMixin, ReferenceIndexingMixin
from build.validators import generate_next_build_reference, validate_build_order_reference from build.validators import generate_next_build_reference, validate_build_order_reference
@ -42,7 +42,7 @@ import stock.models
import users.models import users.models
class Build(MPTTModel, MetadataMixin, ReferenceIndexingMixin): class Build(MPTTModel, InvenTreeBarcodeMixin, MetadataMixin, ReferenceIndexingMixin):
"""A Build object organises the creation of new StockItem objects from other existing StockItem objects. """A Build object organises the creation of new StockItem objects from other existing StockItem objects.
Attributes: Attributes:

View File

@ -37,6 +37,7 @@ class BuildSerializer(InvenTreeModelSerializer):
'pk', 'pk',
'url', 'url',
'title', 'title',
'barcode_hash',
'batch', 'batch',
'creation_date', 'creation_date',
'completed', 'completed',
@ -84,6 +85,8 @@ class BuildSerializer(InvenTreeModelSerializer):
responsible_detail = OwnerSerializer(source='responsible', read_only=True) responsible_detail = OwnerSerializer(source='responsible', read_only=True)
barcode_hash = serializers.CharField(read_only=True)
@staticmethod @staticmethod
def annotate_queryset(queryset): def annotate_queryset(queryset):
"""Add custom annotations to the BuildSerializer queryset, performing database queries as efficiently as possible. """Add custom annotations to the BuildSerializer queryset, performing database queries as efficiently as possible.

View File

@ -33,6 +33,24 @@ src="{% static 'img/blank_image.png' %}"
{% url 'admin:build_build_change' build.pk as url %} {% url 'admin:build_build_change' build.pk as url %}
{% include "admin_button.html" with url=url %} {% include "admin_button.html" with url=url %}
{% endif %} {% endif %}
{% if barcodes %}
<!-- Barcode actions menu -->
<div class='btn-group' role='group'>
<button id='barcode-options' title='{% trans "Barcode actions" %}' class='btn btn-outline-secondary dropdown-toggle' type='button' data-bs-toggle='dropdown'>
<span class='fas fa-qrcode'></span> <span class='caret'></span>
</button>
<ul class='dropdown-menu' role='menu'>
<li><a class='dropdown-item' href='#' id='show-qr-code'><span class='fas fa-qrcode'></span> {% trans "Show QR Code" %}</a></li>
{% if roles.build.change %}
{% if order.barcode_hash %}
<li><a class='dropdown-item' href='#' id='barcode-unlink'><span class='fas fa-unlink'></span> {% trans "Unlink Barcode" %}</a></li>
{% else %}
<li><a class='dropdown-item' href='#' id='barcode-link'><span class='fas fa-link'></span> {% trans "Link Barcode" %}</a></li>
{% endif %}
{% endif %}
</ul>
</div>
{% endif %}
<!-- Printing options --> <!-- Printing options -->
{% if report_enabled %} {% if report_enabled %}
<div class='btn-group'> <div class='btn-group'>
@ -90,6 +108,7 @@ src="{% static 'img/blank_image.png' %}"
<td>{% trans "Build Description" %}</td> <td>{% trans "Build Description" %}</td>
<td>{{ build.title }}</td> <td>{{ build.title }}</td>
</tr> </tr>
{% include "barcode_data.html" with instance=build %}
</table> </table>
<div class='info-messages'> <div class='info-messages'>
@ -264,4 +283,33 @@ src="{% static 'img/blank_image.png' %}"
); );
}); });
{% if barcodes %}
<!-- Barcode functionality callbacks -->
$('#show-qr-code').click(function() {
showQRDialog(
'{% trans "Build Order QR Code" %}',
'{"build": {{ build.pk }}}'
);
});
{% if roles.purchase_order.change %}
$("#barcode-link").click(function() {
linkBarcodeDialog(
{
build: {{ build.pk }},
},
{
title: '{% trans "Link Barcode to Build Order" %}',
}
);
});
$("#barcode-unlink").click(function() {
unlinkBarcode({
build: {{ build.pk }},
});
});
{% endif %}
{% endif %}
{% endblock %} {% endblock %}

View File

@ -11,6 +11,7 @@ import json
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
import build.models
import company.models import company.models
import order.models import order.models
import part.models import part.models
@ -34,6 +35,7 @@ class InvenTreeInternalBarcodePlugin(BarcodeMixin, InvenTreePlugin):
"""Returns a list of database models which support barcode functionality""" """Returns a list of database models which support barcode functionality"""
return [ return [
build.models.Build,
company.models.SupplierPart, company.models.SupplierPart,
order.models.PurchaseOrder, order.models.PurchaseOrder,
order.models.ReturnOrder, order.models.ReturnOrder,