addons-cm/website_sale_aplicoop/models/product_extension.py
snt cf9ea887c1 [REF] Code quality improvements and structure fixes
- Add mypy.ini configuration to exclude migration scripts
- Rename migration files to proper snake_case (post-migration.py → post_migration.py)
- Add __init__.py to migration directories for proper Python package structure
- Add new portal access tests for website_sale_aplicoop
- Code formatting improvements (black, isort)
- Update copilot instructions and project configuration

Related to previous code quality refactoring work.
2026-02-21 13:51:25 +01:00

53 lines
1.6 KiB
Python

# Copyright 2025 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api
from odoo import fields
from odoo import models
# Note: translation function _ is not used in this module (removed to satisfy flake8)
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")