feat: implement reconciliation jar summary.

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

View File

@ -0,0 +1,23 @@
# Generated by Django 5.0.6 on 2024-07-13 14:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('don_confiao', '0011_alter_product_name'),
]
operations = [
migrations.CreateModel(
name='Payment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_time', models.DateTimeField()),
('type_payment', models.CharField(choices=[('CASH', 'Cash'), ('CONFIAR', 'Confiar'), ('BANCOLOMBIA', 'Bancolombia')], default='CASH', max_length=30)),
('mount', models.DecimalField(decimal_places=2, max_digits=9)),
('description', models.CharField(blank=True, max_length=255, null=True)),
],
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-07-13 15:56
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('don_confiao', '0012_payment'),
]
operations = [
migrations.RenameField(
model_name='payment',
old_name='mount',
new_name='amount',
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 5.0.6 on 2024-07-13 16:35
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('don_confiao', '0013_rename_mount_payment_amount'),
]
operations = [
migrations.CreateModel(
name='ReconciliationJar',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_time', models.DateTimeField()),
('description', models.CharField(blank=True, max_length=255, null=True)),
],
),
migrations.AddField(
model_name='payment',
name='reconciliation_jar',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.RESTRICT, to='don_confiao.reconciliationjar'),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 5.0.6 on 2024-07-13 16:36
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('don_confiao', '0014_reconciliationjar_payment_reconciliation_jar'),
]
operations = [
migrations.AlterField(
model_name='payment',
name='reconciliation_jar',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.RESTRICT, to='don_confiao.reconciliationjar'),
),
]

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
)
)

View File

@ -0,0 +1,38 @@
from django.test import Client, TestCase
from .models import Payment
class TestBilling(TestCase):
def test_reconciliation_jar_summary(self):
cash_payment1 = Payment()
cash_payment1.date_time = '2024-07-07 12:00:00'
cash_payment1.type_payment = 'CASH'
cash_payment1.amount = 132000
cash_payment1.description = 'Saldo en compra'
cash_payment1.save()
cash_payment2 = Payment()
cash_payment2.date_time = '2024-07-07 13:05:00'
cash_payment2.type_payment = 'CASH'
cash_payment2.amount = 32000
cash_payment2.save()
confiar_payment = Payment()
confiar_payment.date_time = '2024-07-07 16:00:00'
confiar_payment.type_payment = 'CONFIAR'
confiar_payment.amount = 85000
confiar_payment.save()
bancolombia_payment = Payment()
bancolombia_payment.date_time = '2024-07-07 12:30:00'
bancolombia_payment.type_payment = 'BANCOLOMBIA'
bancolombia_payment.amount = 12000
bancolombia_payment.save()
jar_summary = Payment.get_reconciliation_jar_summary()
self.assertEqual(164000, jar_summary.total)
self.assertSetEqual(
{cash_payment1, cash_payment2},
set(jar_summary.payments)
)