Exportando ventas para tryton desde api #4
@ -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,44 +185,50 @@ def exportar_ventas_para_tryton(request):
|
||||
"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":
|
||||
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()
|
||||
|
||||
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:
|
||||
writer.writerow(row)
|
||||
csv_data = _sales_to_tryton_csv(sales)
|
||||
writer = csv.writer(response)
|
||||
for row in csv_data:
|
||||
writer.writerow(row)
|
||||
|
||||
return response
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user