mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 15:15:42 +00:00 
			
		
		
		
	Reintroduce option to clear (delete) BOM before uploading new data
This commit is contained in:
		@@ -716,6 +716,35 @@ class BomImportUploadSerializer(DataFileUploadSerializer):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    TARGET_MODEL = BomItem
 | 
					    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):
 | 
					class BomImportExtractSerializer(DataFileExtractSerializer):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,6 +81,11 @@ $('#bom-upload').click(function() {
 | 
				
			|||||||
        method: 'POST',
 | 
					        method: 'POST',
 | 
				
			||||||
        fields: {
 | 
					        fields: {
 | 
				
			||||||
            data_file: {},
 | 
					            data_file: {},
 | 
				
			||||||
 | 
					            part: {
 | 
				
			||||||
 | 
					                value: {{ part.pk }},
 | 
				
			||||||
 | 
					                hidden: true,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            clear_existing_bom: {},
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        title: '{% trans "Upload BOM File" %}',
 | 
					        title: '{% trans "Upload BOM File" %}',
 | 
				
			||||||
        onSuccess: function(response) {
 | 
					        onSuccess: function(response) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user