From 6e6f9d6c2f3e4a2a43e4c9fe9856c464b4f89dcb Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Feb 2022 22:54:02 +1100 Subject: [PATCH] Reintroduce option to clear (delete) BOM before uploading new data --- InvenTree/part/serializers.py | 29 +++++++++++++++++++ InvenTree/part/templates/part/upload_bom.html | 5 ++++ 2 files changed, 34 insertions(+) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index cc489cf5c9..549b546a5b 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -716,6 +716,35 @@ class BomImportUploadSerializer(DataFileUploadSerializer): TARGET_MODEL = BomItem + class Meta: + fields = [ + 'data_file', + 'part', + 'clear_existing_bom', + ] + + part = serializers.PrimaryKeyRelatedField( + queryset=Part.objects.all(), + required=True, + allow_null=False, + many=False, + ) + + clear_existing_bom = serializers.BooleanField( + label=_('Clear Existing BOM'), + help_text=_('Delete existing BOM items before uploading') + ) + + def save(self): + + data = self.validated_data + + if data.get('clear_existing_bom', False): + part = data['part'] + + with transaction.atomic(): + part.bom_items.all().delete() + class BomImportExtractSerializer(DataFileExtractSerializer): """ diff --git a/InvenTree/part/templates/part/upload_bom.html b/InvenTree/part/templates/part/upload_bom.html index 1646a9b70c..9db26f7b39 100644 --- a/InvenTree/part/templates/part/upload_bom.html +++ b/InvenTree/part/templates/part/upload_bom.html @@ -81,6 +81,11 @@ $('#bom-upload').click(function() { method: 'POST', fields: { data_file: {}, + part: { + value: {{ part.pk }}, + hidden: true, + }, + clear_existing_bom: {}, }, title: '{% trans "Upload BOM File" %}', onSuccess: function(response) {