#36 Quality checks
* adds check on recording of intervention in case of invalid compensations
This commit is contained in:
		
							parent
							
								
									d7bb2ef1dd
								
							
						
					
					
						commit
						13c1a35a36
					
				@ -481,8 +481,27 @@ class RecordModalForm(BaseModalForm):
 | 
				
			|||||||
                "confirm",
 | 
					                "confirm",
 | 
				
			||||||
                msg
 | 
					                msg
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					        # Special case: Intervention
 | 
				
			||||||
 | 
					        # Add direct checks for related compensations
 | 
				
			||||||
 | 
					        if isinstance(self.instance, Intervention):
 | 
				
			||||||
 | 
					            self._are_compensations_valid()
 | 
				
			||||||
        return super_val and checker.valid
 | 
					        return super_val and checker.valid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _are_compensations_valid(self):
 | 
				
			||||||
 | 
					        """ Runs a special case for intervention-compensations validity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Returns:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        comps = self.instance.compensations.all()
 | 
				
			||||||
 | 
					        for comp in comps:
 | 
				
			||||||
 | 
					            checker = comp.quality_check()
 | 
				
			||||||
 | 
					            for msg in checker.messages:
 | 
				
			||||||
 | 
					                self.add_error(
 | 
				
			||||||
 | 
					                    "confirm",
 | 
				
			||||||
 | 
					                    f"{comp.identifier}: {msg}"
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def save(self):
 | 
					    def save(self):
 | 
				
			||||||
        with transaction.atomic():
 | 
					        with transaction.atomic():
 | 
				
			||||||
            if self.cleaned_data["confirm"]:
 | 
					            if self.cleaned_data["confirm"]:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user