Coverage for apps/accounting/models.py: 95%
52 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-04-19 09:45 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-04-19 09:45 -0600
1from django.db import models
2from django.utils.timezone import now
3from djmoney.models.fields import MoneyField
4from polymorphic.models import PolymorphicModel
6from base.models import RandomSlugModel, TimeStampedModel
9class Method(models.Model):
10 class Meta:
11 verbose_name = "Metodo de Pago"
12 verbose_name_plural = "Metodos de Pago"
14 name = models.CharField("Nombre del Metodo", max_length=128)
16 def __str__(self):
17 return self.name
20class Account(PolymorphicModel, RandomSlugModel, TimeStampedModel):
21 class Meta:
22 verbose_name = "Cuenta"
23 verbose_name_plural = "Cuentas"
25 SIDE_CHOICE_LEFT = "L"
26 SIDE_CHOICE_RIGHT = "R"
27 SIDE_CHOICE_SET = (
28 (SIDE_CHOICE_LEFT, "Izquierdo"),
29 (SIDE_CHOICE_RIGHT, "Derecho"),
30 )
32 name = models.CharField(
33 "Nombre",
34 max_length=128,
35 )
36 positive_side = models.CharField(
37 "Lado Positivo",
38 default=SIDE_CHOICE_LEFT,
39 choices=SIDE_CHOICE_SET,
40 max_length=16,
41 )
42 balance = MoneyField(max_digits=14, decimal_places=2, default_currency="MXN", default=0)
44 @property
45 def get_positive_side(self):
46 return self.positive_side
48 @property
49 def get_negative_side(self):
50 return {self.SIDE_CHOICE_LEFT: self.SIDE_CHOICE_RIGHT, self.SIDE_CHOICE_RIGHT: self.SIDE_CHOICE_LEFT}[
51 self.positive_side
52 ]
55class Movement(RandomSlugModel, TimeStampedModel):
56 class Meta:
57 verbose_name = "Movimiento"
58 verbose_name_plural = "Movimientos"
59 ordering = ["-date", "-pk"]
61 account = models.ForeignKey("accounting.Account", on_delete=models.CASCADE, verbose_name="Cuenta")
62 date = models.DateField("Fecha Movimiento", default=now)
63 side = models.CharField("Lado", max_length=1, choices=Account.SIDE_CHOICE_SET)
64 concept = models.CharField(
65 "Comentario",
66 max_length=128,
67 null=True,
68 blank=True,
69 )
70 amount = MoneyField(max_digits=14, decimal_places=2, default_currency="MXN", default=0)
71 reference = models.CharField(
72 "Referencia",
73 max_length=16,
74 null=True,
75 blank=True,
76 )
79class PositiveMovement(Movement):
80 class Meta:
81 proxy = (True,)
82 verbose_name = "Cargo"
83 verbose_name_plural = "Cargos"
86class NegativeMovement(Movement):
87 class Meta:
88 proxy = (True,)
89 verbose_name = "Abono"
90 verbose_name_plural = "Abonos"
92 def save(self, *args, **kwargs):
93 self.side = self.account.get_negative_side
94 return super().save(*args, **kwargs)
97class PatientAccount(Account):
98 patient = models.OneToOneField("patients.Patient", on_delete=models.CASCADE)
100 def __str__(self):
101 return self.name or self.pk