fix(Sale): allow decimal on quantity products.

This commit is contained in:
Mono Mono 2025-04-06 16:02:44 -05:00
parent 3c318f2751
commit 8791c5fa2d
4 changed files with 63 additions and 5 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2025-04-06 20:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('don_confiao', '0037_admincode'),
]
operations = [
migrations.AlterField(
model_name='saleline',
name='quantity',
field=models.DecimalField(decimal_places=2, max_digits=10, null=True),
),
]

View File

@ -128,7 +128,7 @@ 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(Product, null=False, blank=False, on_delete=models.CASCADE)
quantity = models.IntegerField(null=True) 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)

View File

@ -34,6 +34,25 @@ class TestAPI(APITestCase):
content['id'] content['id']
) )
def test_create_sale_with_decimal(self):
response = self._create_sale_with_decimal()
content = json.loads(response.content.decode('utf-8'))
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Sale.objects.count(), 1)
sale = Sale.objects.all()[0]
self.assertEqual(
sale.customer.name,
self.customer.name
)
self.assertEqual(
sale.id,
content['id']
)
self.assertEqual(
sale.get_total(),
16500.00
)
def test_get_products(self): def test_get_products(self):
url = '/don_confiao/api/products/' url = '/don_confiao/api/products/'
response = self.client.get(url) response = self.client.get(url)
@ -90,10 +109,10 @@ class TestAPI(APITestCase):
expected_rows = [ expected_rows = [
[self.customer.name, self.customer.name, self.customer.name, "", [self.customer.name, self.customer.name, self.customer.name, "",
"", "2024-09-02 00:00:00+00:00", "Contado", "Almacén", "", "2024-09-02 00:00:00+00:00", "Contado", "Almacén",
"Peso colombiano", self.product.name, "2", "3000.00", "Unidad", "Peso colombiano", self.product.name, "2.00", "3000.00", "Unidad",
"TIENDA LA ILUSIÓN", "Tienda La Ilusion", "La Ilusion", "True", "" "TIENDA LA ILUSIÓN", "Tienda La Ilusion", "La Ilusion", "True", ""
], ],
["", "", "", "", "", "", "", "", "", self.product.name, "3", ["", "", "", "", "", "", "", "", "", self.product.name, "3.00",
"5000.00", "Unidad", "", "", "", "", "" "5000.00", "Unidad", "", "", "", "", ""
], ],
] ]
@ -112,3 +131,24 @@ class TestAPI(APITestCase):
], ],
} }
return self.client.post(url, data, format='json') return self.client.post(url, data, format='json')
def _create_sale_with_decimal(self):
url = '/don_confiao/api/sales/'
data = {
'customer': self.customer.id,
'date': '2024-09-02',
'payment_method': 'CASH',
'saleline_set': [
{
'product': self.product.id,
'quantity': 0.5,
'unit_price': 3000
},
{
'product': self.product.id,
'quantity': 3,
'unit_price': 5000
}
],
}
return self.client.post(url, data, format='json')

View File

@ -65,8 +65,8 @@ class TestExportarVentasParaTryton(TestCase):
self.assertEqual(next(csv_reader), expected_header) self.assertEqual(next(csv_reader), expected_header)
expected_rows = [ expected_rows = [
["Camilo", "Camilo", "Camilo", "", "", "2024-09-02 00:00:00+00:00", "Contado", "Almacén", "Peso colombiano", "Panela", "2", "3000.00", "Unidad", "TIENDA LA ILUSIÓN", "Tienda La Ilusion", "La Ilusion", "True", ""], ["Camilo", "Camilo", "Camilo", "", "", "2024-09-02 00:00:00+00:00", "Contado", "Almacén", "Peso colombiano", "Panela", "2.00", "3000.00", "Unidad", "TIENDA LA ILUSIÓN", "Tienda La Ilusion", "La Ilusion", "True", ""],
["", "", "", "", "", "", "", "", "", "Panela", "3", "5000.00", "Unidad", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "Panela", "3.00", "5000.00", "Unidad", "", "", "", "", ""],
] ]
csv_rows = list(csv_reader) csv_rows = list(csv_reader)
self.assertEqual(csv_rows[0], expected_rows[0]) self.assertEqual(csv_rows[0], expected_rows[0])