Import Customers
This commit is contained in:
@@ -4,9 +4,10 @@ from django.views.generic import ListView
|
||||
from django.db import transaction
|
||||
|
||||
from .models import (
|
||||
Sale, SaleLine, Product, ProductCategory, Payment, PaymentMethods)
|
||||
Sale, SaleLine, Product, Customer, ProductCategory, Payment, PaymentMethods)
|
||||
from .forms import (
|
||||
ImportProductsForm,
|
||||
ImportCustomersForm,
|
||||
PurchaseForm,
|
||||
SaleLineFormSet,
|
||||
ReconciliationJarForm,
|
||||
@@ -94,6 +95,19 @@ def import_products(request):
|
||||
{'form': form}
|
||||
)
|
||||
|
||||
def import_customers(request):
|
||||
if request.method == "POST":
|
||||
form = ImportCustomersForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
handle_import_customers_file(request.FILES["csv_file"])
|
||||
return HttpResponseRedirect("productos")
|
||||
else:
|
||||
form = ImportCustomersForm()
|
||||
return render(
|
||||
request,
|
||||
"don_confiao/import_customers.html",
|
||||
{'form': form}
|
||||
)
|
||||
|
||||
def reconciliate_jar(request):
|
||||
summary = Payment.get_reconciliation_jar_summary()
|
||||
@@ -154,6 +168,18 @@ def handle_import_products_file(csv_file):
|
||||
for category in categories:
|
||||
product.categories.add(category)
|
||||
|
||||
def handle_import_customers_file(csv_file):
|
||||
data = io.StringIO(csv_file.read().decode('utf-8'))
|
||||
reader = csv.DictReader(data, quotechar='"')
|
||||
for row in reader:
|
||||
customer, created = Customer.objects.update_or_create(
|
||||
name=row['nombre'],
|
||||
defaults={
|
||||
'email': row['correo'],
|
||||
'phone': row['telefono']
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def exportar_ventas_para_tryton(request):
|
||||
tryton_sales_header = [
|
||||
|
||||
Reference in New Issue
Block a user