[REF] Code quality improvements and structure fixes
- Add mypy.ini configuration to exclude migration scripts - Rename migration files to proper snake_case (post-migration.py → post_migration.py) - Add __init__.py to migration directories for proper Python package structure - Add new portal access tests for website_sale_aplicoop - Code formatting improvements (black, isort) - Update copilot instructions and project configuration Related to previous code quality refactoring work.
This commit is contained in:
parent
380d05785f
commit
cf9ea887c1
30 changed files with 1129 additions and 1102 deletions
124
test_prices.py
124
test_prices.py
|
|
@ -4,15 +4,18 @@ Script de prueba para verificar que los precios incluyen impuestos.
|
|||
Se ejecuta dentro del contenedor de Odoo.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Agregar path de Odoo
|
||||
sys.path.insert(0, "/usr/lib/python3/dist-packages")
|
||||
|
||||
import odoo
|
||||
from odoo import SUPERUSER_ID
|
||||
from odoo import api
|
||||
import odoo # noqa: E402
|
||||
from odoo import SUPERUSER_ID # noqa: E402
|
||||
from odoo import api # noqa: E402
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Configurar Odoo
|
||||
odoo.tools.config["db_host"] = os.environ.get("HOST", "db")
|
||||
|
|
@ -20,9 +23,9 @@ odoo.tools.config["db_port"] = int(os.environ.get("PORT", 5432))
|
|||
odoo.tools.config["db_user"] = os.environ.get("USER", "odoo")
|
||||
odoo.tools.config["db_password"] = os.environ.get("PASSWORD", "odoo")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("TEST: Precios con impuestos incluidos")
|
||||
print("=" * 60 + "\n")
|
||||
logger.info("\n" + "=" * 60)
|
||||
logger.info("TEST: Precios con impuestos incluidos")
|
||||
logger.info("=" * 60 + "\n")
|
||||
|
||||
try:
|
||||
db_name = "odoo"
|
||||
|
|
@ -31,26 +34,26 @@ try:
|
|||
with registry.cursor() as cr:
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
print(f"✓ Conectado a BD: {db_name}")
|
||||
print(f" Usuario: {env.user.name}")
|
||||
print(f" Compañía: {env.company.name}\n")
|
||||
logger.info(f"✓ Conectado a BD: {db_name}")
|
||||
logger.info(f" Usuario: {env.user.name}")
|
||||
logger.info(f" Compañía: {env.company.name}\n")
|
||||
|
||||
# Test 1: Verificar módulo
|
||||
print("TEST 1: Verificar módulo instalado")
|
||||
print("-" * 60)
|
||||
logger.info("TEST 1: Verificar módulo instalado")
|
||||
logger.info("-" * 60)
|
||||
module = env["ir.module.module"].search(
|
||||
[("name", "=", "website_sale_aplicoop")], limit=1
|
||||
)
|
||||
|
||||
if module and module.state == "installed":
|
||||
print(f"✓ Módulo website_sale_aplicoop instalado")
|
||||
logger.info("✓ Módulo website_sale_aplicoop instalado")
|
||||
else:
|
||||
print(f"✗ Módulo NO instalado")
|
||||
logger.error("✗ Módulo NO instalado")
|
||||
sys.exit(1)
|
||||
|
||||
# Test 2: Verificar método nuevo
|
||||
print("\nTEST 2: Verificar método _compute_price_with_taxes")
|
||||
print("-" * 60)
|
||||
logger.info("\nTEST 2: Verificar método _compute_price_with_taxes")
|
||||
logger.info("-" * 60)
|
||||
try:
|
||||
from odoo.addons.website_sale_aplicoop.controllers.website_sale import (
|
||||
AplicoopWebsiteSale,
|
||||
|
|
@ -59,20 +62,20 @@ try:
|
|||
controller = AplicoopWebsiteSale()
|
||||
|
||||
if hasattr(controller, "_compute_price_with_taxes"):
|
||||
print("✓ Método _compute_price_with_taxes existe")
|
||||
logger.info("✓ Método _compute_price_with_taxes existe")
|
||||
|
||||
import inspect
|
||||
|
||||
sig = inspect.signature(controller._compute_price_with_taxes)
|
||||
print(f" Firma: {sig}")
|
||||
logger.info(f" Firma: {sig}")
|
||||
else:
|
||||
print("✗ Método NO encontrado")
|
||||
logger.error("✗ Método NO encontrado")
|
||||
except Exception as e:
|
||||
print(f"✗ Error: {e}")
|
||||
logger.exception("✗ Error verificando método: %s", e)
|
||||
|
||||
# Test 3: Probar cálculo de impuestos
|
||||
print("\nTEST 3: Calcular precio con impuestos")
|
||||
print("-" * 60)
|
||||
logger.info("\nTEST 3: Calcular precio con impuestos")
|
||||
logger.info("-" * 60)
|
||||
|
||||
# Buscar un producto con impuestos
|
||||
product = env["product.product"].search(
|
||||
|
|
@ -80,7 +83,7 @@ try:
|
|||
)
|
||||
|
||||
if not product:
|
||||
print(" Creando producto de prueba...")
|
||||
logger.info(" Creando producto de prueba...")
|
||||
|
||||
# Buscar impuesto existente
|
||||
tax = env["account.tax"].search(
|
||||
|
|
@ -97,19 +100,22 @@ try:
|
|||
"sale_ok": True,
|
||||
}
|
||||
)
|
||||
print(f" Producto creado: {product.name}")
|
||||
logger.info(f" Producto creado: {product.name}")
|
||||
else:
|
||||
print(" ✗ No hay impuestos de venta configurados")
|
||||
logger.error(" ✗ No hay impuestos de venta configurados")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(f" Producto encontrado: {product.name}")
|
||||
logger.info(f" Producto encontrado: {product.name}")
|
||||
|
||||
print(f" Precio de lista: {product.list_price:.2f} €")
|
||||
logger.info(f" Precio de lista: {product.list_price:.2f} €")
|
||||
|
||||
taxes = product.taxes_id.filtered(lambda t: t.company_id == env.company)
|
||||
|
||||
if taxes:
|
||||
print(f" Impuestos: {', '.join(f'{t.name} ({t.amount}%)' for t in taxes)}")
|
||||
logger.info(
|
||||
" Impuestos: %s",
|
||||
", ".join(f"{t.name} ({t.amount}%)" for t in taxes),
|
||||
)
|
||||
|
||||
# Calcular precio con impuestos
|
||||
base_price = product.list_price
|
||||
|
|
@ -124,24 +130,26 @@ try:
|
|||
price_with_tax = tax_result["total_included"]
|
||||
tax_amount = price_with_tax - price_without_tax
|
||||
|
||||
print(f"\n Cálculo:")
|
||||
print(f" Base: {base_price:.2f} €")
|
||||
print(f" Sin IVA: {price_without_tax:.2f} €")
|
||||
print(f" IVA: {tax_amount:.2f} €")
|
||||
print(f" CON IVA: {price_with_tax:.2f} €")
|
||||
logger.info("\n Cálculo:")
|
||||
logger.info(f" Base: {base_price:.2f} €")
|
||||
logger.info(f" Sin IVA: {price_without_tax:.2f} €")
|
||||
logger.info(f" IVA: {tax_amount:.2f} €")
|
||||
logger.info(f" CON IVA: {price_with_tax:.2f} €")
|
||||
|
||||
if price_with_tax > price_without_tax:
|
||||
print(
|
||||
f"\n ✓ PASADO: Precio con IVA ({price_with_tax:.2f}) > sin IVA ({price_without_tax:.2f})"
|
||||
logger.info(
|
||||
"\n ✓ PASADO: Precio con IVA (%.2f) > sin IVA (%.2f)",
|
||||
price_with_tax,
|
||||
price_without_tax,
|
||||
)
|
||||
else:
|
||||
print(f"\n ✗ FALLADO: Impuestos no se calculan correctamente")
|
||||
logger.error("\n ✗ FALLADO: Impuestos no se calculan correctamente")
|
||||
else:
|
||||
print(" ⚠ Producto sin impuestos")
|
||||
logger.warning(" ⚠ Producto sin impuestos")
|
||||
|
||||
# Test 4: Verificar OCA _get_price
|
||||
print("\nTEST 4: Verificar OCA _get_price")
|
||||
print("-" * 60)
|
||||
logger.info("\nTEST 4: Verificar OCA _get_price")
|
||||
logger.info("-" * 60)
|
||||
|
||||
pricelist = env["product.pricelist"].search(
|
||||
[("company_id", "=", env.company.id)], limit=1
|
||||
|
|
@ -154,33 +162,35 @@ try:
|
|||
fposition=False,
|
||||
)
|
||||
|
||||
print(f" OCA _get_price:")
|
||||
print(f" value: {price_info.get('value', 0):.2f} €")
|
||||
print(f" tax_included: {price_info.get('tax_included', False)}")
|
||||
logger.info(" OCA _get_price:")
|
||||
logger.info(" value: %.2f €", price_info.get("value", 0))
|
||||
logger.info(
|
||||
" tax_included: %s", str(price_info.get("tax_included", False))
|
||||
)
|
||||
|
||||
if not price_info.get("tax_included", False):
|
||||
print(f" ✓ PASADO: OCA retorna precio SIN IVA (esperado)")
|
||||
logger.info(" ✓ PASADO: OCA retorna precio SIN IVA (esperado)")
|
||||
else:
|
||||
print(f" ⚠ OCA indica IVA incluido")
|
||||
logger.warning(" ⚠ OCA indica IVA incluido")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("RESUMEN")
|
||||
print("=" * 60)
|
||||
print("""
|
||||
Corrección implementada:
|
||||
1. ✓ Método _compute_price_with_taxes añadido
|
||||
2. ✓ Calcula precio CON IVA usando taxes.compute_all()
|
||||
3. ✓ Usado en eskaera_shop y add_to_eskaera_cart
|
||||
4. ✓ Soluciona problema de precios sin IVA en la tienda
|
||||
logger.info("\n" + "=" * 60)
|
||||
logger.info("RESUMEN")
|
||||
logger.info("=" * 60)
|
||||
logger.info("""
|
||||
Corrección implementada:
|
||||
1. ✓ Método _compute_price_with_taxes añadido
|
||||
2. ✓ Calcula precio CON IVA usando taxes.compute_all()
|
||||
3. ✓ Usado en eskaera_shop y add_to_eskaera_cart
|
||||
4. ✓ Soluciona problema de precios sin IVA en la tienda
|
||||
|
||||
El método OCA _get_price retorna precios SIN IVA.
|
||||
Nuestra función _compute_price_with_taxes añade el IVA.
|
||||
""")
|
||||
El método OCA _get_price retorna precios SIN IVA.
|
||||
Nuestra función _compute_price_with_taxes añade el IVA.
|
||||
""")
|
||||
|
||||
print("✓ Todos los tests completados exitosamente\n")
|
||||
logger.info("✓ Todos los tests completados exitosamente\n")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n✗ ERROR: {e}\n")
|
||||
logger.exception("\n✗ ERROR: %s\n", e)
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue