refactor(views): extract to method.
This commit is contained in:
		| @@ -163,8 +163,7 @@ def handle_import_customers_file(csv_file): | ||||
|             } | ||||
|         ) | ||||
|  | ||||
|  | ||||
| def exportar_ventas_para_tryton(request): | ||||
| def _sales_to_tryton_csv(sales): | ||||
|     tryton_sales_header = [ | ||||
|         "Tercero", | ||||
|         "Dirección de facturación", | ||||
| @@ -186,14 +185,7 @@ def exportar_ventas_para_tryton(request): | ||||
|         "Comentario" | ||||
|     ] | ||||
|  | ||||
|     if request.method == "GET": | ||||
|         response = HttpResponse(content_type='text/csv') | ||||
|         response['Content-Disposition'] = "attachment; filename=sales.csv" | ||||
|         writer = csv.writer(response) | ||||
|         writer.writerow(tryton_sales_header) | ||||
|  | ||||
|         sales = Sale.objects.all() | ||||
|  | ||||
|     csv_data = [tryton_sales_header] | ||||
|     for sale in sales: | ||||
|         sale_lines = SaleLine.objects.filter(sale=sale.id) | ||||
|         if not sale_lines: | ||||
| @@ -223,6 +215,19 @@ def exportar_ventas_para_tryton(request): | ||||
|                 line.unit_price, | ||||
|                 "Unidad"]+[""]*5) | ||||
|         for row in lines: | ||||
|             csv_data.append(row) | ||||
|  | ||||
|     return csv_data | ||||
|  | ||||
|  | ||||
| def exportar_ventas_para_tryton(request): | ||||
|     if request.method == "GET": | ||||
|         response = HttpResponse(content_type='text/csv') | ||||
|         response['Content-Disposition'] = "attachment; filename=sales.csv" | ||||
|         sales = Sale.objects.all() | ||||
|         csv_data = _sales_to_tryton_csv(sales) | ||||
|         writer = csv.writer(response) | ||||
|         for row in csv_data: | ||||
|             writer.writerow(row) | ||||
|  | ||||
|         return response | ||||
|   | ||||
		Reference in New Issue
	
	Block a user