diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index f29cc1de2c..536aced1a2 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -154,6 +154,13 @@ class BuildAllocationItemSerializer(serializers.Serializer): required=True ) + def validate_quantity(self, quantity): + + if quantity <= 0: + raise ValidationError(_("Quantity must be greater than zero")) + + return quantity + output = serializers.PrimaryKeyRelatedField( queryset=StockItem.objects.filter(is_building=True), many=False, diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index 5715af9f3f..14523e445a 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -378,52 +378,18 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { // Primary key of the 'sub_part' var pk = $(this).attr('pk'); - // Launch form to allocate new stock against this output - launchModalForm('{% url "build-item-create" %}', { - success: reloadTable, - data: { - part: pk, - build: buildId, - install_into: outputId, - }, - secondary: [ - { - field: 'stock_item', - label: '{% trans "New Stock Item" %}', - title: '{% trans "Create new Stock Item" %}', - url: '{% url "stock-item-create" %}', - data: { - part: pk, - }, + allocateStockToBuild( + buildId, + partId, + { + success: function(data) { + console.log("here we go I guess"); }, - ], - callback: [ - { - field: 'stock_item', - action: function(value) { - inventreeGet( - `/api/stock/${value}/`, {}, - { - success: function(response) { - - // How many items are actually available for the given stock item? - var available = response.quantity - response.allocated; - - var field = getFieldByName('#modal-form', 'quantity'); - - // Allocation quantity initial value - var initial = field.attr('value'); - - if (available < initial) { - field.val(available); - } - } - } - ); - } - } - ] - }); + parts: [ + parseInt(pk), + ] + } + ); }); // Callback for 'buy' button @@ -831,18 +797,18 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { * - outputId: ID / PK of the associated build output (or null for untracked items) * - parts: List of ID values for filtering against specific sub parts */ -function allocateStockToBuild(buildId, partId, options={}) { +function allocateStockToBuild(build_id, part_id, options={}) { // ID of the associated "build output" (or null) - var outputId = options.output || null; + var output_id = options.output || null; // Extract list of BOM items (or empty list) - var subPartIds = options.parts || []; + var sub_part_ids = options.parts || []; - var bomItemQueryParams = { - part: partId, + var query_params = { + part: part_id, sub_part_detail: true, - sub_part_trackable: outputId != null + sub_part_trackable: output_id != null }; function renderBomItemRow(bom_item, quantity) { @@ -856,29 +822,50 @@ function allocateStockToBuild(buildId, partId, options={}) { delete_button += makeIconButton( 'fa-times icon-red', - 'button-part-remove', + 'button-row-remove', pk, '{% trans "Remove row" %}', ); delete_button += ``; - var quantity_input = constructNumberInput(pk, { - value: quantity || 0, - min_value: 0, - title: '{% trans "Specify stock allocation quantity" %}', - }); + var quantity_input = constructField( + `items_quantity_${pk}`, + { + type: 'decimal', + min_value: 0, + value: quantity || 0, + title: '{% trans "Specify stock allocation quantity" %}', + required: true, + }, + { + hideLabels: true, + } + ); - var stock_input = constructRelatedFieldInput(`stock_query_${pk}`); + var stock_input = constructField( + `items_stock_item_${pk}`, + { + type: 'related field', + required: 'true', + }, + { + hideLabels: true, + } + ); + + // var stock_input = constructRelatedFieldInput(`items_stock_item_${pk}`); var html = ` -
{% trans "Part" %} | {% trans "Stock Item" %} | +{% trans "Allocated" %} | {% trans "Quantity" %} |
---|