Fix: Clean Home, Crear lineas de Venta
This commit is contained in:
parent
5879296132
commit
02fba454ba
@ -7,6 +7,7 @@ from .models import Sale, SaleLine, ReconciliationJar
|
||||
class ImportProductsForm(forms.Form):
|
||||
csv_file = forms.FileField()
|
||||
|
||||
|
||||
class PurchaseForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Sale
|
||||
@ -20,6 +21,7 @@ class PurchaseForm(forms.ModelForm):
|
||||
'date': DateInput(attrs={'type': 'date'})
|
||||
}
|
||||
|
||||
|
||||
class PurchaseLineForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = SaleLine
|
||||
|
@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class Sale(models.Model):
|
||||
|
||||
customer = models.CharField(max_length=100)
|
||||
|
1
tienda_ilusion/don_confiao/tests/__init__.py
Normal file
1
tienda_ilusion/don_confiao/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
#!/usr/bin/env python3
|
@ -1,13 +1,11 @@
|
||||
from django.test import Client, TestCase
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.conf import settings
|
||||
|
||||
from .views import import_products, products
|
||||
from .models import ProductCategory, Product
|
||||
from ..models import ProductCategory, Product
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
class TestProducts(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
@ -54,7 +52,8 @@ class TestProducts(TestCase):
|
||||
first_categories = {p["name"]: p["categories"] for p in first_products}
|
||||
self._import_csv('example_products2.csv')
|
||||
updated_products = self._get_products()
|
||||
updated_categories = {p["name"]: p["categories"] for p in updated_products}
|
||||
updated_categories = {
|
||||
p["name"]: p["categories"] for p in updated_products}
|
||||
|
||||
self.assertIn('Cafes', first_categories['Arroz'])
|
||||
self.assertNotIn('Granos', first_categories['Arroz'])
|
||||
@ -62,7 +61,6 @@ class TestProducts(TestCase):
|
||||
self.assertIn('Granos', updated_categories['Arroz'])
|
||||
self.assertNotIn('Cafes', updated_categories['Arroz'])
|
||||
|
||||
|
||||
def test_update_price(self):
|
||||
self._import_csv()
|
||||
first_products = self._get_products()
|
@ -1,5 +1,5 @@
|
||||
from django.test import TestCase
|
||||
from .models import Sale, SaleLine
|
||||
from ..models import Sale, SaleLine
|
||||
|
||||
|
||||
class ConfiaoTest(TestCase):
|
@ -1,6 +1,7 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.template import loader
|
||||
#from django.template import loader
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .models import Sale, Product, ProductCategory, Payment
|
||||
@ -9,18 +10,22 @@ from .forms import ImportProductsForm, PurchaseForm, LineaFormSet, Reconciliatio
|
||||
import csv
|
||||
import io
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, 'don_confiao/index.html')
|
||||
|
||||
|
||||
def buy(request):
|
||||
if request.method == "POST":
|
||||
sale_form = PurchaseForm(request.POST)
|
||||
sale_linea_form = LineaFormSet(request.POST)
|
||||
if sale_form.is_valid():
|
||||
sale_form.save()
|
||||
if sale_linea_form.is_valid():
|
||||
sale_linea_form.save()
|
||||
return HttpResponseRedirect("productos")
|
||||
if sale_form.is_valid() and sale_linea_form.is_valid():
|
||||
sale = sale_form.save()
|
||||
lines = sale_linea_form.save(commit=False)
|
||||
for line in lines:
|
||||
line.sale = sale
|
||||
line.save()
|
||||
return HttpResponseRedirect("compras")
|
||||
else:
|
||||
sale_form = PurchaseForm()
|
||||
sale_linea_form = LineaFormSet()
|
||||
@ -33,6 +38,7 @@ def buy(request):
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def purchases(request):
|
||||
purchases = Sale.objects.all()
|
||||
context = {
|
||||
@ -89,6 +95,7 @@ def reconciliate_jar(request):
|
||||
{'summary': summary, 'form': form}
|
||||
)
|
||||
|
||||
|
||||
def reconciliations(request):
|
||||
return HttpResponse('<h1>Reconciliaciones</h1>')
|
||||
|
||||
@ -98,9 +105,11 @@ def _categories_from_csv_string(categories_string, separator="&"):
|
||||
clean_categories = [c.strip() for c in categories]
|
||||
return [_category_from_name(category) for category in clean_categories]
|
||||
|
||||
|
||||
def _category_from_name(name):
|
||||
return ProductCategory.objects.get_or_create(name=name)[0]
|
||||
|
||||
|
||||
def handle_import_products_file(csv_file):
|
||||
data = io.StringIO(csv_file.read().decode('utf-8'))
|
||||
reader = csv.DictReader(data, quotechar='"')
|
||||
|
Loading…
Reference in New Issue
Block a user