feat: implement reconciliation jar summary.
This commit is contained in:
@@ -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
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user