# Copyright 2022 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


class StockMoveLine(models.Model):
    _inherit = "stock.move.line"

    def _get_aggregated_product_quantities(self, **kwargs):
        """Odoo displays undelivered products in the main table too.

        Remove them from the aggregated dict so they only show up in the
        bottom "remaining products" table.
        """
        aggregated_move_lines = super()._get_aggregated_product_quantities(**kwargs)
        keys_to_remove = {
            key
            for key, values in aggregated_move_lines.items()
            if not values["quantity"]
        }
        for key in keys_to_remove:
            aggregated_move_lines.pop(key, None)
        return aggregated_move_lines
