Compare commits
11 Commits
add_self_p
...
f3d3681bc4
| Author | SHA1 | Date | |
|---|---|---|---|
| f3d3681bc4 | |||
| e6d2160d2e | |||
| f323873d80 | |||
| b730d24855 | |||
| 6261d64206 | |||
| 64f07a2ce2 | |||
| 308e2d08c1 | |||
| e1ff427856 | |||
| bf70c47551 | |||
| f02f754ae7 | |||
| 1668a37091 |
@@ -38,10 +38,12 @@ class SaleView(viewsets.ModelViewSet):
|
||||
date = data['date']
|
||||
lines = data['saleline_set']
|
||||
payment_method = data['payment_method']
|
||||
description = data.get('notes', '')
|
||||
sale = Sale.objects.create(
|
||||
customer=customer,
|
||||
date=date,
|
||||
payment_method=payment_method
|
||||
payment_method=payment_method,
|
||||
description=description
|
||||
)
|
||||
|
||||
for line in lines:
|
||||
@@ -97,7 +99,8 @@ class ReconciliateJarView(APIView):
|
||||
|
||||
def _is_valid_total(self, purchases, total):
|
||||
calculated_total = sum(p.get_total() for p in purchases)
|
||||
return calculated_total == Decimal(total)
|
||||
return Decimal(calculated_total).quantize(Decimal('.0001')) == (
|
||||
Decimal(total).quantize(Decimal('.0001')))
|
||||
|
||||
def _get_other_purchases(self, other_totals):
|
||||
if not other_totals:
|
||||
@@ -233,7 +236,10 @@ class TrytonSale:
|
||||
"shipment_address": self.sale.customer.address_external_id,
|
||||
"invoice_address": self.sale.customer.address_external_id,
|
||||
"currency": TRYTON_COP_CURRENCY,
|
||||
"description": self.sale.description or '',
|
||||
"comment": self.sale.description or '',
|
||||
"description": "Metodo pago: " + str(
|
||||
self.sale.payment_method or ''
|
||||
),
|
||||
"party": self.sale.customer.external_id,
|
||||
"reference": "don_confiao " + str(self.sale.id),
|
||||
"sale_date": self._format_date(self.sale.date),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.test import TestCase, Client
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from ..models import AdminCode
|
||||
|
||||
@@ -7,14 +8,18 @@ import json
|
||||
|
||||
class TestAdminCode(TestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
self.valid_code = 'some valid code'
|
||||
admin_code = AdminCode()
|
||||
admin_code.value = self.valid_code
|
||||
admin_code.clean()
|
||||
admin_code.save()
|
||||
|
||||
self.client = Client()
|
||||
|
||||
def test_validate_code(self):
|
||||
url = '/don_confiao/api/admin_code/validate/' + self.valid_code
|
||||
response = self.client.get(url)
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
import csv
|
||||
import io
|
||||
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
from ..models import Sale, Product, Customer
|
||||
@@ -10,6 +10,12 @@ from ..models import Sale, Product, Customer
|
||||
|
||||
class TestAPI(APITestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
self.product = Product.objects.create(
|
||||
name='Panela',
|
||||
price=5000,
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from ..models import Customer
|
||||
|
||||
|
||||
class TestCustomersFromTryton(TestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
self.customer = Customer.objects.create(
|
||||
name='Calos',
|
||||
external_id=5
|
||||
|
||||
@@ -2,13 +2,20 @@ import csv
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from ..models import Sale, SaleLine, Product, Customer
|
||||
|
||||
|
||||
class TestExportarVentasParaTryton(TestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
self.product = Product.objects.create(
|
||||
name='Panela',
|
||||
price=5000,
|
||||
@@ -25,6 +32,7 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
customer=self.customer,
|
||||
date='2024-09-02',
|
||||
payment_method='CASH',
|
||||
description='un comentario'
|
||||
)
|
||||
self.sale_line1 = SaleLine.objects.create(
|
||||
product=self.product,
|
||||
@@ -40,9 +48,8 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
)
|
||||
|
||||
def test_exportar_ventas_para_tryton(self):
|
||||
client = Client()
|
||||
url = '/don_confiao/exportar_ventas_para_tryton'
|
||||
response = client.get(url)
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response['Content-Type'], 'text/csv')
|
||||
csv_content = response.content.decode('utf-8')
|
||||
@@ -71,7 +78,7 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
self.assertEqual(next(csv_reader), expected_header)
|
||||
|
||||
expected_rows = [
|
||||
["Camilo", "Camilo", "Camilo", "", "", "2024-09-02", "Contado", "Almacén", "Peso colombiano", "Panela", "2.00", "3000.00", "Unidad", "TIENDA LA ILUSIÓN", "Tienda La Ilusion", "La Ilusion", "True", ""],
|
||||
["Camilo", "Camilo", "Camilo", "un comentario", "un comentario", "2024-09-02", "Contado", "Almacén", "Peso colombiano", "Panela", "2.00", "3000.00", "Unidad", "TIENDA LA ILUSIÓN", "Tienda La Ilusion", "La Ilusion", "True", "un comentario"],
|
||||
["", "", "", "", "", "", "", "", "", "Panela", "3.00", "5000.00", "Unidad", "", "", "", "", ""],
|
||||
]
|
||||
csv_rows = list(csv_reader)
|
||||
@@ -81,12 +88,11 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.call')
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
||||
def test_send_sales_to_tryton(self, mock_connect, mock_call):
|
||||
client = Client()
|
||||
external_id = '23423'
|
||||
url = '/don_confiao/api/enviar_ventas_a_tryton'
|
||||
mock_connect.return_value = None
|
||||
mock_call.return_value = [external_id]
|
||||
response = client.post(url)
|
||||
response = self.client.post(url)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
content = json.loads(response.content.decode('utf-8'))
|
||||
@@ -100,4 +106,4 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
self.assertEqual(updated_sale.external_id, external_id)
|
||||
mock_connect.assert_called_once()
|
||||
mock_call.assert_called_once()
|
||||
mock_call.assert_called_with('model.sale.sale.create', [[{'company': 1, 'shipment_address': '307', 'invoice_address': '307', 'currency': 31, 'description': '', 'party': '1', 'reference': 'don_confiao 1', 'sale_date': {'__class__': 'date', 'year': 2024, 'month': 9, 'day': 2}, 'lines': [['create', [{'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '2.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '3000.00'}}, {'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '3.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '5000.00'}}]]], 'self_pick_up': True}], {'company': 1, 'shops': [1]}])
|
||||
mock_call.assert_called_with('model.sale.sale.create', [[{'company': 1, 'shipment_address': '307', 'invoice_address': '307', 'currency': 31, 'comment': 'un comentario', 'description': 'Metodo pago: CASH', 'party': '1', 'reference': 'don_confiao 1', 'sale_date': {'__class__': 'date', 'year': 2024, 'month': 9, 'day': 2}, 'lines': [['create', [{'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '2.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '3000.00'}}, {'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '3.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '5000.00'}}]]], 'self_pick_up': True}], {'company': 1, 'shops': [1]}])
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.test import TestCase, Client
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from django.core.exceptions import ValidationError
|
||||
from ..models import Sale, Product, SaleLine, Customer, ReconciliationJar
|
||||
|
||||
@@ -7,12 +8,16 @@ import json
|
||||
|
||||
class TestJarReconcliation(TestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
customer = Customer()
|
||||
customer.name = 'Alejo Mono'
|
||||
customer.save()
|
||||
|
||||
self.client = Client()
|
||||
|
||||
purchase = Sale()
|
||||
purchase.customer = customer
|
||||
purchase.date = "2024-07-30"
|
||||
@@ -235,6 +240,47 @@ class TestJarReconcliation(TestCase):
|
||||
[sale['payment_method'] for sale in content['Sales']]
|
||||
)
|
||||
|
||||
def test_create_reconciliation_with_decimal_on_sale_lines(self):
|
||||
customer = Customer()
|
||||
customer.name = 'Consumidor final'
|
||||
customer.save()
|
||||
|
||||
product = Product()
|
||||
product.name = "Mantequilla natural gramos"
|
||||
product.price = "57.50"
|
||||
product.save()
|
||||
|
||||
purchase = Sale()
|
||||
purchase.customer = customer
|
||||
purchase.date = "2024-07-30"
|
||||
purchase.payment_method = 'CASH'
|
||||
purchase.clean()
|
||||
purchase.save()
|
||||
|
||||
line = SaleLine()
|
||||
line.sale = purchase
|
||||
line.product = product
|
||||
line.quantity = "0.24"
|
||||
line.unit_price = "57.50"
|
||||
line.save()
|
||||
|
||||
url = '/don_confiao/reconciliate_jar'
|
||||
total_purchases = 13.80
|
||||
data = {
|
||||
'date_time': '2024-12-02T21:07',
|
||||
'reconcilier': 'carlos',
|
||||
'total_cash_purchases': total_purchases,
|
||||
'cash_taken': total_purchases,
|
||||
'cash_discrepancy': 0,
|
||||
'cash_purchases': [purchase.id],
|
||||
}
|
||||
response = self.client.post(
|
||||
url, data=json.dumps(data).encode('utf-8'),
|
||||
content_type='application/json'
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
def _create_simple_reconciliation(self):
|
||||
reconciliation = ReconciliationJar()
|
||||
reconciliation.date_time = "2024-07-30"
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
from django.test import Client, TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
# from ..models import PaymentMethods
|
||||
|
||||
class TestPaymentMethods(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
def test_keys_in_payment_methods_to_select(self):
|
||||
response = self.client.get(
|
||||
|
||||
@@ -2,12 +2,18 @@ import json
|
||||
from decimal import Decimal
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from ..models import ProductCategory, Product
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from ..models import Product
|
||||
|
||||
|
||||
class TestProductsFromTryton(TestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
self.product = Product.objects.create(
|
||||
name='Panela',
|
||||
price=5000,
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
from django.test import TestCase, Client
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from ..models import Sale, Product, SaleLine, Customer
|
||||
|
||||
|
||||
class TestSummaryViewPurchase(TestCase):
|
||||
def setUp(self):
|
||||
username = 'nombre_usuario'
|
||||
password = 'contraseña'
|
||||
email = 'correo@example.com'
|
||||
self.user = User.objects.create_user(username, email, password)
|
||||
self.client.login(username=username, password=password)
|
||||
|
||||
customer = Customer()
|
||||
customer.name = 'Alejo Mono'
|
||||
customer.save()
|
||||
|
||||
self.client = Client()
|
||||
purchase = Sale()
|
||||
purchase.customer = customer
|
||||
purchase.date = "2024-07-30"
|
||||
|
||||
@@ -65,7 +65,7 @@ ROOT_URLCONF = 'tienda_ilusion.urls'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'DIRS': [os.path.join(BASE_DIR, 'tienda_ilusion/templates')],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
@@ -134,3 +134,14 @@ STATIC_URL = 'static/'
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
FIXTURE_DIRS = ['don_confiao/tests/Fixtures']
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
],
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
],
|
||||
}
|
||||
|
||||
LOGOUT_REDIRECT_URL = '/start/'
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Iniciar sesión</button>
|
||||
</form>
|
||||
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Perfil de usuario</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<h1>Perfil de usuario</h1>
|
||||
<p>Nombre de usuario: {{ user.username }}</p>
|
||||
<p>Email: {{ user.email }}</p>
|
||||
<form action="{% url 'logout' %}" method="post" style="display: inline-block;">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-danger">Cerrar sesión</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
22
tienda_ilusion/tienda_ilusion/templates/start.html
Normal file
22
tienda_ilusion/tienda_ilusion/templates/start.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bienvenido a la tienda la ilusión</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<h1>Bienvenido a la tienda la ilusion</h1>
|
||||
|
||||
<a href="{% url 'login' %}">Login</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -16,11 +16,15 @@ Including another URLconf
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from . import views
|
||||
|
||||
|
||||
app_name = "don_confiao"
|
||||
|
||||
urlpatterns = [
|
||||
path("don_confiao/", include("don_confiao.urls")),
|
||||
path("accounts/", include("django.contrib.auth.urls")),
|
||||
path('accounts/profile/', views.ProfileView.as_view(), name='profile'),
|
||||
path('start/', views.StartView.as_view(), name='start'),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
15
tienda_ilusion/tienda_ilusion/views.py
Normal file
15
tienda_ilusion/tienda_ilusion/views.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.views.generic import TemplateView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
|
||||
class ProfileView(LoginRequiredMixin, TemplateView):
|
||||
template_name = 'registration/profile.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['user'] = self.request.user
|
||||
return context
|
||||
|
||||
|
||||
class StartView(TemplateView):
|
||||
template_name = 'start.html'
|
||||
Reference in New Issue
Block a user