feat(buy): send products list to buy view.
This commit is contained in:
parent
23ec2bc298
commit
f1d96467d6
@ -1,6 +1,9 @@
|
||||
{% extends 'don_confiao/base.html' %}
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<script>
|
||||
let listProducts = JSON.parse("{{ list_products|escapejs }}");
|
||||
</script>
|
||||
<div class="flex h-full">
|
||||
<div class="h-full w-10/12 flex flex-col p-5">
|
||||
<form id="complete_form_purchase" method="POST" class="h-10/12 w-full max-h-full overflow-auto">
|
||||
@ -15,7 +18,6 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</form>
|
||||
<div class="h-2/12 flex justify-center">
|
||||
<button id="add_line" type="button" class="bg-yellow-400 shadow hover:shadow-lg py-2 px-5 rounded-full font-bold hover:bg-violet-200 ease-in duration-150" onclick="add_line">Añadir Linea</button>
|
||||
</div>
|
||||
@ -26,6 +28,7 @@
|
||||
{{ summary_form }}
|
||||
<button class="font-bold my-10 py-2 px-4 rounded-full bg-yellow-400 shadow hover:shadow-lg hover:bg-violet-200 ease-in duration-150" name="form" type="submit" >Comprar</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.tailwindcss.com/"></script>
|
||||
|
22
tienda_ilusion/don_confiao/tests/test_buy_form.py
Normal file
22
tienda_ilusion/don_confiao/tests/test_buy_form.py
Normal file
@ -0,0 +1,22 @@
|
||||
from django.test import Client, TestCase
|
||||
from ..models import Product
|
||||
|
||||
|
||||
class TestBuyForm(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
self.product = Product()
|
||||
self.product.name = "Arroz"
|
||||
self.product.price = 5000
|
||||
self.product.save()
|
||||
|
||||
def test_buy_contains_products_list(self):
|
||||
response = self.client.get('/don_confiao/comprar')
|
||||
self.assertIn(
|
||||
self.product.name,
|
||||
response.context['list_products']
|
||||
)
|
||||
content = response.content.decode('utf-8')
|
||||
self.assertIn('5000', content)
|
||||
self.assertIn('Arroz', content)
|
||||
self.assertIn(str(self.product.id), content)
|
@ -8,8 +8,16 @@ from .forms import ImportProductsForm, PurchaseForm, SaleLineFormSet, Reconcilia
|
||||
|
||||
import csv
|
||||
import io
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class DecimalEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
def index(request):
|
||||
return render(request, 'don_confiao/index.html')
|
||||
|
||||
@ -47,6 +55,7 @@ def buy(request):
|
||||
'sale_form': sale_form,
|
||||
'linea_formset': line_formset,
|
||||
'summary_form': sale_summary_form,
|
||||
'list_products': json.dumps(Product.to_list(), cls=DecimalEncoder),
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user