diff --git a/InvenTree/InvenTree/api_version.py b/InvenTree/InvenTree/api_version.py index 3c703f149f..1808182cbb 100644 --- a/InvenTree/InvenTree/api_version.py +++ b/InvenTree/InvenTree/api_version.py @@ -2,11 +2,14 @@ # InvenTree API version -INVENTREE_API_VERSION = 112 +INVENTREE_API_VERSION = 113 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about +v113 -> 2023-05-13 : https://github.com/inventree/InvenTree/pull/4800 + - Adds API endpoints for scrapping a build output + v112 -> 2023-05-13: https://github.com/inventree/InvenTree/pull/4741 - Adds flag use_pack_size to the stock addition API, which allows addings packs @@ -16,6 +19,7 @@ v111 -> 2023-05-02 : https://github.com/inventree/InvenTree/pull/4367 - Adds tags to the ManufacturerPart serializer - Adds tags to the StockItem serializer - Adds tags to the StockLocation serializer + v110 -> 2023-04-26 : https://github.com/inventree/InvenTree/pull/4698 - Adds 'order_currency' field for PurchaseOrder / SalesOrder endpoints diff --git a/InvenTree/InvenTree/status_codes.py b/InvenTree/InvenTree/status_codes.py index d2c6afeee1..124100a5dc 100644 --- a/InvenTree/InvenTree/status_codes.py +++ b/InvenTree/InvenTree/status_codes.py @@ -227,13 +227,12 @@ class StockStatus(StatusCode): LOST: _("Lost"), REJECTED: _("Rejected"), QUARANTINED: _("Quarantined"), - RETURNED: _("Returned"), } colors = { OK: 'success', ATTENTION: 'warning', - DAMAGED: 'danger', + DAMAGED: 'warning', DESTROYED: 'danger', LOST: 'dark', REJECTED: 'danger', @@ -289,6 +288,7 @@ class StockHistoryCode(StatusCode): # Build order codes BUILD_OUTPUT_CREATED = 50 BUILD_OUTPUT_COMPLETED = 55 + BUILD_OUTPUT_REJECTED = 56 BUILD_CONSUMED = 57 # Sales order codes @@ -337,6 +337,7 @@ class StockHistoryCode(StatusCode): BUILD_OUTPUT_CREATED: _('Build order output created'), BUILD_OUTPUT_COMPLETED: _('Build order output completed'), + BUILD_OUTPUT_REJECTED: _('Build order output rejected'), BUILD_CONSUMED: _('Consumed by build order'), SHIPPED_AGAINST_SALES_ORDER: _("Shipped against Sales Order"), diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index a76b51fd15..b4d5853b41 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -276,6 +276,19 @@ class BuildOutputCreate(BuildOrderContextMixin, CreateAPI): serializer_class = build.serializers.BuildOutputCreateSerializer +class BuildOutputScrap(BuildOrderContextMixin, CreateAPI): + """API endpoint for scrapping build output(s).""" + + queryset = Build.objects.none() + serializer_class = build.serializers.BuildOutputScrapSerializer + + def get_serializer_context(self): + """Add extra context information to the endpoint serializer.""" + ctx = super().get_serializer_context() + ctx['to_complete'] = False + return ctx + + class BuildOutputComplete(BuildOrderContextMixin, CreateAPI): """API endpoint for completing build outputs.""" @@ -489,6 +502,7 @@ build_api_urls = [ re_path(r'^complete/', BuildOutputComplete.as_view(), name='api-build-output-complete'), re_path(r'^create-output/', BuildOutputCreate.as_view(), name='api-build-output-create'), re_path(r'^delete-outputs/', BuildOutputDelete.as_view(), name='api-build-output-delete'), + re_path(r'^scrap-outputs/', BuildOutputScrap.as_view(), name='api-build-output-scrap'), re_path(r'^finish/', BuildFinish.as_view(), name='api-build-finish'), re_path(r'^cancel/', BuildCancel.as_view(), name='api-build-cancel'), re_path(r'^unallocate/', BuildUnallocate.as_view(), name='api-build-unallocate'), diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index dcb31aa0e6..9942f455d7 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -620,6 +620,7 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. location: Override location auto_allocate: Automatically allocate stock with matching serial numbers """ + user = kwargs.get('user', None) batch = kwargs.get('batch', self.batch) location = kwargs.get('location', self.destination) serials = kwargs.get('serials', None) @@ -630,6 +631,24 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. or multiple outputs (with quantity = 1) """ + def _add_tracking_entry(output, user): + """Helper function to add a tracking entry to the newly created output""" + deltas = { + 'quantity': float(output.quantity), + 'buildorder': self.pk, + } + + if output.batch: + deltas['batch'] = output.batch + + if output.serial: + deltas['serial'] = output.serial + + if output.location: + deltas['location'] = output.location.pk + + output.add_tracking_entry(StockHistoryCode.BUILD_OUTPUT_CREATED, user, deltas) + multiple = False # Serial numbers are provided? We need to split! @@ -663,6 +682,8 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. is_building=True, ) + _add_tracking_entry(output, user) + if auto_allocate and serial is not None: # Get a list of BomItem objects which point to "trackable" parts @@ -695,7 +716,7 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. else: """Create a single build output of the given quantity.""" - stock.models.StockItem.objects.create( + output = stock.models.StockItem.objects.create( quantity=quantity, location=location, part=self.part, @@ -704,6 +725,8 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. is_building=True ) + _add_tracking_entry(output, user) + if self.status == BuildStatus.PENDING: self.status = BuildStatus.PRODUCTION self.save() @@ -773,6 +796,50 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. # Delete allocation items.all().delete() + @transaction.atomic + def scrap_build_output(self, output, location, **kwargs): + """Mark a particular build output as scrapped / rejected + + - Mark the output as "complete" + - *Do Not* update the "completed" count for this order + - Set the item status to "scrapped" + - Add a transaction entry to the stock item history + """ + + if not output: + raise ValidationError(_("No build output specified")) + + user = kwargs.get('user', None) + notes = kwargs.get('notes', '') + discard_allocations = kwargs.get('discard_allocations', False) + + # Update build output item + output.is_building = False + output.status = StockStatus.REJECTED + output.location = location + output.save(add_note=False) + + allocated_items = output.items_to_install.all() + + # Complete or discard allocations + for build_item in allocated_items: + if not discard_allocations: + build_item.complete_allocation(user) + + # Delete allocations + allocated_items.delete() + + output.add_tracking_entry( + StockHistoryCode.BUILD_OUTPUT_REJECTED, + user, + notes=notes, + deltas={ + 'location': location.pk, + 'status': StockStatus.REJECTED, + 'buildorder': self.pk, + } + ) + @transaction.atomic def complete_build_output(self, output, user, **kwargs): """Complete a particular build output. @@ -801,15 +868,21 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. output.location = location output.status = status - output.save() + output.save(add_note=False) + + deltas = { + 'status': status, + 'buildorder': self.pk + } + + if location: + deltas['location'] = location.pk output.add_tracking_entry( StockHistoryCode.BUILD_OUTPUT_COMPLETED, user, notes=notes, - deltas={ - 'status': status, - } + deltas=deltas ) # Increase the completed quantity for this build diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index 4773d7e75e..bba5f75757 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -302,12 +302,14 @@ class BuildOutputCreateSerializer(serializers.Serializer): auto_allocate = data.get('auto_allocate', False) build = self.get_build() + user = self.context['request'].user build.create_build_output( quantity, serials=self.serials, batch=batch_code, auto_allocate=auto_allocate, + user=user, ) @@ -349,6 +351,76 @@ class BuildOutputDeleteSerializer(serializers.Serializer): build.delete_output(output) +class BuildOutputScrapSerializer(serializers.Serializer): + """DRF serializer for scrapping one or more build outputs""" + + class Meta: + """Serializer metaclass""" + fields = [ + 'outputs', + 'location', + 'notes', + ] + + outputs = BuildOutputSerializer( + many=True, + required=True, + ) + + location = serializers.PrimaryKeyRelatedField( + queryset=StockLocation.objects.all(), + many=False, + allow_null=False, + required=True, + label=_('Location'), + help_text=_('Stock location for scrapped outputs'), + ) + + discard_allocations = serializers.BooleanField( + required=False, + default=False, + label=_('Discard Allocations'), + help_text=_('Discard any stock allocations for scrapped outputs'), + ) + + notes = serializers.CharField( + label=_('Notes'), + help_text=_('Reason for scrapping build output(s)'), + required=True, + allow_blank=False, + ) + + def validate(self, data): + """Perform validation on the serializer data""" + super().validate(data) + outputs = data.get('outputs', []) + + if len(outputs) == 0: + raise ValidationError(_("A list of build outputs must be provided")) + + return data + + def save(self): + """Save the serializer to scrap the build outputs""" + + build = self.context['build'] + request = self.context['request'] + data = self.validated_data + outputs = data.get('outputs', []) + + # Scrap the build outputs + with transaction.atomic(): + for item in outputs: + output = item['output'] + build.scrap_build_output( + output, + data.get('location', None), + user=request.user, + notes=data.get('notes', ''), + discard_allocations=data.get('discard_allocations', False) + ) + + class BuildOutputCompleteSerializer(serializers.Serializer): """DRF serializer for completing one or more build outputs.""" diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 2e727b4014..029464fd17 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -261,6 +261,11 @@ {% trans "Complete outputs" %} {% endif %} + {% if roles.build.change %} +
  • + {% trans "Scrap outputs" %} +
  • + {% endif %} {% if roles.build.delete %}
  • {% trans "Delete outputs" %} diff --git a/InvenTree/build/test_api.py b/InvenTree/build/test_api.py index d27102e53d..fefafcf60d 100644 --- a/InvenTree/build/test_api.py +++ b/InvenTree/build/test_api.py @@ -10,7 +10,7 @@ from part.models import Part from build.models import Build, BuildItem from stock.models import StockItem -from InvenTree.status_codes import BuildStatus +from InvenTree.status_codes import BuildStatus, StockStatus from InvenTree.api_tester import InvenTreeAPITestCase @@ -924,3 +924,127 @@ class BuildListTest(BuildAPITest): builds = response.data self.assertEqual(len(builds), 20) + + +class BuildOutputScrapTest(BuildAPITest): + """Unit tests for scrapping build outputs""" + + def scrap(self, build_id, data, expected_code=None): + """Helper method to POST to the scrap API""" + + url = reverse('api-build-output-scrap', kwargs={'pk': build_id}) + + response = self.post(url, data, expected_code=expected_code) + + return response.data + + def test_invalid_scraps(self): + """Test that invalid scrap attempts are rejected""" + + # Test with missing required fields + response = self.scrap(1, {}, expected_code=400) + + for field in ['outputs', 'location', 'notes']: + self.assertIn('This field is required', str(response[field])) + + # Scrap with no outputs specified + response = self.scrap( + 1, + { + 'outputs': [], + 'location': 1, + 'notes': 'Should fail', + } + ) + + self.assertIn('A list of build outputs must be provided', str(response)) + + # Scrap with an invalid output ID + response = self.scrap( + 1, + { + 'outputs': [ + { + 'output': 9999, + } + ], + 'location': 1, + 'notes': 'Should fail', + }, + expected_code=400 + ) + + self.assertIn('object does not exist', str(response['outputs'])) + + # Create a build output, for a different build + build = Build.objects.get(pk=2) + output = StockItem.objects.create( + part=build.part, + quantity=10, + batch='BATCH-TEST', + is_building=True, + build=build, + ) + + response = self.scrap( + 1, + { + 'outputs': [ + { + 'output': output.pk, + }, + ], + 'location': 1, + 'notes': 'Should fail', + }, + expected_code=400 + ) + + self.assertIn("Build output does not match the parent build", str(response['outputs'])) + + def test_valid_scraps(self): + """Test that valid scrap attempts succeed""" + + # Create a build output + build = Build.objects.get(pk=1) + + for _ in range(3): + build.create_build_output(2) + + outputs = build.build_outputs.all() + + self.assertEqual(outputs.count(), 3) + self.assertEqual(StockItem.objects.filter(build=build).count(), 3) + + for output in outputs: + self.assertEqual(output.status, StockStatus.OK) + self.assertTrue(output.is_building) + + # Scrap all three outputs + self.scrap( + 1, + { + 'outputs': [ + { + 'output': outputs[0].pk, + }, + { + 'output': outputs[1].pk, + }, + { + 'output': outputs[2].pk, + }, + ], + 'location': 1, + 'notes': 'Should succeed', + }, + expected_code=201 + ) + + # There should still be three outputs associated with this build + self.assertEqual(StockItem.objects.filter(build=build).count(), 3) + + for output in outputs: + output.refresh_from_db() + self.assertEqual(output.status, StockStatus.REJECTED) + self.assertFalse(output.is_building) diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 3079993825..70ea74a189 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -164,7 +164,7 @@ class PluginsRegistry: if not _maintenance: set_maintenance_mode(False) - logger.info('Finished loading plugins') + logger.debug('Finished loading plugins') def unload_plugins(self, force_reload: bool = False): """Unload and deactivate all IntegrationPlugins. @@ -335,7 +335,7 @@ class PluginsRegistry: return True try: - output = str(subprocess.check_output(['pip', 'install', '-U', '-r', settings.PLUGIN_FILE], cwd=settings.BASE_DIR.parent), 'utf-8') + subprocess.check_output(['pip', 'install', '-U', '-r', settings.PLUGIN_FILE], cwd=settings.BASE_DIR.parent) except subprocess.CalledProcessError as error: # pragma: no cover logger.error(f'Ran into error while trying to install plugins!\n{str(error)}') return False @@ -343,8 +343,6 @@ class PluginsRegistry: # System most likely does not have 'git' installed return False - logger.info(f'plugin requirements were run\n{output}') - # do not run again settings.PLUGIN_FILE_CHECKED = True return 'first_run' @@ -503,7 +501,7 @@ class PluginsRegistry: if hasattr(mixin, '_activate_mixin'): mixin._activate_mixin(self, plugins, force_reload=force_reload, full_reload=full_reload) - logger.info('Done activating') + logger.debug('Done activating') def _deactivate_plugins(self, force_reload: bool = False): """Run deactivation functions for all plugins. diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 3890c9bfc4..3fb3585fb7 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -19,6 +19,7 @@ import common.models import common.settings import stock.serializers as StockSerializers from build.models import Build +from build.serializers import BuildSerializer from company.models import Company, SupplierPart from company.serializers import CompanySerializer, SupplierPartSerializer from InvenTree.api import (APIDownloadMixin, AttachmentMixin, @@ -1308,6 +1309,15 @@ class StockTrackingList(ListAPI): except Exception: pass + # Add BuildOrder detail + if 'buildorder' in deltas: + try: + order = Build.objects.get(pk=deltas['buildorder']) + serializer = BuildSerializer(order) + deltas['buildorder_detail'] = serializer.data + except Exception: + pass + if page is not None: return self.get_paginated_response(data) if request.is_ajax(): diff --git a/InvenTree/stock/migrations/0099_alter_stockitem_status.py b/InvenTree/stock/migrations/0099_alter_stockitem_status.py new file mode 100644 index 0000000000..4765e52fe7 --- /dev/null +++ b/InvenTree/stock/migrations/0099_alter_stockitem_status.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.18 on 2023-05-13 05:15 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0098_auto_20230427_2033'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='status', + field=models.PositiveIntegerField(choices=[(10, 'OK'), (50, 'Attention needed'), (55, 'Damaged'), (60, 'Destroyed'), (70, 'Lost'), (65, 'Rejected'), (75, 'Quarantined')], default=10, validators=[django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index cdf3b10f4c..c1b6b83cd3 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -397,9 +397,17 @@ function makeBuildOutputButtons(output_id, build_info, options={}) { '{% trans "Complete build output" %}', ); - // Add a button to "delete" this build output + // Add a button to "scrap" the build output + html += makeIconButton( + 'fa-times-circle icon-red', + 'button-output-scrap', + output_id, + '{% trans "Scrap build output" %}', + ); + + // Add a button to "remove" this build output html += makeDeleteButton( - 'button-output-delete', + 'button-output-remove', output_id, '{% trans "Delete build output" %}', ); @@ -452,6 +460,51 @@ function unallocateStock(build_id, options={}) { } +/* + * Helper function to render a single build output in a modal form + */ +function renderBuildOutput(output, opts={}) { + let pk = output.pk; + + let output_html = imageHoverIcon(output.part_detail.thumbnail); + + if (output.quantity == 1 && output.serial) { + output_html += `{% trans "Serial Number" %}: ${output.serial}`; + } else { + output_html += `{% trans "Quantity" %}: ${output.quantity}`; + if (output.part_detail && output.part_detail.units) { + output_html += ` ${output.part_detail.units} `; + } + } + + let buttons = `
    `; + + buttons += makeRemoveButton('button-row-remove', pk, '{% trans "Remove row" %}'); + + buttons += '
    '; + + let field = constructField( + `outputs_output_${pk}`, + { + type: 'raw', + html: output_html, + }, + { + hideLabels: true, + } + ); + + let html = ` + + ${field} + ${output.part_detail.full_name} + ${buttons} + `; + + return html; +} + + /** * Launch a modal form to complete selected build outputs */ @@ -465,48 +518,6 @@ function completeBuildOutputs(build_id, outputs, options={}) { return; } - // Render a single build output (StockItem) - function renderBuildOutput(output, opts={}) { - var pk = output.pk; - - var output_html = imageHoverIcon(output.part_detail.thumbnail); - - if (output.quantity == 1 && output.serial) { - output_html += `{% trans "Serial Number" %}: ${output.serial}`; - } else { - output_html += `{% trans "Quantity" %}: ${output.quantity}`; - if (output.part_detail && output.part_detail.units) { - output_html += ` ${output.part_detail.units} `; - } - } - - var buttons = `
    `; - - buttons += makeRemoveButton('button-row-remove', pk, '{% trans "Remove row" %}'); - - buttons += '
    '; - - var field = constructField( - `outputs_output_${pk}`, - { - type: 'raw', - html: output_html, - }, - { - hideLabels: true, - } - ); - - var html = ` - - ${field} - ${output.part_detail.full_name} - ${buttons} - `; - - return html; - } - // Construct table entries var table_entries = ''; @@ -515,6 +526,9 @@ function completeBuildOutputs(build_id, outputs, options={}) { }); var html = ` +
    + {% trans "Selected build outputs will be marked as complete" %} +
    @@ -613,8 +627,122 @@ function completeBuildOutputs(build_id, outputs, options={}) { +/* + * Launch a modal form to scrap selected build outputs. + * Scrapped outputs are marked as "complete", but with the "rejected" code + * These outputs are not included in build completion calculations. + */ +function scrapBuildOutputs(build_id, outputs, options={}) { + + if (outputs.length == 0) { + showAlertDialog( + '{% trans "Select Build Outputs" %}', + '{% trans "At least one build output must be selected" %}', + ); + return; + } + + let table_entries = ''; + + outputs.forEach(function(output) { + table_entries += renderBuildOutput(output); + }); + + var html = ` +
    + {% trans "Selected build outputs will be marked as scrapped" %} +
      +
    • {% trans "Scrapped output are given the 'rejected' status" %}
    • +
    • {% trans "Allocated stock items will no longer be available" %}
    • +
    • {% trans "The completion status of the build order will not be adjusted" %}
    • +
    +
    +
    {% trans "Output" %}
    + + + + + + ${table_entries} + +
    {% trans "Output" %}
    `; + + constructForm(`{% url "api-build-list" %}${build_id}/scrap-outputs/`, { + method: 'POST', + preFormContent: html, + fields: { + location: {}, + notes: {}, + discard_allocations: {}, + }, + confirm: true, + title: '{% trans "Scrap Build Outputs" %}', + afterRender: function(fields, opts) { + // Setup callbacks to remove outputs + $(opts.modal).find('.button-row-remove').click(function() { + let pk = $(this).attr('pk'); + $(opts.modal).find(`#output_row_${pk}`).remove(); + }); + }, + onSubmit: function(fields, opts) { + let data = { + outputs: [], + location: getFormFieldValue('location', {}, opts), + notes: getFormFieldValue('notes', {}, opts), + discard_allocations: getFormFieldValue('discard_allocations', {type: 'boolean'}, opts), + }; + + let output_pk_values = []; + + outputs.forEach(function(output) { + let pk = output.pk; + let row = $(opts.modal).find(`#output_row_${pk}`); + + if (row.exists()) { + data.outputs.push({ + output: pk, + }); + output_pk_values.push(pk); + } + }); + + opts.nested = { + 'outputs': output_pk_values, + }; + + inventreePut( + opts.url, + data, + { + method: 'POST', + success: function(response) { + $(opts.modal).modal('hide'); + + if (options.success) { + options.success(response); + } + }, + error: function(xhr) { + switch (xhr.status) { + case 400: + handleFormErrors(xhr.responseJSON, fields, opts); + break; + default: + $(opts.modal).modal('hide'); + showApiError(xhr, opts.url); + break; + } + } + } + ); + } + }); +} + + /** - * Launch a modal form to delete selected build outputs + * Launch a modal form to delete selected build outputs. + * Deleted outputs are expunged from the database. */ function deleteBuildOutputs(build_id, outputs, options={}) { @@ -626,48 +754,6 @@ function deleteBuildOutputs(build_id, outputs, options={}) { return; } - // Render a single build output (StockItem) - function renderBuildOutput(output, opts={}) { - var pk = output.pk; - - var output_html = imageHoverIcon(output.part_detail.thumbnail); - - if (output.quantity == 1 && output.serial) { - output_html += `{% trans "Serial Number" %}: ${output.serial}`; - } else { - output_html += `{% trans "Quantity" %}: ${output.quantity}`; - if (output.part_detail && output.part_detail.units) { - output_html += ` ${output.part_detail.units} `; - } - } - - var buttons = `
    `; - - buttons += makeRemoveButton('button-row-remove', pk, '{% trans "Remove row" %}'); - - buttons += '
    '; - - var field = constructField( - `outputs_output_${pk}`, - { - type: 'raw', - html: output_html, - }, - { - hideLabels: true, - } - ); - - var html = ` - - ${field} - ${output.part_detail.full_name} - ${buttons} - `; - - return html; - } - // Construct table entries var table_entries = ''; @@ -676,6 +762,13 @@ function deleteBuildOutputs(build_id, outputs, options={}) { }); var html = ` +
    + {% trans "Selected build outputs will be deleted" %} +
      +
    • {% trans "Build output data will be permanently deleted" %}
    • +
    • {% trans "Allocated stock items will be returned to stock" %}
    • +
    +
    @@ -952,8 +1045,25 @@ function loadBuildOutputTable(build_info, options={}) { ); }); - // Callback for the "delete" button - $(table).find('.button-output-delete').click(function() { + // Callback for the "scrap" button + $(table).find('.button-output-scrap').click(function() { + var pk = $(this).attr('pk'); + var output = $(table).bootstrapTable('getRowByUniqueId', pk); + + scrapBuildOutputs( + build_info.pk, + [output], + { + success: function() { + $(table).bootstrapTable('refresh'); + $('#build-stock-table').bootstrapTable('refresh'); + } + } + ); + }); + + // Callback for the "remove" button + $(table).find('.button-output-remove').click(function() { var pk = $(this).attr('pk'); var output = $(table).bootstrapTable('getRowByUniqueId', pk); @@ -1368,6 +1478,25 @@ function loadBuildOutputTable(build_info, options={}) { // Add callbacks for the various table menubar buttons + // Scrap multiple outputs + $('#multi-output-scrap').click(function() { + var outputs = getTableData(table); + + scrapBuildOutputs( + build_info.pk, + outputs, + { + success: function() { + // Reload the "in progress" table + $('#build-output-table').bootstrapTable('refresh'); + + // Reload the "completed" table + $('#build-stock-table').bootstrapTable('refresh'); + } + } + ); + }); + // Complete multiple outputs $('#multi-output-complete').click(function() { var outputs = getTableData(table); diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 23a22c27e4..0aebdfa0ae 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -3,8 +3,6 @@ {% load status_codes %} /* globals - attachSelect, - closeModal, constructField, constructFormBody, getFormFieldValue, @@ -18,12 +16,6 @@ loadTableFilters, makeIconBadge, makeIconButton, - makeOptionsList, - modalEnable, - modalSetContent, - modalSetTitle, - modalSubmit, - openModal, renderLink, scanItemsIntoLocation, showAlertDialog, @@ -54,7 +46,6 @@ serializeStockItem, stockItemFields, stockLocationFields, - stockStatusCodes, uninstallStockItem, */ @@ -603,22 +594,6 @@ function findStockItemBySerialNumber(part_id) { } -/* Stock API functions - * Requires api.js to be loaded first - */ - -function stockStatusCodes() { - return [ - {% for code in StockStatus.list %} - { - key: {{ code.key }}, - text: '{{ code.value }}', - }, - {% endfor %} - ]; -} - - /** * Assign multiple stock items to a customer */ @@ -2261,93 +2236,6 @@ function loadStockTable(table, options) { orderParts(parts, {}); }); - $('#multi-item-set-status').click(function() { - // Select and set the STATUS field for selected stock items - var selections = getTableData(table); - - // Select stock status - var modal = '#modal-form'; - - var status_list = makeOptionsList( - stockStatusCodes(), - function(item) { - return item.text; - }, - function(item) { - return item.key; - } - ); - - // Add an empty option at the start of the list - status_list.unshift(''); - - // Construct form - var html = ` - -
    - -
    - -
    -
    - `; - - openModal({ - modal: modal, - }); - - modalEnable(modal, true); - modalSetTitle(modal, '{% trans "Set Stock Status" %}'); - modalSetContent(modal, html); - - attachSelect(modal); - - modalSubmit(modal, function() { - var label = $(modal).find('#id_status'); - - var status_code = label.val(); - - closeModal(modal); - - if (!status_code) { - showAlertDialog( - '{% trans "Select Status Code" %}', - '{% trans "Status code must be selected" %}' - ); - - return; - } - - var requests = []; - - selections.forEach(function(item) { - var url = `/api/stock/${item.pk}/`; - - requests.push( - inventreePut( - url, - { - status: status_code, - }, - { - method: 'PATCH', - success: function() { - } - } - ) - ); - }); - - $.when.apply($, requests).done(function() { - $(table).bootstrapTable('refresh'); - }); - }); - }); - $('#multi-item-delete').click(function() { var selections = getTableData(table); @@ -2697,11 +2585,24 @@ function loadStockTrackingTable(table, options) { html += ''; } + // BuildOrder Information + if (details.buildorder) { + html += ``; + html += ``; - html += '
    {% trans "Output" %}
    {% trans "Build Order" %}`; + + if (details.buildorder_detail) { + html += renderLink( + details.buildorder_detail.reference, + `/build/${details.buildorder}/` + ); + } else { + html += `{% trans "Build order no longer exists" %}`; + } + } + // PurchaseOrder Information if (details.purchaseorder) { - html += `
    {% trans "Purchase Order" %}'; if (details.purchaseorder_detail) { diff --git a/InvenTree/templates/js/translated/table_filters.js b/InvenTree/templates/js/translated/table_filters.js index 9ca1bf83c0..c501baa091 100644 --- a/InvenTree/templates/js/translated/table_filters.js +++ b/InvenTree/templates/js/translated/table_filters.js @@ -405,6 +405,12 @@ function getStockTestTableFilters() { } +// Return a dictionary of filters for the "stocktracking" table +function getStockTrackingTableFilters() { + return {}; +} + + // Return a dictionary of filters for the "part tests" table function getPartTestTemplateFilters() { return { @@ -741,6 +747,8 @@ function getAvailableTableFilters(tableKey) { return getStockTableFilters(); case 'stocktests': return getStockTestTableFilters(); + case 'stocktracking': + return getStockTrackingTableFilters(); case 'supplierpart': return getSupplierPartFilters(); case 'usedin': diff --git a/InvenTree/templates/stock_table.html b/InvenTree/templates/stock_table.html index 6484f74f0c..26a7a5abea 100644 --- a/InvenTree/templates/stock_table.html +++ b/InvenTree/templates/stock_table.html @@ -37,7 +37,6 @@
  • {% trans "Merge stock" %}
  • {% trans "Order stock" %}
  • {% trans "Assign to customer" %}
  • -
  • {% trans "Change stock status" %}
  • {% endif %} {% if roles.stock.delete %}
  • {% trans "Delete stock" %}
  • diff --git a/docs/docs/assets/images/build/build_example_allocate_untracked.png b/docs/docs/assets/images/build/build_example_allocate_untracked.png new file mode 100644 index 0000000000..95cd85fa77 Binary files /dev/null and b/docs/docs/assets/images/build/build_example_allocate_untracked.png differ diff --git a/docs/docs/assets/images/build/build_example_allocated_tracked.png b/docs/docs/assets/images/build/build_example_allocated_tracked.png new file mode 100644 index 0000000000..9f2b2dae7e Binary files /dev/null and b/docs/docs/assets/images/build/build_example_allocated_tracked.png differ diff --git a/docs/docs/assets/images/build/build_example_complete_outputs.png b/docs/docs/assets/images/build/build_example_complete_outputs.png new file mode 100644 index 0000000000..7a3382af9a Binary files /dev/null and b/docs/docs/assets/images/build/build_example_complete_outputs.png differ diff --git a/docs/docs/assets/images/build/build_example_create.png b/docs/docs/assets/images/build/build_example_create.png new file mode 100644 index 0000000000..e62d438543 Binary files /dev/null and b/docs/docs/assets/images/build/build_example_create.png differ diff --git a/docs/docs/assets/images/build/build_example_create_outputs.png b/docs/docs/assets/images/build/build_example_create_outputs.png new file mode 100644 index 0000000000..1606728039 Binary files /dev/null and b/docs/docs/assets/images/build/build_example_create_outputs.png differ diff --git a/docs/docs/assets/images/build/build_example_incomplete_list.png b/docs/docs/assets/images/build/build_example_incomplete_list.png new file mode 100644 index 0000000000..a6fbd37d5b Binary files /dev/null and b/docs/docs/assets/images/build/build_example_incomplete_list.png differ diff --git a/docs/docs/assets/images/build/build_output_complete.png b/docs/docs/assets/images/build/build_output_complete.png index c729493087..6583cbddf2 100644 Binary files a/docs/docs/assets/images/build/build_output_complete.png and b/docs/docs/assets/images/build/build_output_complete.png differ diff --git a/docs/docs/assets/images/build/build_output_create.png b/docs/docs/assets/images/build/build_output_create.png new file mode 100644 index 0000000000..5b29ceb26e Binary files /dev/null and b/docs/docs/assets/images/build/build_output_create.png differ diff --git a/docs/docs/assets/images/build/build_output_delete.png b/docs/docs/assets/images/build/build_output_delete.png new file mode 100644 index 0000000000..523ace3a2b Binary files /dev/null and b/docs/docs/assets/images/build/build_output_delete.png differ diff --git a/docs/docs/assets/images/build/build_output_scrap.png b/docs/docs/assets/images/build/build_output_scrap.png new file mode 100644 index 0000000000..91ab653f89 Binary files /dev/null and b/docs/docs/assets/images/build/build_output_scrap.png differ diff --git a/docs/docs/assets/images/build/build_outputs_complete.png b/docs/docs/assets/images/build/build_outputs_complete.png new file mode 100644 index 0000000000..a35866e948 Binary files /dev/null and b/docs/docs/assets/images/build/build_outputs_complete.png differ diff --git a/docs/docs/assets/images/build/build_outputs_incomplete.png b/docs/docs/assets/images/build/build_outputs_incomplete.png new file mode 100644 index 0000000000..746206ed9a Binary files /dev/null and b/docs/docs/assets/images/build/build_outputs_incomplete.png differ diff --git a/docs/docs/assets/images/stock/stock_status_change_multiple.png b/docs/docs/assets/images/stock/stock_status_change_multiple.png deleted file mode 100644 index 245761aac8..0000000000 Binary files a/docs/docs/assets/images/stock/stock_status_change_multiple.png and /dev/null differ diff --git a/docs/docs/assets/images/stock/stock_status_change_multiple_done.png b/docs/docs/assets/images/stock/stock_status_change_multiple_done.png deleted file mode 100644 index f2e928d874..0000000000 Binary files a/docs/docs/assets/images/stock/stock_status_change_multiple_done.png and /dev/null differ diff --git a/docs/docs/assets/images/stock/stock_status_edit.png b/docs/docs/assets/images/stock/stock_status_edit.png new file mode 100644 index 0000000000..0c4793437b Binary files /dev/null and b/docs/docs/assets/images/stock/stock_status_edit.png differ diff --git a/docs/docs/assets/images/stock/stock_status_edit_multiple.png b/docs/docs/assets/images/stock/stock_status_edit_multiple.png new file mode 100644 index 0000000000..d7d108c2e5 Binary files /dev/null and b/docs/docs/assets/images/stock/stock_status_edit_multiple.png differ diff --git a/docs/docs/assets/images/stock/stock_status_label.png b/docs/docs/assets/images/stock/stock_status_label.png index cc35420231..4102694972 100644 Binary files a/docs/docs/assets/images/stock/stock_status_label.png and b/docs/docs/assets/images/stock/stock_status_label.png differ diff --git a/docs/docs/assets/images/stock/stock_status_label_updated.png b/docs/docs/assets/images/stock/stock_status_label_updated.png deleted file mode 100644 index eb91a1bcdf..0000000000 Binary files a/docs/docs/assets/images/stock/stock_status_label_updated.png and /dev/null differ diff --git a/docs/docs/build/allocate.md b/docs/docs/build/allocate.md index 20597709cf..9f7eb874a4 100644 --- a/docs/docs/build/allocate.md +++ b/docs/docs/build/allocate.md @@ -131,16 +131,6 @@ Here we can see that the incomplete build outputs (serial numbers 15 and 14) now - Serial number 15 has been fully allocated, and can be completed - Serial number 14 has not been fully allocated, and cannot yet be completed -## Completing a Build Output - -An individual build output is completed by selecting the "Complete build output" button associated with that build output: - -{% with id="build_output_complete", url="build/build_output_complete.png", description="Complete build output" %} -{% include "img.html" %} -{% endwith %} - -Here the user can select the destination location for the build output, as well as the stock item status. - ### Allocated Stock *Tracked* stock items which are allocated against the selected build output will be removed from stock, and installed "inside" the output assembly. The allocated stock items will still exist in the InvenTree database, however will no longer be available for regular stock actions. @@ -151,7 +141,7 @@ Here the user can select the destination location for the build output, as well ## Completing a Build !!! warning "Complete Build Outputs" - A build order cannot be completed if there are outstanding build outputs. Ensure that all build outputs are completed first. + A build order cannot be completed if there are outstanding build outputs. Ensure that all [build outputs](./output.md) are completed first. Once all build outputs have been completed, the build order itself can be completed by selecting the *Complete Build* button: diff --git a/docs/docs/build/build.md b/docs/docs/build/build.md index a27526871f..1736023e10 100644 --- a/docs/docs/build/build.md +++ b/docs/docs/build/build.md @@ -66,8 +66,7 @@ The following parameters are available for each Build Order, and can be edited b A *Build Output* creates a new stock instance of the assembly part, of a specified quantity. Each *Build Order* requires at least one build output. Multiple build outputs can be specified if the build is completed in batches. -!!! info "Example - Build Outputs" - For example, let's say we wish to create 10 new "Widgets". We create a new build for the widget, which signals an *intent* to assemble the "Widget" in quantity 10. We can produce 5 widgets in a single day, and so we create 2 build outputs, each of quantity 5. +Read more about build outputs [here](./output.md). ### Build Status @@ -125,7 +124,7 @@ The allocation table (as shown above) shows the stock allocation progress for th ### Build Outputs -The *Build Outputs* tab shows the outputs (created stock items) associated with this build. +The *Build Outputs* tab shows the [build outputs](./output.md) (created stock items) associated with this build. As shown below, there are separate panels for *incomplete* and *completed* build outputs. diff --git a/docs/docs/build/example.md b/docs/docs/build/example.md new file mode 100644 index 0000000000..624f83fa95 --- /dev/null +++ b/docs/docs/build/example.md @@ -0,0 +1,57 @@ +--- +title: Build Order Example +--- + +## Build Order Example + +For example, let's say we wish to create 10 new "Widgets". We create a new build for the widget, which signals an *intent* to assemble the "Widget" in quantity 10. As the *Widget* is a serialized part, with tracked subcomponents, the build outputs must themselves be serialized. This means that we need to generate 10 separate build outputs for this build order. + +### Create Build Order + +First, create a new build order for the *Widget* assembly: + +{% with id="build_example_create", url="build/build_example_create.png", description="Create build order" %} +{% include "img.html" %} +{% endwith %} + +### Generate Build Outputs + +Generate build outputs for this build order. As this is a tracked item, with tracked subcomponents, the build outputs must be serialized: + +{% with id="build_example_create_outputs", url="build/build_example_create_outputs.png", description="Create build outputs" %} +{% include "img.html" %} +{% endwith %} + +A list of new build outputs will have now been generated: + +{% with id="build_example_incomplete_list", url="build/build_example_incomplete_list.png", description="Incomplete build outputs" %} +{% include "img.html" %} +{% endwith %} + +### Allocate Untracked Stock + +Untracked stock items are allocated to the build order in the *Allocate Stock* tab: + +{% with id="build_example_allocate_untracked", url="build/build_example_allocate_untracked.png", description="Allocated Untracked Stock" %} +{% include "img.html" %} +{% endwith %} + +### Allocate Tracked Stock + +Tracked stock items are allocated to individual build outputs: + +{% with id="build_example_allocate_tracked", url="build/build_example_allocated_tracked.png", description="Allocated Tracked Stock" %} +{% include "img.html" %} +{% endwith %} + +### Complete Build Outputs + +Mark each build output as complete: + +{% with id="build_example_complete_outputs", url="build/build_example_complete_outputs.png", description="Complete Build Outputs" %} +{% include "img.html" %} +{% endwith %} + +### Complete Build Order + +Once the build outputs have been completed, and all stock has been allocated, the build order can be completed. diff --git a/docs/docs/build/output.md b/docs/docs/build/output.md new file mode 100644 index 0000000000..ebccedc338 --- /dev/null +++ b/docs/docs/build/output.md @@ -0,0 +1,119 @@ +--- +title: Build Outputs +--- + +## Build Outputs + +With reference to a [build order](./build.md), a *Build Output* is a finished product which is expected to be produced by completing the order. + +- A single build order may have multiple build outputs which are produced at different times or by different operators. +- An individual build output may be a single unit, or a batch of units +- Serial numbers and batch codes can be associated with a build output + +### Incomplete Outputs + +The *Incomplete Outputs* tab displays any outstanding / in-progress build outputs for the current build order. + +{% with id="build-outputs-incomplete", url="build/build_outputs_incomplete.png", description="Incomplete build outputs" %} +{% include "img.html" %} +{% endwith %} + +### Completed Outputs + +The *Completed Outputs* tab displays any [completed](#complete-build-output) or [scrapped](#scrap-build-output) outputs for the current build order. + +{% with id="build-outputs-complete", url="build/build_outputs_complete.png", description="Complete build outputs" %} +{% include "img.html" %} +{% endwith %} + +## Create Build Output + +Create a new build output by pressing the New Build Output button under the [incomplete outputs](#incomplete-outputs) tab: + +{% with id="build_output_create", url="build/build_output_create.png", description="Create build output" %} +{% include "img.html" %} +{% endwith %} + +### Create Options + +The following options are available when creating a new build output: + +| Option | Description | +| --- | --- | +| Quantity | The number of items to create as part of this build output | +| Serial Numbers | If this is a tracked build output, the serial numbers for each of the generated outputs | +| Batch Code | Batch code identifier for the generated output(s) | +| Auto Allocate Serial Numbers | If selected, any available tracked subcomponents which already have serial numbers assigned, will be automatically assigned to matching build outputs | + +### Specifying Serial Numbers + +Refer to the [serial number generation guide](../stock/tracking.md#generating-serial-numbers) for further information on serial number input. + +## Complete Build Output + +*Completing* a build output marks that output as finished, in the context of the given build order. + +An individual build output is completed by selecting the "Complete build output" button associated with that build output: + +{% with id="build_output_complete", url="build/build_output_complete.png", description="Complete build output" %} +{% include "img.html" %} +{% endwith %} + +Here the user can select the destination location for the build output, as well as the stock item status. + +Marking the build output(s) as complete performs the following actions: + +- The completed build quantity is increased by the quantity of the selected build output(s) +- The build output(s) are marked as "completed", and available for stock actions +- Any [tracked BOM items](./allocate.md#allocating-tracked-stock) which are allocated to the build output are *installed* into that build output. + +### Complete Options + +The following options are available when completing a build output: + +| Option | Description | +| --- | --- | +| Status | The [stock status](../stock/status.md) for the completed outputs | +| Location | The [stock location](../stock/stock.md#stock-location) where the outputs will be located | +| Notes | Any additional notes associated with the completion of these outputs | +| Accept Incomplete Allocation | If selected, this option allows [tracked build outputs](./allocate.md#tracked-build-outputs) to be completed in the case where required BOM items have not been fully allocated | + +## Scrap Build Output + +*Scrapping* a build output marks the particular output as rejected, in the context of the given build order. + +An individual build output is completed by selecting the *Scrap build output* button associated with that build output: + +{% with id="build_output_scrap", url="build/build_output_scrap.png", description="Scrap build output" %} +{% include "img.html" %} +{% endwith %} + +Marking the build output(s) as scrapped performs the following actions: + +- The build outputs are marked as "rejected" and removed from the build +- The completed build quantity *does not increase* +- The build outputs are not available for any further stock actions +- Optionally, any [tracked BOM items](./allocate.md#allocating-tracked-stock) which are allocated to the build output are *installed* into the rejected build output + +### Scrap Options + +The following options are available when scrapping a build order: + +| Option | Description | +| --- | --- | +| Location | The stock location where the scrapped build output(s) will be located | +| Notes | Any additional notes associated with the scrapping of these outputs | +| Discard Allocations | If selected, any installed BOM items will be removed first, before marking the build output as scrapped. Use this option if the installed items are recoverable and can be used elsewhere | + +## Delete Build Output + +*Deleting* a build output causes the build output to be cancelled, and removed from the database entirely. Use this option when the build output does not physically exist (or was never built) and should not be tracked in the database. + +{% with id="build_output_delete", url="build/build_output_delete.png", description="Delete build output" %} +{% include "img.html" %} +{% endwith %} + +Marking the build output(s) as deleted performs the following actions: + +- Any allocated stock items are returned to stock +- The build output is removed from the database diff --git a/docs/docs/stock/status.md b/docs/docs/stock/status.md index e8dcf96611..42e5bffe32 100644 --- a/docs/docs/stock/status.md +++ b/docs/docs/stock/status.md @@ -4,39 +4,36 @@ title: Stock Status ## Stock Status -Stock status serves at categorizing and identifying the state of stock items. +Each [Stock Item](./stock.md#stock-item) has a *status* attribute, which serves to identify the current condition of the individual stock item. -Below is the current list of stock status and their proposed meaning: +Certain stock item status codes will restrict the availability of the stock item. -| Status | Description | -| ----------- | ----------- | -| OK | Stock item is healthy, nothing wrong to report | -| Attention needed | Stock item hasn't been checked or tested yet | -| Damaged | Stock item is not functional in its present state | -| Destroyed | Stock item has been destroyed | -| Lost | Stock item has been lost | -| Rejected | Stock item did not pass the quality control standards | -| Returned | Stock item was returned to seller (if bought) or is a customer return (if sold) | -| Quarantined | Stock item has been intentionally isolated and it unavailable | +Below is the list of available stock status codes and their meaning: -Stock status code will remove the stock from certain operations. For instance, users can't add "destroyed" or "lost" stock to a sales order. +| Status | Description | Available | +| ----------- | ----------- | --- | +| OK | Stock item is healthy, nothing wrong to report | Yes | +| Attention needed | Stock item hasn't been checked or tested yet | Yes | +| Damaged | Stock item is not functional in its present state | Yes | +| Destroyed | Stock item has been destroyed | No | +| Lost | Stock item has been lost | No | +| Rejected | Stock item did not pass the quality control standards | No | +| Quarantined | Stock item has been intentionally isolated and it unavailable | No | -The stock status is displayed as a label in the header of each stock item detail page, for instance here the stock status is "OK": +The *status* of a given stock item is displayed on the stock item detail page: {% with id="stock_status_label", url="stock/stock_status_label.png", description="Stock Status Label" %} {% include 'img.html' %} {% endwith %} +### Default Status Code + +The default status code for any newly created Stock Item is OK + ## Update Status -In the "Stock" tab of the part view, select all stock items which stock status needs to be updated: +To update the status code for an individual stock item, open the *Edit Stock Item* dialog and then select the required status code in the *Status* field -{% with id="stock_status_change_multiple", url="stock/stock_status_change_multiple.png", description="Stock Status Status Multiple" %} -{% include 'img.html' %} -{% endwith %} - -Click on `Stock Options > Change stock status`, select the new status then submit. All selected stock items status will be automatically updated: - -{% with id="stock_status_change_multiple_done", url="stock/stock_status_change_multiple_done.png", description="Stock Status Status Multiple Done" %} +{% with id="stock_status_edit", url="stock/stock_status_edit.png", description="Edit stock item status" %} {% include 'img.html' %} {% endwith %} diff --git a/docs/docs/stylesheets/extra.css b/docs/docs/stylesheets/extra.css index 5f2db992eb..3641b1f2cb 100644 --- a/docs/docs/stylesheets/extra.css +++ b/docs/docs/stylesheets/extra.css @@ -135,3 +135,22 @@ div:nth-of-type(1) p { margin: 5px; margin-bottom: 0px; } + +.badge.inventree.success { + background-color: #5cb85c; + color: #555; +} + +.badge.inventree.warning { + background-color: #f0ad4e; + color: #555; +} + +.badge.inventree.danger { + background-color: #d9534f; +} + +.badge.inventree.info { + background-color: #5bc0de; + color: #555; +} diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index f4c3690803..0a3199306f 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -99,7 +99,9 @@ nav: - Test Results: stock/test.md - Build: - Build Orders: build/build.md + - Build Outputs: build/output.md - Allocating Stock: build/allocate.md + - Example Build Order: build/example.md - Bill of Materials: build/bom.md - Importing BOM Data: build/bom_import.md - Exporting BOM Data: build/bom_export.md