refactoring(Purchase): simplify payment_method #47
This commit is contained in:
@@ -6,6 +6,12 @@ from decimal import Decimal
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class PaymentMethods(models.TextChoices):
|
||||
CASH = 'CASH', _('Cash')
|
||||
CONFIAR = 'CONFIAR', _('Confiar')
|
||||
BANCOLOMBIA = 'BANCOLOMBIA', _('Bancolombia')
|
||||
|
||||
|
||||
class Customer(models.Model):
|
||||
name = models.CharField(max_length=100, default=None, null=False, blank=False)
|
||||
address = models.CharField(max_length=100, null=True, blank=True)
|
||||
@@ -61,6 +67,13 @@ class Sale(models.Model):
|
||||
date = models.DateField("Date")
|
||||
phone = models.CharField(max_length=13, null=True, blank=True)
|
||||
description = models.CharField(max_length=255, null=True, blank=True)
|
||||
payment_method = models.CharField(
|
||||
max_length=30,
|
||||
choices=PaymentMethods.choices,
|
||||
default=PaymentMethods.CASH,
|
||||
blank=False,
|
||||
null=False
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.date} {self.customer}"
|
||||
@@ -69,6 +82,10 @@ class Sale(models.Model):
|
||||
lines = self.saleline_set.all()
|
||||
return sum([l.quantity * l.unit_price for l in lines])
|
||||
|
||||
def clean(self):
|
||||
if self.payment_method not in [choice[0] for choice in PaymentMethods.choices]:
|
||||
raise ValidationError({'payment_method': f"Null or invalid payment method ({self.payment_method}, {PaymentMethods.choices})"})
|
||||
|
||||
@classmethod
|
||||
def sale_header_csv(cls):
|
||||
sale_header_csv = [field.name for field in cls._meta.fields]
|
||||
@@ -88,12 +105,6 @@ class SaleLine(models.Model):
|
||||
return f"{self.sale} - {self.product}"
|
||||
|
||||
|
||||
class PaymentMethods(models.TextChoices):
|
||||
CASH = 'CASH', _('Cash')
|
||||
CONFIAR = 'CONFIAR', _('Confiar')
|
||||
BANCOLOMBIA = 'BANCOLOMBIA', _('Bancolombia')
|
||||
|
||||
|
||||
class ReconciliationJarSummary():
|
||||
def __init__(self, payments):
|
||||
self._validate_payments(payments)
|
||||
|
||||
Reference in New Issue
Block a user