# Copyright 2025 Criptomart # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) from odoo import _, api, fields, models class ProductProduct(models.Model): _inherit = 'product.product' group_order_ids = fields.Many2many( 'group.order', 'group_order_product_rel', 'product_id', 'order_id', string='Group Orders', readonly=True, help='Group orders where this product is available', ) @api.model def _get_products_for_group_order(self, order_id): """Backward-compatible delegation to `group.order` discovery. The canonical discovery logic lives on `group.order` to keep responsibilities together. Keep this wrapper so existing callers on `product.product` keep working. """ order = self.env['group.order'].browse(order_id) if not order.exists(): return self.browse() return order._get_products_for_group_order(order.id) class ProductTemplate(models.Model): _inherit = 'product.template' group_order_ids = fields.Many2many( 'group.order', compute='_compute_group_order_ids', string='Consumer Group Orders', readonly=True, help='Consumer group orders where variants of this product are available', ) @api.depends('product_variant_ids.group_order_ids') def _compute_group_order_ids(self): for template in self: variants = template.product_variant_ids template.group_order_ids = variants.mapped('group_order_ids')