Refactoring
* moves add_state from compensation to AbstractCompensation
This commit is contained in:
		
							parent
							
								
									779065ec91
								
							
						
					
					
						commit
						8e1c4446dd
					
				@ -101,6 +101,34 @@ class AbstractCompensation(BaseObject):
 | 
			
		||||
            self.actions.add(comp_action)
 | 
			
		||||
            return comp_action
 | 
			
		||||
 | 
			
		||||
    def add_state(self, form, is_before_state: bool) -> CompensationState:
 | 
			
		||||
        """ Adds a new compensation state to the compensation
 | 
			
		||||
 | 
			
		||||
        Args:
 | 
			
		||||
            form (NewStateModalForm): The form, holding all relevant data
 | 
			
		||||
            is_before_state (bool): Whether this is a new before_state or after_state
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        form_data = form.cleaned_data
 | 
			
		||||
        user = form.user
 | 
			
		||||
        with transaction.atomic():
 | 
			
		||||
            user_action = UserActionLogEntry.get_edited_action(user, _("Added state"))
 | 
			
		||||
            self.log.add(user_action)
 | 
			
		||||
            self.modified = user_action
 | 
			
		||||
            self.save()
 | 
			
		||||
 | 
			
		||||
            state = CompensationState.objects.create(
 | 
			
		||||
                biotope_type=form_data["biotope_type"],
 | 
			
		||||
                surface=form_data["surface"],
 | 
			
		||||
            )
 | 
			
		||||
            if is_before_state:
 | 
			
		||||
                self.before_states.add(state)
 | 
			
		||||
            else:
 | 
			
		||||
                self.after_states.add(state)
 | 
			
		||||
            return state
 | 
			
		||||
 | 
			
		||||
    def get_surface_after_states(self) -> float:
 | 
			
		||||
        """ Calculates the compensation's/account's surface
 | 
			
		||||
 | 
			
		||||
@ -243,35 +271,6 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
 | 
			
		||||
        )
 | 
			
		||||
        return docs
 | 
			
		||||
 | 
			
		||||
    def add_state(self, form, is_before_state: bool) -> CompensationState:
 | 
			
		||||
        """ Adds a new compensation state to the compensation
 | 
			
		||||
 | 
			
		||||
        Args:
 | 
			
		||||
            form (NewStateModalForm): The form, holding all relevant data
 | 
			
		||||
            is_before_state (bool): Whether this is a new before_state or after_state
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        form_data = form.cleaned_data
 | 
			
		||||
        user = form.user
 | 
			
		||||
        with transaction.atomic():
 | 
			
		||||
            user_action = UserActionLogEntry.get_edited_action(user, _("Added state"))
 | 
			
		||||
            self.log.add(user_action)
 | 
			
		||||
            self.modified = user_action
 | 
			
		||||
            self.save()
 | 
			
		||||
 | 
			
		||||
            state = CompensationState.objects.create(
 | 
			
		||||
                biotope_type=form_data["biotope_type"],
 | 
			
		||||
                surface=form_data["surface"],
 | 
			
		||||
            )
 | 
			
		||||
            if is_before_state:
 | 
			
		||||
                self.before_states.add(state)
 | 
			
		||||
            else:
 | 
			
		||||
                self.after_states.add(state)
 | 
			
		||||
            return state
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CompensationDocument(AbstractDocument):
 | 
			
		||||
    """
 | 
			
		||||
    Specializes document upload for revocations with certain path
 | 
			
		||||
 | 
			
		||||
@ -35,4 +35,3 @@ class Payment(BaseResource):
 | 
			
		||||
        ordering = [
 | 
			
		||||
            "-amount",
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user