# Copyright 2026 Criptomart # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) import logging from odoo import models _logger = logging.getLogger(__name__) class PaymentTransaction(models.Model): _inherit = "payment.transaction" def _check_amount_and_confirm_order(self): """Confirm group order sales the way the cutoff cron already does. ``group.order._confirm_linked_sale_orders`` confirms with ``from_orderpoint=True`` on purpose: ``stock.move._action_confirm`` forwards ``raise_user_error=not from_orderpoint`` to ``procurement.group.run``, so a product with a broken replenishment route does not block the sale, and the missing moves are reported operationally instead. The standard payment post-processing confirms without that context, and ``/payment/status/poll`` rolls back and re-raises anything ``_post_process`` throws. Without this override, one misconfigured product turns a successful payment into an error page while the transaction is already ``done``, and the retry cron keeps failing on it. Orders born from a group order follow the cron's operational rules, so they get the cron's context. """ eskaera_txs = self.filtered(lambda tx: tx.sale_order_ids.group_order_id) if not eskaera_txs: return super()._check_amount_and_confirm_order() confirmed_orders = super( PaymentTransaction, self - eskaera_txs )._check_amount_and_confirm_order() _logger.info( "[PAYMENT] Confirming %d group order transaction(s) with " "from_orderpoint=True: %s", len(eskaera_txs), eskaera_txs.ids, ) confirmed_orders |= super( PaymentTransaction, eskaera_txs.with_context(from_orderpoint=True) )._check_amount_and_confirm_order() return confirmed_orders