""" Author: Michel Peltriaux Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany Contact: michel.peltriaux@sgdnord.rlp.de Created on: 16.11.21 """ from django.core.validators import MinValueValidator from django.db import models from intervention.models import Intervention from konova.models import BaseResource from konova.utils.message_templates import PAYMENT_REMOVED from user.models import UserActionLogEntry class Payment(BaseResource): """ Holds data on a payment for an intervention (alternative to a classic compensation) """ amount = models.FloatField(validators=[MinValueValidator(limit_value=0.00)]) due_on = models.DateField(null=True, blank=True) comment = models.TextField( null=True, blank=True, help_text="Refers to german money transfer 'Verwendungszweck'", ) intervention = models.ForeignKey( Intervention, null=True, blank=True, on_delete=models.CASCADE, related_name='payments' ) class Meta: ordering = [ "-amount", ] def delete(self, user=None, *args, **kwargs): if user is not None: self.intervention.mark_as_edited(user, edit_comment=PAYMENT_REMOVED) super().delete(*args, **kwargs)