mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Catch db integrity errors
This commit is contained in:
		@@ -75,13 +75,13 @@ class LabelConfig(AppConfig):
 | 
				
			|||||||
                logger.info(f"Copying label template '{dst_file}'")
 | 
					                logger.info(f"Copying label template '{dst_file}'")
 | 
				
			||||||
                shutil.copyfile(src_file, dst_file)
 | 
					                shutil.copyfile(src_file, dst_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
                # Check if a label matching the template already exists
 | 
					                # Check if a label matching the template already exists
 | 
				
			||||||
                if StockItemLabel.objects.filter(label=filename).exists():
 | 
					                if StockItemLabel.objects.filter(label=filename).exists():
 | 
				
			||||||
                    continue
 | 
					                    continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                logger.info(f"Creating entry for StockItemLabel '{label['name']}'")
 | 
					                logger.info(f"Creating entry for StockItemLabel '{label['name']}'")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                StockItemLabel.objects.create(
 | 
					                StockItemLabel.objects.create(
 | 
				
			||||||
                    name=label['name'],
 | 
					                    name=label['name'],
 | 
				
			||||||
                    description=label['description'],
 | 
					                    description=label['description'],
 | 
				
			||||||
@@ -89,7 +89,7 @@ class LabelConfig(AppConfig):
 | 
				
			|||||||
                    filters='',
 | 
					                    filters='',
 | 
				
			||||||
                    enabled=True
 | 
					                    enabled=True
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            except IntegrityError:
 | 
					            except:
 | 
				
			||||||
                pass
 | 
					                pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_stock_location_labels(self):
 | 
					    def create_stock_location_labels(self):
 | 
				
			||||||
@@ -151,13 +151,13 @@ class LabelConfig(AppConfig):
 | 
				
			|||||||
                logger.info(f"Copying label template '{dst_file}'")
 | 
					                logger.info(f"Copying label template '{dst_file}'")
 | 
				
			||||||
                shutil.copyfile(src_file, dst_file)
 | 
					                shutil.copyfile(src_file, dst_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
                # Check if a label matching the template already exists
 | 
					                # Check if a label matching the template already exists
 | 
				
			||||||
                if StockLocationLabel.objects.filter(label=filename).exists():
 | 
					                if StockLocationLabel.objects.filter(label=filename).exists():
 | 
				
			||||||
                    continue
 | 
					                    continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                logger.info(f"Creating entry for StockLocationLabel '{label['name']}'")
 | 
					                logger.info(f"Creating entry for StockLocationLabel '{label['name']}'")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                StockLocationLabel.objects.create(
 | 
					                StockLocationLabel.objects.create(
 | 
				
			||||||
                    name=label['name'],
 | 
					                    name=label['name'],
 | 
				
			||||||
                    description=label['description'],
 | 
					                    description=label['description'],
 | 
				
			||||||
@@ -165,5 +165,5 @@ class LabelConfig(AppConfig):
 | 
				
			|||||||
                    filters='',
 | 
					                    filters='',
 | 
				
			||||||
                    enabled=True
 | 
					                    enabled=True
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            except IntegrityError:
 | 
					            except:
 | 
				
			||||||
                pass
 | 
					                pass
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user