#69 feat(Reconciliation):get purchases for reconciliation endpoint.
This commit is contained in:
@@ -62,6 +62,38 @@ class Product(models.Model):
|
||||
return products_list
|
||||
|
||||
|
||||
class ReconciliationJar(models.Model):
|
||||
is_valid = models.BooleanField(default=False)
|
||||
date_time = models.DateTimeField()
|
||||
description = models.CharField(max_length=255, null=True, blank=True)
|
||||
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)
|
||||
|
||||
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):
|
||||
for payment in payments:
|
||||
self.payment_set.add(payment)
|
||||
self.is_valid = True
|
||||
|
||||
|
||||
class Sale(models.Model):
|
||||
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
|
||||
date = models.DateField("Date")
|
||||
@@ -74,6 +106,12 @@ class Sale(models.Model):
|
||||
blank=False,
|
||||
null=False
|
||||
)
|
||||
reconciliation = models.ForeignKey(
|
||||
ReconciliationJar,
|
||||
on_delete=models.RESTRICT,
|
||||
related_name='Sales',
|
||||
null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.date} {self.customer}"
|
||||
@@ -122,38 +160,6 @@ class ReconciliationJarSummary():
|
||||
return self._payments
|
||||
|
||||
|
||||
class ReconciliationJar(models.Model):
|
||||
is_valid = models.BooleanField(default=False)
|
||||
date_time = models.DateTimeField()
|
||||
description = models.CharField(max_length=255, null=True, blank=True)
|
||||
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)
|
||||
|
||||
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):
|
||||
for payment in payments:
|
||||
self.payment_set.add(payment)
|
||||
self.is_valid = True
|
||||
|
||||
|
||||
class Payment(models.Model):
|
||||
date_time = models.DateTimeField()
|
||||
type_payment = models.CharField(
|
||||
|
||||
Reference in New Issue
Block a user