#69 refactor(ReconciliationJar): remove old view.
This commit is contained in:
parent
3294b8e814
commit
0d61e457c7
@ -70,24 +70,6 @@ class ReconciliationJar(models.Model):
|
|||||||
cash_taken = models.DecimalField(max_digits=9, decimal_places=2)
|
cash_taken = models.DecimalField(max_digits=9, decimal_places=2)
|
||||||
cash_discrepancy = models.DecimalField(max_digits=9, decimal_places=2)
|
cash_discrepancy = models.DecimalField(max_digits=9, decimal_places=2)
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
if not self.is_valid:
|
|
||||||
payments = Payment.get_reconciliation_jar_summary().payments
|
|
||||||
else:
|
|
||||||
payments = self.payment_set.all()
|
|
||||||
|
|
||||||
payments_amount = Decimal(sum([p.amount for p in payments]))
|
|
||||||
reconciliation_ammount = Decimal(sum([
|
|
||||||
self.cash_taken,
|
|
||||||
self.cash_discrepancy,
|
|
||||||
]))
|
|
||||||
|
|
||||||
equal_ammounts = reconciliation_ammount.compare(payments_amount) == Decimal('0')
|
|
||||||
if not equal_ammounts:
|
|
||||||
raise ValidationError(
|
|
||||||
{"cash_taken": _("The taken ammount has discrepancy.")}
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_payments(self, payments):
|
def add_payments(self, payments):
|
||||||
for payment in payments:
|
for payment in payments:
|
||||||
self.payment_set.add(payment)
|
self.payment_set.add(payment)
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
<li><a href='/don_confiao/lista_productos'>Productos</a></li>
|
<li><a href='/don_confiao/lista_productos'>Productos</a></li>
|
||||||
<li><a href='/don_confiao/importar_productos'>Importar Productos</a></li>
|
<li><a href='/don_confiao/importar_productos'>Importar Productos</a></li>
|
||||||
<li><a href='/don_confiao/importar_terceros'>Importar Terceros</a></li>
|
<li><a href='/don_confiao/importar_terceros'>Importar Terceros</a></li>
|
||||||
<li><a href='/don_confiao/cuadrar_tarro'>Cuadrar tarro</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<p id="page_title" class="text-center decoration-solid font-mono font-bold text-lg page_title">Don Confiao - Tienda la Ilusión</p>
|
<p id="page_title" class="text-center decoration-solid font-mono font-bold text-lg page_title">Don Confiao - Tienda la Ilusión</p>
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
{% extends 'don_confiao/base.html' %}
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
{% if summary.total %}
|
|
||||||
<div class="reconciliate_jar summary" style="border: solid 1px brown; margin: 10px">
|
|
||||||
<h2>Pagos No reconciliados</h2>
|
|
||||||
<table style="border: solid 1px blue; margin: 10px">
|
|
||||||
<thead>
|
|
||||||
<tr><th>Fecha</th><th>Monto</th></tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for payment in summary.payments %}
|
|
||||||
<tr><td>{{ payment.date_time }}</td><td>{{ payment.amount }}</td></tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
<tfoot>
|
|
||||||
<tr><th>Total</th><td>{{ summary.total }}</td></tr>
|
|
||||||
</tfoot>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<form method="POST">
|
|
||||||
<table style="border: solid 1px blue; margin: 10px">
|
|
||||||
{% csrf_token %}
|
|
||||||
{{ form.as_table }}
|
|
||||||
</table>
|
|
||||||
<br/><button name="form" type="submit" >Recoger dinero</button>
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
<div class="reconciliate_jar information noform">
|
|
||||||
<h2>No hay pagos registrados.</h2>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@ -1,88 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from ..models import Payment, ReconciliationJar
|
|
||||||
|
|
||||||
|
|
||||||
class TestBilling(TestCase):
|
|
||||||
|
|
||||||
def test_reconciliation_jar_summary(self):
|
|
||||||
cash_payment1, cash_payment2 = self._create_two_cash_payments()
|
|
||||||
jar_summary = Payment.get_reconciliation_jar_summary()
|
|
||||||
self.assertEqual(164000, jar_summary.total)
|
|
||||||
self.assertSetEqual(
|
|
||||||
{cash_payment1, cash_payment2},
|
|
||||||
set(jar_summary.payments)
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_reconciliation_jar_summary_use_only_cash(self):
|
|
||||||
cash_payment1, cash_payment2 = self._create_two_cash_payments()
|
|
||||||
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_fail_validate_reconciliation_jar_with_discrepancy_values(self):
|
|
||||||
cash_payment1, cash_payment2 = self._create_two_cash_payments()
|
|
||||||
|
|
||||||
jar_summary = Payment.get_reconciliation_jar_summary()
|
|
||||||
|
|
||||||
reconciliation_jar = ReconciliationJar()
|
|
||||||
reconciliation_jar.date_time = '2024-07-13 13:02:00'
|
|
||||||
reconciliation_jar.description = "test reconcialiation jar"
|
|
||||||
reconciliation_jar.reconcilier = 'Jorge'
|
|
||||||
reconciliation_jar.cash_float = 0
|
|
||||||
reconciliation_jar.cash_taken = 0
|
|
||||||
reconciliation_jar.cash_discrepancy = 0
|
|
||||||
reconciliation_jar.save()
|
|
||||||
|
|
||||||
reconciliation_jar.add_payments(jar_summary.payments)
|
|
||||||
with self.assertRaises(ValidationError):
|
|
||||||
reconciliation_jar.clean()
|
|
||||||
|
|
||||||
def test_validate_reconciliation_jar_with_cash_float(self):
|
|
||||||
cash_payment1, cash_payment2 = self._create_two_cash_payments()
|
|
||||||
jar_summary = Payment.get_reconciliation_jar_summary()
|
|
||||||
|
|
||||||
reconciliation_jar = ReconciliationJar()
|
|
||||||
reconciliation_jar.date_time = '2024-07-13 13:02:00'
|
|
||||||
reconciliation_jar.description = "test reconcialiation jar"
|
|
||||||
reconciliation_jar.reconcilier = 'Jorge'
|
|
||||||
reconciliation_jar.cash_taken = jar_summary.total
|
|
||||||
reconciliation_jar.cash_discrepancy = 0
|
|
||||||
reconciliation_jar.save()
|
|
||||||
|
|
||||||
reconciliation_jar.add_payments(jar_summary.payments)
|
|
||||||
reconciliation_jar.clean()
|
|
||||||
reconciliation_jar.save()
|
|
||||||
self.assertTrue(reconciliation_jar.is_valid)
|
|
||||||
|
|
||||||
def _create_two_cash_payments(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()
|
|
||||||
|
|
||||||
return [cash_payment1, cash_payment2]
|
|
@ -1,44 +0,0 @@
|
|||||||
from django.test import Client, TestCase
|
|
||||||
from django.contrib.auth.models import AnonymousUser, User
|
|
||||||
|
|
||||||
from ..models import Payment
|
|
||||||
|
|
||||||
|
|
||||||
class TestReconciliationJarClient(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
def test_get_summary_info_on_view(self):
|
|
||||||
self._generate_two_cash_payments()
|
|
||||||
response = self.client.get("/don_confiao/cuadrar_tarro")
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
self.assertEqual(response.context["summary"].total, 160000)
|
|
||||||
self.assertIn('160000', response.content.decode('utf-8'))
|
|
||||||
|
|
||||||
def test_create_reconciliation_jar(self):
|
|
||||||
self._generate_two_cash_payments()
|
|
||||||
response = self.client.post(
|
|
||||||
"/don_confiao/cuadrar_tarro",
|
|
||||||
{
|
|
||||||
"date_time": "2024-07-20T00:00",
|
|
||||||
"description": "Cuadre de prueba",
|
|
||||||
"reconcilier": "Jorge",
|
|
||||||
"cash_taken": "100000",
|
|
||||||
"cash_discrepancy": "60000",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
self.assertRedirects(response, '/don_confiao/cuadres')
|
|
||||||
|
|
||||||
def _generate_two_cash_payments(self):
|
|
||||||
cash_payment1 = Payment()
|
|
||||||
cash_payment1.date_time = '2024-07-07 12:00:00'
|
|
||||||
cash_payment1.type_payment = 'CASH'
|
|
||||||
cash_payment1.amount = 130000
|
|
||||||
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 = 30000
|
|
||||||
cash_payment2.save()
|
|
@ -24,7 +24,6 @@ urlpatterns = [
|
|||||||
views.exportar_ventas_para_tryton,
|
views.exportar_ventas_para_tryton,
|
||||||
name="exportar_ventas_para_tryton"),
|
name="exportar_ventas_para_tryton"),
|
||||||
path("cuadrar_tarro", views.reconciliate_jar, name="reconciliate_jar"),
|
path("cuadrar_tarro", views.reconciliate_jar, name="reconciliate_jar"),
|
||||||
path("cuadres", views.reconciliate_jar, name="reconciliations"),
|
|
||||||
path("resumen_compra/<int:id>", views.purchase_summary, name="purchase_summary"),
|
path("resumen_compra/<int:id>", views.purchase_summary, name="purchase_summary"),
|
||||||
path("resumen_compra_json/<int:id>", views.purchase_json_summary, name="purchase_json_summary"),
|
path("resumen_compra_json/<int:id>", views.purchase_json_summary, name="purchase_json_summary"),
|
||||||
path("payment_methods/all/select_format", views.payment_methods_to_select, name="payment_methods_to_select"),
|
path("payment_methods/all/select_format", views.payment_methods_to_select, name="payment_methods_to_select"),
|
||||||
|
@ -10,7 +10,6 @@ from .forms import (
|
|||||||
ImportCustomersForm,
|
ImportCustomersForm,
|
||||||
PurchaseForm,
|
PurchaseForm,
|
||||||
SaleLineFormSet,
|
SaleLineFormSet,
|
||||||
ReconciliationJarForm,
|
|
||||||
PurchaseSummaryForm)
|
PurchaseSummaryForm)
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
@ -110,22 +109,7 @@ def import_customers(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def reconciliate_jar(request):
|
def reconciliate_jar(request):
|
||||||
summary = Payment.get_reconciliation_jar_summary()
|
pass
|
||||||
if request.method == 'POST':
|
|
||||||
form = ReconciliationJarForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
reconciliation = form.save()
|
|
||||||
reconciliation.add_payments(summary.payments)
|
|
||||||
reconciliation.clean()
|
|
||||||
reconciliation.save()
|
|
||||||
return HttpResponseRedirect('cuadres')
|
|
||||||
else:
|
|
||||||
form = ReconciliationJarForm()
|
|
||||||
return render(
|
|
||||||
request,
|
|
||||||
"don_confiao/reconciliate_jar.html",
|
|
||||||
{'summary': summary, 'form': form}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def reconciliations(request):
|
def reconciliations(request):
|
||||||
|
Loading…
Reference in New Issue
Block a user