La comparación abs(a - b) < 0.01 no era fiable por la coma flotante: el mismo céntimo se aceptaba o rechazaba según el importe (431.41 contra 431.40 se rechazaba y 624.39 contra 624.38 se aceptaba). pipeline_utils.importes_coinciden redondea la diferencia a 2 decimales, lo que muestra un comprobante, y admite hasta 1 céntimo. Se usa en la validación de precios y en la comparación del valor referencial. Con datos reales de SAP (49 líneas) ningún resultado cambió. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
import notificaciones as n
|
|
|
|
FACTURA = {"serie": "F002", "numero": "486", "razon_social_emisor": "TRANSPORTES SA"}
|
|
|
|
|
|
def test_cuerpo_draft_creado():
|
|
html = n.build_notification_body("created", FACTURA, "<t1/>", "<t2/>", doc_entry=2021)
|
|
assert "✅" in html and "<b>DocEntry:</b> 2021" in html
|
|
assert "F002-486" in html and "TRANSPORTES SA" in html
|
|
assert "<t1/>" in html and "<t2/>" in html
|
|
|
|
|
|
def test_cuerpo_error():
|
|
html = n.build_notification_body("error", FACTURA, "<t1/>", "<t2/>", error=ValueError("boom"))
|
|
assert "❌ Error al crear Draft" in html and "boom" in html
|
|
|
|
|
|
def test_cuerpo_precios_no_coinciden():
|
|
html = n.build_notification_body("skipped", FACTURA, "<t1/>", "<t2/>")
|
|
assert "Draft NO creado" in html and "no coinciden" in html
|
|
|
|
|
|
def test_tabla_de_validacion():
|
|
resultados = [
|
|
{"grflete": "09T001-1", "ok": True, "draft_price": 100.0, "sap_price": 100.0,
|
|
"warehouse_code": "A-X", "label": "LineTotal"},
|
|
{"grflete": "-", "ok": False, "draft_price": None, "sap_price": None,
|
|
"warehouse_code": "-", "label": "Sin guía de referencia"},
|
|
]
|
|
html = n.build_validation_html(resultados)
|
|
assert "09T001-1" in html and "100.000000" in html
|
|
assert html.count("✅") == 1 and html.count("❌") == 1
|
|
assert "Sin guía de referencia" in html
|
|
|
|
|
|
def test_valor_referencial_coincide():
|
|
factura = {"lineas": [{"valor_referencial": 10.0}, {"valor_referencial": 5.0}]}
|
|
guias = [{"serie": "T001", "numero": "1", "valor_sap": 9.0}, {"serie": "T001", "numero": "2", "valor_sap": 6.0}]
|
|
html = n.build_valor_referencial_html(factura, guias)
|
|
assert "✅ Coincide" in html and "<b>15.00</b>" in html
|
|
|
|
|
|
def test_valor_referencial_no_coincide():
|
|
factura = {"lineas": [{"valor_referencial": 10.0}]}
|
|
html = n.build_valor_referencial_html(factura, [{"serie": "T001", "numero": "1", "valor_sap": 9.0}])
|
|
assert "❌ No coincide" in html
|
|
|
|
|
|
def test_valor_referencial_con_un_centimo_de_diferencia_coincide():
|
|
factura = {"lineas": [{"valor_referencial": 624.38}]}
|
|
html = n.build_valor_referencial_html(factura, [{"serie": "T001", "numero": "1", "valor_sap": 624.39}])
|
|
assert "✅ Coincide" in html
|
|
|