refactor: move Products list logic to model.

This commit is contained in:
2024-08-24 10:30:58 -05:00
parent 77361c13db
commit 23ec2bc298
2 changed files with 15 additions and 12 deletions

View File

@@ -37,6 +37,20 @@ class Product(models.Model):
def __str__(self):
return self.name
@classmethod
def to_list(cls):
products_list = []
all_products = cls.objects.all()
for product in all_products:
rproduct = {
"name": product.name,
"price_list": product.price,
"uom": product.measuring_unit,
"categories": [c.name for c in product.categories.all()]
}
products_list.append(rproduct)
return products_list
class Sale(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)