diff --git a/tienda_ilusion/don_confiao/migrations/0038_alter_saleline_quantity.py b/tienda_ilusion/don_confiao/migrations/0038_alter_saleline_quantity.py new file mode 100644 index 0000000..52c9deb --- /dev/null +++ b/tienda_ilusion/don_confiao/migrations/0038_alter_saleline_quantity.py @@ -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), + ), + ] diff --git a/tienda_ilusion/don_confiao/models.py b/tienda_ilusion/don_confiao/models.py index 032998e..4b6c2c9 100644 --- a/tienda_ilusion/don_confiao/models.py +++ b/tienda_ilusion/don_confiao/models.py @@ -128,7 +128,7 @@ 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.IntegerField(null=True) + 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) diff --git a/tienda_ilusion/don_confiao/tests/test_api.py b/tienda_ilusion/don_confiao/tests/test_api.py index dff5dfd..d6b56fc 100644 --- a/tienda_ilusion/don_confiao/tests/test_api.py +++ b/tienda_ilusion/don_confiao/tests/test_api.py @@ -34,6 +34,25 @@ class TestAPI(APITestCase): 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): url = '/don_confiao/api/products/' response = self.client.get(url) @@ -90,10 +109,10 @@ class TestAPI(APITestCase): expected_rows = [ [self.customer.name, self.customer.name, self.customer.name, "", "", "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", "" ], - ["", "", "", "", "", "", "", "", "", self.product.name, "3", + ["", "", "", "", "", "", "", "", "", self.product.name, "3.00", "5000.00", "Unidad", "", "", "", "", "" ], ] @@ -112,3 +131,24 @@ class TestAPI(APITestCase): ], } 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') diff --git a/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py b/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py index 6b946f5..465ea44 100644 --- a/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py @@ -65,8 +65,8 @@ class TestExportarVentasParaTryton(TestCase): self.assertEqual(next(csv_reader), expected_header) 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", ""], - ["", "", "", "", "", "", "", "", "", "Panela", "3", "5000.00", "Unidad", "", "", "", "", ""], + ["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.00", "5000.00", "Unidad", "", "", "", "", ""], ] csv_rows = list(csv_reader) self.assertEqual(csv_rows[0], expected_rows[0])