chore: Add external_id to representation

This commit is contained in:
2026-05-09 15:52:56 -05:00
parent d45dbc4658
commit 6bc76282d1

View File

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