2021-11-16 08:29:18 +01:00
|
|
|
"""
|
|
|
|
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
|
2022-02-02 15:16:25 +01:00
|
|
|
from konova.utils.message_templates import PAYMENT_REMOVED
|
|
|
|
from user.models import UserActionLogEntry
|
2021-11-16 08:29:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
]
|
2022-02-02 15:16:25 +01:00
|
|
|
|
|
|
|
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)
|