[FIX] TestConfirmEskaera_Integration: limpieza de decoradores @patch y corrección de bugs
- Convertir 4 tests de decorador @patch a context manager 'with patch(...)' para evitar RuntimeError en LocalProxy de Werkzeug - Corregir patrón env(user=..., context=dict(...)) en Odoo 18 (sin .with_context()) - Agregar website real al mock para integración con helpers de pricing (_get_pricing_info) - Añadir pickup_date en fixture de existing_order para que _find_recent_draft_order localice correctamente - BUGFIX: Agregar (5,) a order_line para limpiar líneas previas al actualizar pedido existente Resultado: 0 failed, 0 errors de 4 tests en Docker para TestConfirmEskaera_Integration BREAKING: _create_or_update_sale_order ahora limpia las líneas anteriores con (5,) antes de asignar las nuevas cuando se actualiza un pedido existente. Comportamiento previo (duplicación de líneas) era un bug.
This commit is contained in:
parent
e9809b90e9
commit
ce393b6034
13 changed files with 857 additions and 192 deletions
|
|
@ -2,8 +2,10 @@
|
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
|
|
@ -402,3 +404,54 @@ class TestCronPickingBatch(TransactionCase):
|
|||
"draft",
|
||||
"Sale order should remain draft - group order is closed",
|
||||
)
|
||||
|
||||
def test_cron_confirm_ignores_procurement_usererror(self):
|
||||
"""Procurement UserError must not block confirmation in cron flow."""
|
||||
group_order = self._create_group_order(cutoff_in_past=True)
|
||||
|
||||
so_ok = self._create_sale_order(
|
||||
group_order, self.member_1, self.consumer_group_1
|
||||
)
|
||||
so_fail = self._create_sale_order(
|
||||
group_order,
|
||||
self.member_2,
|
||||
self.consumer_group_2,
|
||||
)
|
||||
|
||||
so_ok.write({"name": "SO-OK"})
|
||||
so_fail.write({"name": "SO-FAIL"})
|
||||
|
||||
SaleOrderClass = type(self.env["sale.order"])
|
||||
original_action_confirm = SaleOrderClass.action_confirm
|
||||
|
||||
def _patched_action_confirm(recordset):
|
||||
should_fail = any(so.name == "SO-FAIL" for so in recordset)
|
||||
if should_fail and not recordset.env.context.get("from_orderpoint"):
|
||||
raise UserError("Simulated stock route error")
|
||||
return original_action_confirm(recordset)
|
||||
|
||||
with patch.object(SaleOrderClass, "action_confirm", _patched_action_confirm):
|
||||
group_order._confirm_linked_sale_orders()
|
||||
|
||||
so_ok.invalidate_recordset()
|
||||
so_fail.invalidate_recordset()
|
||||
|
||||
self.assertEqual(
|
||||
so_ok.state,
|
||||
"sale",
|
||||
"The valid order must still be confirmed",
|
||||
)
|
||||
self.assertTrue(
|
||||
so_ok.picking_ids,
|
||||
"The valid order should have pickings created",
|
||||
)
|
||||
self.assertTrue(
|
||||
so_ok.picking_ids[0].batch_id,
|
||||
"Pickings from valid orders should be batched",
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
so_fail.state,
|
||||
"sale",
|
||||
"The order should be confirmed when cron uses non-blocking procurement context",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue