chore: Add external_id to representation
This commit is contained in:
@@ -7,26 +7,30 @@ from datetime import datetime
|
|||||||
|
|
||||||
|
|
||||||
class PaymentMethods(models.TextChoices):
|
class PaymentMethods(models.TextChoices):
|
||||||
CASH = 'CASH', _('Efectivo')
|
CASH = "CASH", _("Efectivo")
|
||||||
CONFIAR = 'CONFIAR', _('Confiar')
|
CONFIAR = "CONFIAR", _("Confiar")
|
||||||
BANCOLOMBIA = 'BANCOLOMBIA', _('Bancolombia')
|
BANCOLOMBIA = "BANCOLOMBIA", _("Bancolombia")
|
||||||
CREDIT = 'CREDIT', _('Crédito')
|
CREDIT = "CREDIT", _("Crédito")
|
||||||
|
|
||||||
|
|
||||||
class Customer(models.Model):
|
class Customer(models.Model):
|
||||||
name = models.CharField(max_length=100, default=None, null=False, blank=False)
|
name = models.CharField(
|
||||||
|
max_length=100, default=None, null=False, blank=False
|
||||||
|
)
|
||||||
address = models.CharField(max_length=100, null=True, blank=True)
|
address = models.CharField(max_length=100, null=True, blank=True)
|
||||||
email = models.CharField(max_length=100, null=True, blank=True)
|
email = models.CharField(max_length=100, null=True, blank=True)
|
||||||
phone = models.CharField(max_length=100, null=True, blank=True)
|
phone = models.CharField(max_length=100, null=True, blank=True)
|
||||||
external_id = models.CharField(max_length=100, null=True, blank=True)
|
external_id = models.CharField(max_length=100, null=True, blank=True)
|
||||||
address_external_id = models.CharField(max_length=100, null=True, blank=True)
|
address_external_id = models.CharField(
|
||||||
|
max_length=100, null=True, blank=True
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class MeasuringUnits(models.TextChoices):
|
class MeasuringUnits(models.TextChoices):
|
||||||
UNIT = 'UNIT', _('Unit')
|
UNIT = "UNIT", _("Unit")
|
||||||
|
|
||||||
|
|
||||||
class ProductCategory(models.Model):
|
class ProductCategory(models.Model):
|
||||||
@@ -42,9 +46,11 @@ class Product(models.Model):
|
|||||||
measuring_unit = models.CharField(
|
measuring_unit = models.CharField(
|
||||||
max_length=20,
|
max_length=20,
|
||||||
choices=MeasuringUnits.choices,
|
choices=MeasuringUnits.choices,
|
||||||
default=MeasuringUnits.UNIT
|
default=MeasuringUnits.UNIT,
|
||||||
|
)
|
||||||
|
unit_external_id = models.CharField(
|
||||||
|
max_length=100, null=True, blank=True
|
||||||
)
|
)
|
||||||
unit_external_id = models.CharField(max_length=100, null=True, blank=True)
|
|
||||||
categories = models.ManyToManyField(ProductCategory)
|
categories = models.ManyToManyField(ProductCategory)
|
||||||
external_id = models.CharField(max_length=100, null=True, blank=True)
|
external_id = models.CharField(max_length=100, null=True, blank=True)
|
||||||
|
|
||||||
@@ -61,7 +67,8 @@ class Product(models.Model):
|
|||||||
"name": product.name,
|
"name": product.name,
|
||||||
"price_list": product.price,
|
"price_list": product.price,
|
||||||
"uom": product.measuring_unit,
|
"uom": product.measuring_unit,
|
||||||
"categories": [c.name for c in product.categories.all()]
|
"external_id": product.external_id,
|
||||||
|
"categories": [c.name for c in product.categories.all()],
|
||||||
}
|
}
|
||||||
products_list.append(rproduct)
|
products_list.append(rproduct)
|
||||||
return products_list
|
return products_list
|
||||||
@@ -74,7 +81,9 @@ class ReconciliationJar(models.Model):
|
|||||||
reconcilier = models.CharField(max_length=255, null=False, blank=False)
|
reconcilier = models.CharField(max_length=255, null=False, blank=False)
|
||||||
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)
|
||||||
total_cash_purchases = models.DecimalField(max_digits=9, decimal_places=2)
|
total_cash_purchases = models.DecimalField(
|
||||||
|
max_digits=9, decimal_places=2
|
||||||
|
)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
self._validate_taken_ammount()
|
self._validate_taken_ammount()
|
||||||
@@ -102,13 +111,13 @@ class Sale(models.Model):
|
|||||||
choices=PaymentMethods.choices,
|
choices=PaymentMethods.choices,
|
||||||
default=PaymentMethods.CASH,
|
default=PaymentMethods.CASH,
|
||||||
blank=False,
|
blank=False,
|
||||||
null=False
|
null=False,
|
||||||
)
|
)
|
||||||
reconciliation = models.ForeignKey(
|
reconciliation = models.ForeignKey(
|
||||||
ReconciliationJar,
|
ReconciliationJar,
|
||||||
on_delete=models.RESTRICT,
|
on_delete=models.RESTRICT,
|
||||||
related_name='Sales',
|
related_name="Sales",
|
||||||
null=True
|
null=True,
|
||||||
)
|
)
|
||||||
external_id = models.CharField(max_length=100, null=True, blank=True)
|
external_id = models.CharField(max_length=100, null=True, blank=True)
|
||||||
|
|
||||||
@@ -121,7 +130,9 @@ class Sale(models.Model):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.payment_method not in PaymentMethods.values:
|
if self.payment_method not in PaymentMethods.values:
|
||||||
raise ValidationError({'payment_method': "Invalid payment method"})
|
raise ValidationError(
|
||||||
|
{"payment_method": "Invalid payment method"}
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sale_header_csv(cls):
|
def sale_header_csv(cls):
|
||||||
@@ -133,8 +144,12 @@ class Sale(models.Model):
|
|||||||
class SaleLine(models.Model):
|
class SaleLine(models.Model):
|
||||||
|
|
||||||
sale = models.ForeignKey(Sale, on_delete=models.CASCADE)
|
sale = models.ForeignKey(Sale, on_delete=models.CASCADE)
|
||||||
product = models.ForeignKey(Product, null=False, blank=False, on_delete=models.CASCADE)
|
product = models.ForeignKey(
|
||||||
quantity = models.DecimalField(max_digits=10, decimal_places=2, null=True)
|
Product, null=False, blank=False, on_delete=models.CASCADE
|
||||||
|
)
|
||||||
|
quantity = models.DecimalField(
|
||||||
|
max_digits=10, decimal_places=2, null=True
|
||||||
|
)
|
||||||
unit_price = models.DecimalField(max_digits=9, decimal_places=2)
|
unit_price = models.DecimalField(max_digits=9, decimal_places=2)
|
||||||
description = models.CharField(max_length=255, null=True, blank=True)
|
description = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
|
||||||
@@ -142,7 +157,7 @@ class SaleLine(models.Model):
|
|||||||
return f"{self.sale} - {self.product}"
|
return f"{self.sale} - {self.product}"
|
||||||
|
|
||||||
|
|
||||||
class ReconciliationJarSummary():
|
class ReconciliationJarSummary:
|
||||||
def __init__(self, payments):
|
def __init__(self, payments):
|
||||||
self._validate_payments(payments)
|
self._validate_payments(payments)
|
||||||
self._payments = payments
|
self._payments = payments
|
||||||
@@ -164,7 +179,7 @@ class Payment(models.Model):
|
|||||||
type_payment = models.CharField(
|
type_payment = models.CharField(
|
||||||
max_length=30,
|
max_length=30,
|
||||||
choices=PaymentMethods.choices,
|
choices=PaymentMethods.choices,
|
||||||
default=PaymentMethods.CASH
|
default=PaymentMethods.CASH,
|
||||||
)
|
)
|
||||||
amount = models.DecimalField(max_digits=9, decimal_places=2)
|
amount = models.DecimalField(max_digits=9, decimal_places=2)
|
||||||
reconciliation_jar = models.ForeignKey(
|
reconciliation_jar = models.ForeignKey(
|
||||||
@@ -172,7 +187,7 @@ class Payment(models.Model):
|
|||||||
null=True,
|
null=True,
|
||||||
default=None,
|
default=None,
|
||||||
blank=True,
|
blank=True,
|
||||||
on_delete=models.RESTRICT
|
on_delete=models.RESTRICT,
|
||||||
)
|
)
|
||||||
description = models.CharField(max_length=255, null=True, blank=True)
|
description = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
|
||||||
@@ -180,8 +195,7 @@ class Payment(models.Model):
|
|||||||
def get_reconciliation_jar_summary(cls):
|
def get_reconciliation_jar_summary(cls):
|
||||||
return ReconciliationJarSummary(
|
return ReconciliationJarSummary(
|
||||||
cls.objects.filter(
|
cls.objects.filter(
|
||||||
type_payment=PaymentMethods.CASH,
|
type_payment=PaymentMethods.CASH, reconciliation_jar=None
|
||||||
reconciliation_jar=None
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user