feat: implement reconciliation jar summary.

This commit is contained in:
2024-07-13 11:43:16 -05:00
parent 7b0bee8313
commit ee38c29ce3
6 changed files with 177 additions and 0 deletions

View File

@@ -44,3 +44,55 @@ class Product(models.Model):
def __str__(self):
return self.name
class PyamentMethods(models.TextChoices):
CASH = 'CASH', _('Cash')
CONFIAR = 'CONFIAR', _('Confiar')
BANCOLOMBIA = 'BANCOLOMBIA', _('Bancolombia')
class ReconciliationJarSummary():
def __init__(self, payments):
self._validate_payments(payments)
self._payments = payments
def _validate_payments(self, payments):
pass
@property
def total(self):
return sum([p.amount for p in self.payments])
@property
def payments(self):
return self._payments
class ReconciliationJar(models.Model):
date_time = models.DateTimeField()
description = models.CharField(max_length=255, null=True, blank=True)
class Payment(models.Model):
date_time = models.DateTimeField()
type_payment = models.CharField(
max_length=30,
choices=PyamentMethods.choices,
default=PyamentMethods.CASH
)
amount = models.DecimalField(max_digits=9, decimal_places=2)
reconciliation_jar = models.ForeignKey(
ReconciliationJar,
null=True,
default=None,
on_delete=models.RESTRICT
)
description = models.CharField(max_length=255, null=True, blank=True)
@classmethod
def get_reconciliation_jar_summary(cls):
return ReconciliationJarSummary(
cls.objects.filter(
type_payment=PyamentMethods.CASH,
reconciliation_jar=None
)
)