refactor(views): extract to method.
This commit is contained in:
parent
585d92c64c
commit
2364583952
@ -163,8 +163,7 @@ def handle_import_customers_file(csv_file):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _sales_to_tryton_csv(sales):
|
||||||
def exportar_ventas_para_tryton(request):
|
|
||||||
tryton_sales_header = [
|
tryton_sales_header = [
|
||||||
"Tercero",
|
"Tercero",
|
||||||
"Dirección de facturación",
|
"Dirección de facturación",
|
||||||
@ -186,44 +185,50 @@ def exportar_ventas_para_tryton(request):
|
|||||||
"Comentario"
|
"Comentario"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
csv_data = [tryton_sales_header]
|
||||||
|
for sale in sales:
|
||||||
|
sale_lines = SaleLine.objects.filter(sale=sale.id)
|
||||||
|
if not sale_lines:
|
||||||
|
continue
|
||||||
|
lines = []
|
||||||
|
first_sale_line = sale_lines[0]
|
||||||
|
customer_info = [sale.customer.name] * 3 + [sale.description] * 2
|
||||||
|
first_line = customer_info + [
|
||||||
|
sale.date,
|
||||||
|
"Contado",
|
||||||
|
"Almacén",
|
||||||
|
"Peso colombiano",
|
||||||
|
first_sale_line.product.name,
|
||||||
|
first_sale_line.quantity,
|
||||||
|
first_sale_line.unit_price,
|
||||||
|
"Unidad",
|
||||||
|
"TIENDA LA ILUSIÓN",
|
||||||
|
"Tienda La Ilusion",
|
||||||
|
"La Ilusion",
|
||||||
|
True,
|
||||||
|
sale.description]
|
||||||
|
lines.append(first_line)
|
||||||
|
for line in sale_lines[1:]:
|
||||||
|
lines.append([""]*9+[
|
||||||
|
line.product.name,
|
||||||
|
line.quantity,
|
||||||
|
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":
|
if request.method == "GET":
|
||||||
response = HttpResponse(content_type='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
response['Content-Disposition'] = "attachment; filename=sales.csv"
|
response['Content-Disposition'] = "attachment; filename=sales.csv"
|
||||||
writer = csv.writer(response)
|
|
||||||
writer.writerow(tryton_sales_header)
|
|
||||||
|
|
||||||
sales = Sale.objects.all()
|
sales = Sale.objects.all()
|
||||||
|
csv_data = _sales_to_tryton_csv(sales)
|
||||||
for sale in sales:
|
writer = csv.writer(response)
|
||||||
sale_lines = SaleLine.objects.filter(sale=sale.id)
|
for row in csv_data:
|
||||||
if not sale_lines:
|
writer.writerow(row)
|
||||||
continue
|
|
||||||
lines = []
|
|
||||||
first_sale_line = sale_lines[0]
|
|
||||||
customer_info = [sale.customer.name] * 3 + [sale.description] * 2
|
|
||||||
first_line = customer_info + [
|
|
||||||
sale.date,
|
|
||||||
"Contado",
|
|
||||||
"Almacén",
|
|
||||||
"Peso colombiano",
|
|
||||||
first_sale_line.product.name,
|
|
||||||
first_sale_line.quantity,
|
|
||||||
first_sale_line.unit_price,
|
|
||||||
"Unidad",
|
|
||||||
"TIENDA LA ILUSIÓN",
|
|
||||||
"Tienda La Ilusion",
|
|
||||||
"La Ilusion",
|
|
||||||
True,
|
|
||||||
sale.description]
|
|
||||||
lines.append(first_line)
|
|
||||||
for line in sale_lines[1:]:
|
|
||||||
lines.append([""]*9+[
|
|
||||||
line.product.name,
|
|
||||||
line.quantity,
|
|
||||||
line.unit_price,
|
|
||||||
"Unidad"]+[""]*5)
|
|
||||||
for row in lines:
|
|
||||||
writer.writerow(row)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user