Feat: Export Ventas Para Tryton
This commit is contained in:
@@ -3,8 +3,14 @@ from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.views.generic import ListView
|
||||
from django.db import transaction
|
||||
|
||||
from .models import Sale, Product, ProductCategory, Payment, PaymentMethods
|
||||
from .forms import ImportProductsForm, PurchaseForm, SaleLineFormSet, ReconciliationJarForm, PurchaseSummaryForm
|
||||
from .models import (
|
||||
Sale, SaleLine, Product, ProductCategory, Payment, PaymentMethods)
|
||||
from .forms import (
|
||||
ImportProductsForm,
|
||||
PurchaseForm,
|
||||
SaleLineFormSet,
|
||||
ReconciliationJarForm,
|
||||
PurchaseSummaryForm)
|
||||
|
||||
import csv
|
||||
import io
|
||||
@@ -18,9 +24,11 @@ class DecimalEncoder(json.JSONEncoder):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, 'don_confiao/index.html')
|
||||
|
||||
|
||||
def buy(request):
|
||||
if request.method == "POST":
|
||||
sale_form = PurchaseForm(request.POST)
|
||||
@@ -115,10 +123,11 @@ def purchase_summary(request, id):
|
||||
request,
|
||||
"don_confiao/purchase_summary.html",
|
||||
{
|
||||
"purchase" : purchase
|
||||
"purchase": purchase
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _categories_from_csv_string(categories_string, separator="&"):
|
||||
categories = categories_string.split(separator)
|
||||
clean_categories = [c.strip() for c in categories]
|
||||
@@ -146,6 +155,70 @@ def handle_import_products_file(csv_file):
|
||||
product.categories.add(category)
|
||||
|
||||
|
||||
def exportar_ventas_para_tryton(request):
|
||||
tryton_sales_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"
|
||||
]
|
||||
|
||||
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,
|
||||
"Unidad",
|
||||
first_sale_line.unit_price,
|
||||
"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
|
||||
|
||||
|
||||
class ProductListView(ListView):
|
||||
model = Product
|
||||
template_model = 'don_confiao/product_list.html'
|
||||
|
||||
Reference in New Issue
Block a user