# Copyright 2026 Criptomart
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class StockBackorderConfirmation(models.TransientModel):
    _inherit = "stock.backorder.confirmation"

    def _check_batch_summary_lines(self):
        pickings = self.env["stock.picking"].browse(
            self.env.context.get("button_validate_picking_ids", [])
        )
        for batch in pickings.batch_id:
            batch._check_all_products_collected(pickings)

    def process(self):
        self._check_batch_summary_lines()
        return super().process()

    def process_cancel_backorder(self):
        self._check_batch_summary_lines()
        return super().process_cancel_backorder()
