File size: 1,850 Bytes
b4f2238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""客户回款记录模型"""

from __future__ import annotations

from decimal import Decimal
from typing import TYPE_CHECKING, Any, ClassVar

from django.db import models
from django.utils.translation import gettext_lazy as _

if TYPE_CHECKING:
    from django.db.models.fields.related_descriptors import RelatedManager

    from apps.cases.models import Case

    from .contract import Contract


class ClientPaymentRecord(models.Model):
    """客户回款记录"""

    id: int
    contract: models.ForeignKey[Contract | None, Contract] = models.ForeignKey(
        "contracts.Contract",
        on_delete=models.CASCADE,
        related_name="client_payment_records",
        verbose_name=_("关联合同"),
    )
    case: models.ForeignKey[Any | None, Any] = models.ForeignKey(
        "cases.Case",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="client_payment_records",
        verbose_name=_("关联案件"),
    )
    amount: Decimal = models.DecimalField(
        max_digits=14,
        decimal_places=2,
        verbose_name=_("回款金额"),
    )
    image_path = models.CharField(
        max_length=500,
        blank=True,
        null=True,
        verbose_name=_("凭证图片路径"),
    )
    note = models.TextField(
        blank=True,
        null=True,
        verbose_name=_("备注"),
    )
    created_at = models.DateTimeField(
        auto_now_add=True,
        verbose_name=_("创建时间"),
    )

    class Meta:
        verbose_name = _("客户回款")
        verbose_name_plural = _("客户回款")
        ordering = ["-created_at"]
        indexes: ClassVar = [
            models.Index(fields=["contract"]),
            models.Index(fields=["-created_at"]),
        ]

    def __str__(self) -> str:
        return f"{self.contract.name} - ¥{self.amount}"