#69 feat(ReconciliationJar): Add total_cash_purchases field.
This commit is contained in:
parent
a3d5fb1b45
commit
bea08da17d
@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0.6 on 2024-12-03 02:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('don_confiao', '0034_sale_reconciliation_alter_payment_type_payment_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='reconciliationjar',
|
||||
name='total_cash_purchases',
|
||||
field=models.DecimalField(decimal_places=2, default=0, max_digits=9),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -69,12 +69,23 @@ class ReconciliationJar(models.Model):
|
||||
reconcilier = models.CharField(max_length=255, null=False, blank=False)
|
||||
cash_taken = models.DecimalField(max_digits=9, decimal_places=2)
|
||||
cash_discrepancy = models.DecimalField(max_digits=9, decimal_places=2)
|
||||
total_cash_purchases = models.DecimalField(max_digits=9, decimal_places=2)
|
||||
|
||||
def clean(self):
|
||||
self._validate_taken_ammount()
|
||||
|
||||
def add_payments(self, payments):
|
||||
for payment in payments:
|
||||
self.payment_set.add(payment)
|
||||
self.is_valid = True
|
||||
|
||||
def _validate_taken_ammount(self):
|
||||
ammount_cash = self.cash_taken + self.cash_discrepancy
|
||||
if not self.total_cash_purchases == ammount_cash:
|
||||
raise ValidationError(
|
||||
{"cash_taken": _("The taken ammount has discrepancy.")}
|
||||
)
|
||||
|
||||
|
||||
class Sale(models.Model):
|
||||
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django.test import TestCase, Client
|
||||
from django.core.exceptions import ValidationError
|
||||
from ..models import Sale, Product, SaleLine, Customer, ReconciliationJar
|
||||
|
||||
import json
|
||||
@ -101,9 +102,20 @@ class TestJarReconcliation(TestCase):
|
||||
self.assertNotIn(str(37*72500), rawContent)
|
||||
self.assertIn(str(47*72500), rawContent)
|
||||
|
||||
def test_don_create_reconcialiation_with_bad_numbers(self):
|
||||
reconciliation = ReconciliationJar()
|
||||
reconciliation.date_time = "2024-07-30"
|
||||
reconciliation.total_cash_purchases = 145000
|
||||
reconciliation.cash_taken = 143000
|
||||
reconciliation.cash_discrepancy = 1000
|
||||
with self.assertRaises(ValidationError):
|
||||
reconciliation.clean()
|
||||
reconciliation.save()
|
||||
|
||||
def _create_simple_reconciliation(self):
|
||||
reconciliation = ReconciliationJar()
|
||||
reconciliation.date_time = "2024-07-30"
|
||||
reconciliation.total_cash_purchases = 0
|
||||
reconciliation.cash_taken = 0
|
||||
reconciliation.cash_discrepancy = 0
|
||||
reconciliation.clean()
|
||||
|
Loading…
Reference in New Issue
Block a user