Merge branch 'main' into implement_api
This commit is contained in:
		
							
								
								
									
										47
									
								
								tienda_ilusion/don_confiao/tests/Fixtures/sales_fixture.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								tienda_ilusion/don_confiao/tests/Fixtures/sales_fixture.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| [ | ||||
|   { | ||||
|     "model": "don_confiao.customer", | ||||
|     "pk": 1, | ||||
|     "fields": { | ||||
|       "name": "Alejandro Fernandez", | ||||
|       "address": "Avenida Siempre Viva" | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     "model": "don_confiao.productcategory", | ||||
|     "pk": 1, | ||||
|     "fields": { | ||||
|       "name": "Unidad" | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     "model": "don_confiao.product", | ||||
|     "pk": 1, | ||||
|     "fields": { | ||||
|       "name": "Papaya", | ||||
|       "price": 2500, | ||||
|       "measuring_unit": "Unidad" | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     "model": "don_confiao.sale", | ||||
|     "pk": 1, | ||||
|     "fields": { | ||||
|       "customer": 1, | ||||
|       "date": "2024-08-31", | ||||
|       "phone": 312201103, | ||||
|       "description": "Primera Venta" | ||||
|     } | ||||
|   }, | ||||
|     { | ||||
|         "model": "don_confiao.saleline", | ||||
|         "pk": 1, | ||||
|         "fields": { | ||||
|             "sale": 1, | ||||
|             "product": 1, | ||||
|             "quantity": 10, | ||||
|             "unit_price": 5000, | ||||
|             "description": "Primer Sale Line" | ||||
|         } | ||||
|     } | ||||
| ] | ||||
							
								
								
									
										50
									
								
								tienda_ilusion/don_confiao/tests/test_export_sales.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								tienda_ilusion/don_confiao/tests/test_export_sales.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| #!/usr/bin/env python3 | ||||
| from django.test import Client, TestCase | ||||
| from io import StringIO | ||||
| import csv | ||||
|  | ||||
|  | ||||
| class TestExportSales(TestCase): | ||||
|     fixtures = ['sales_fixture'] | ||||
|  | ||||
|     def setUp(self): | ||||
|         self.client = Client() | ||||
|  | ||||
|     def test_export_sales(self): | ||||
|         sales_response = self._export_sales_csv() | ||||
|         filename = sales_response.headers[ | ||||
|             'Content-Disposition'].split('; ')[1].strip('filename=').strip("'") | ||||
|         content = sales_response.content | ||||
|         content_str = content.decode('utf-8') | ||||
|         csv_file = StringIO(content_str) | ||||
|         header = next(csv.reader(csv_file)) | ||||
|  | ||||
|         self.assertGreater(len(content), 0) | ||||
|         self.assertEqual(filename, 'sales.csv') | ||||
|         self.assertEqual(sales_response.headers['Content-Type'], 'text/csv') | ||||
|         self.assertEqual(header, self._tryton_sale_header()) | ||||
|  | ||||
|     def _export_sales_csv(self): | ||||
|         return self.client.get("/don_confiao/exportar_ventas_para_tryton") | ||||
|  | ||||
|     def _tryton_sale_header(self): | ||||
|         return [ | ||||
|             "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" | ||||
|                 ] | ||||
		Reference in New Issue
	
	Block a user