fix(ExportSales): add test and fix.
This commit is contained in:
		| @@ -0,0 +1,73 @@ | ||||
| import csv | ||||
|  | ||||
| from django.test import TestCase, Client | ||||
| from django.urls import reverse | ||||
|  | ||||
| from ..models import Sale, SaleLine, Product, Customer | ||||
|  | ||||
| class TestExportarVentasParaTryton(TestCase): | ||||
|     def setUp(self): | ||||
|         self.product = Product.objects.create( | ||||
|             name='Panela', | ||||
|             price=5000, | ||||
|             measuring_unit='UNIT' | ||||
|         ) | ||||
|         self.customer = Customer.objects.create( | ||||
|             name='Camilo' | ||||
|         ) | ||||
|         self.sale = Sale.objects.create( | ||||
|             customer=self.customer, | ||||
|             date='2024-09-02', | ||||
|             payment_method='CASH', | ||||
|         ) | ||||
|         self.sale_line1 = SaleLine.objects.create( | ||||
|             product=self.product, | ||||
|             quantity=2, | ||||
|             unit_price=3000, | ||||
|             sale=self.sale | ||||
|         ) | ||||
|         self.sale_line2 = SaleLine.objects.create( | ||||
|             product=self.product, | ||||
|             quantity=3, | ||||
|             unit_price=5000, | ||||
|             sale=self.sale | ||||
|         ) | ||||
|  | ||||
|     def test_exportar_ventas_para_tryton(self): | ||||
|         client = Client() | ||||
|         url = '/don_confiao/exportar_ventas_para_tryton' | ||||
|         response = client.get(url) | ||||
|         self.assertEqual(response.status_code, 200) | ||||
|         self.assertEqual(response['Content-Type'], 'text/csv') | ||||
|         csv_content = response.content.decode('utf-8') | ||||
|  | ||||
|         expected_header = [ | ||||
|             "Tercero", | ||||
|             "Dirección de facturación", | ||||
|             "Dirección de envío", | ||||
|             "Descripción", | ||||
|             "Referencia", | ||||
|             "Fecha venta", | ||||
|             "Plazo de pago", | ||||
|             "Almacén", | ||||
|             "Moneda", | ||||
|             "Líneas/Producto", | ||||
|             "Líneas/Cantidad", | ||||
|             "Líneas/Precio unitario", | ||||
|             "Líneas/Unidad", | ||||
|             "Empresa", | ||||
|             "Tienda", | ||||
|             "Terminal de venta", | ||||
|             "Autorecogida", | ||||
|             "Comentario" | ||||
|         ] | ||||
|         csv_reader = csv.reader(csv_content.splitlines()) | ||||
|         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", "", "", "", "", ""], | ||||
|         ] | ||||
|         csv_rows = list(csv_reader) | ||||
|         self.assertEqual(csv_rows[0], expected_rows[0]) | ||||
|         self.assertEqual(csv_rows[1], expected_rows[1]) | ||||
		Reference in New Issue
	
	Block a user