feat: implementing form to reconciliation jar.

This commit is contained in:
2024-07-13 17:13:17 -05:00
parent ee38c29ce3
commit a8f8820a55
12 changed files with 266 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ValidationError
class Sale(models.Model):
@@ -23,15 +25,18 @@ class SaleLine(models.Model):
def __str__(self):
return f"{self.sale} - {self.product}"
class MeasuringUnits(models.TextChoices):
UNIT = 'UNIT', _('Unit')
class ProductCategory(models.Model):
name = models.CharField(max_length=100, unique=True)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=100, unique=True)
price = models.DecimalField(max_digits=9, decimal_places=2)
@@ -45,11 +50,13 @@ 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)
@@ -68,9 +75,24 @@ class ReconciliationJarSummary():
class ReconciliationJar(models.Model):
is_valid = models.BooleanField(default=False)
date_time = models.DateTimeField()
description = models.CharField(max_length=255, null=True, blank=True)
reconciler = 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)
def clean(self):
payments_amount = sum([p.amount for p in self.payment_set.all()])
reconciliation_ammount = sum([
self.cash_taken,
self.cash_discrepancy,
])
if reconciliation_ammount != payments_amount:
raise ValidationError(
{"cash_take": _("The taken ammount has discrepancy.")}
)
self.is_valid = True
class Payment(models.Model):
date_time = models.DateTimeField()