Merge pull request 'Importación de clientes por CSV' (#56) from import_customers into main
Reviewed-on: OneTeam/don_confiao#56
This commit is contained in:
commit
95fab71898
4
tienda_ilusion/don_confiao/example_customer.csv
Normal file
4
tienda_ilusion/don_confiao/example_customer.csv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
nombre,correo,telefono
|
||||||
|
Alejandro Ayala,mono@disroot.org,3232321
|
||||||
|
Mono Francisco,pablo@onecluster.org,321312312
|
||||||
|
Pablo Bolivar,alejo@onecluster.org,3243242
|
|
@ -12,6 +12,10 @@ class ImportProductsForm(forms.Form):
|
|||||||
csv_file = forms.FileField()
|
csv_file = forms.FileField()
|
||||||
|
|
||||||
|
|
||||||
|
class ImportCustomersForm(forms.Form):
|
||||||
|
csv_file = forms.FileField()
|
||||||
|
|
||||||
|
|
||||||
class PurchaseForm(forms.ModelForm):
|
class PurchaseForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Sale
|
model = Sale
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-10-26 22:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('don_confiao', '0030_paymentsale'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='customer',
|
||||||
|
old_name='address',
|
||||||
|
new_name='email',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='customer',
|
||||||
|
name='phone',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-10-26 22:21
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('don_confiao', '0031_rename_address_customer_email_customer_phone'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='customer',
|
||||||
|
name='address',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -9,6 +9,8 @@ from datetime import datetime
|
|||||||
class Customer(models.Model):
|
class Customer(models.Model):
|
||||||
name = models.CharField(max_length=100, default=None, null=False, blank=False)
|
name = models.CharField(max_length=100, default=None, null=False, blank=False)
|
||||||
address = models.CharField(max_length=100, null=True, blank=True)
|
address = models.CharField(max_length=100, null=True, blank=True)
|
||||||
|
email = models.CharField(max_length=100, null=True, blank=True)
|
||||||
|
phone = models.CharField(max_length=100, null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
{% extends 'don_confiao/base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
{% if form.is_multipart %}
|
||||||
|
<form enctype="multipart/form-data" method="post">
|
||||||
|
{% else %}
|
||||||
|
<form method="post">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
|
<input type="submit" value="Importar">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -4,4 +4,5 @@
|
|||||||
<li><a href='./comprar'>Comprar</a></li>
|
<li><a href='./comprar'>Comprar</a></li>
|
||||||
<li><a href='./productos'>Productos</a></li>
|
<li><a href='./productos'>Productos</a></li>
|
||||||
<li><a href='./importar_productos'>Importar Productos</a></li>
|
<li><a href='./importar_productos'>Importar Productos</a></li>
|
||||||
|
<li><a href='./importar_terceros'>Importar Terceros</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<li><a href='/don_confiao/compras'>Compras</a></li>
|
<li><a href='/don_confiao/compras'>Compras</a></li>
|
||||||
<li><a href='/don_confiao/lista_productos'>Productos</a></li>
|
<li><a href='/don_confiao/lista_productos'>Productos</a></li>
|
||||||
<li><a href='/don_confiao/importar_productos'>Importar Productos</a></li>
|
<li><a href='/don_confiao/importar_productos'>Importar Productos</a></li>
|
||||||
|
<li><a href='/don_confiao/importar_terceros'>Importar Terceros</a></li>
|
||||||
<li><a href='/don_confiao/cuadrar_tarro'>Cuadrar tarro</a></li>
|
<li><a href='/don_confiao/cuadrar_tarro'>Cuadrar tarro</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -19,6 +19,7 @@ urlpatterns = [
|
|||||||
path("productos", views.products, name="products"),
|
path("productos", views.products, name="products"),
|
||||||
path("lista_productos", views.ProductListView.as_view(), name='product_list'),
|
path("lista_productos", views.ProductListView.as_view(), name='product_list'),
|
||||||
path("importar_productos", views.import_products, name="import_products"),
|
path("importar_productos", views.import_products, name="import_products"),
|
||||||
|
path("importar_terceros", views.import_customers, name="import_customers"),
|
||||||
path("exportar_ventas_para_tryton",
|
path("exportar_ventas_para_tryton",
|
||||||
views.exportar_ventas_para_tryton,
|
views.exportar_ventas_para_tryton,
|
||||||
name="exportar_ventas_para_tryton"),
|
name="exportar_ventas_para_tryton"),
|
||||||
|
@ -4,9 +4,10 @@ from django.views.generic import ListView
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Sale, SaleLine, Product, ProductCategory, Payment, PaymentMethods)
|
Sale, SaleLine, Product, Customer, ProductCategory, Payment, PaymentMethods)
|
||||||
from .forms import (
|
from .forms import (
|
||||||
ImportProductsForm,
|
ImportProductsForm,
|
||||||
|
ImportCustomersForm,
|
||||||
PurchaseForm,
|
PurchaseForm,
|
||||||
SaleLineFormSet,
|
SaleLineFormSet,
|
||||||
ReconciliationJarForm,
|
ReconciliationJarForm,
|
||||||
@ -94,6 +95,19 @@ def import_products(request):
|
|||||||
{'form': form}
|
{'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):
|
def reconciliate_jar(request):
|
||||||
summary = Payment.get_reconciliation_jar_summary()
|
summary = Payment.get_reconciliation_jar_summary()
|
||||||
@ -154,6 +168,18 @@ def handle_import_products_file(csv_file):
|
|||||||
for category in categories:
|
for category in categories:
|
||||||
product.categories.add(category)
|
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):
|
def exportar_ventas_para_tryton(request):
|
||||||
tryton_sales_header = [
|
tryton_sales_header = [
|
||||||
|
Loading…
Reference in New Issue
Block a user