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

from odoo import fields
from odoo import models


class SaleOrder(models.Model):
    _inherit = "sale.order"

    def _get_pickup_day_selection(self):
        """Return pickup day selection options with translations."""
        return [
            ("0", self.env._("Monday")),
            ("1", self.env._("Tuesday")),
            ("2", self.env._("Wednesday")),
            ("3", self.env._("Thursday")),
            ("4", self.env._("Friday")),
            ("5", self.env._("Saturday")),
            ("6", self.env._("Sunday")),
        ]

    pickup_day = fields.Selection(
        selection=_get_pickup_day_selection,
        help="Day of week when this order will be picked up (inherited from group order)",
    )

    group_order_id = fields.Many2one(
        "group.order",
        help="Reference to the consumer group order that originated this sale order",
    )

    pickup_date = fields.Date(
        help="Calculated pickup/delivery date (inherited from consumer group order)",
    )

    home_delivery = fields.Boolean(
        default=False,
        help="Whether this order includes home delivery (inherited from consumer group order)",
    )

    def _get_name_portal_content_view(self):
        """Override to return custom portal content template with group order info.

        This method is called by the portal template to determine which content
        template to render. We return our custom template that includes the
        group order information (Consumer Group, Delivery/Pickup info, etc.)
        """
        self.ensure_one()
        if self.group_order_id:
            return "website_sale_aplicoop.sale_order_portal_content_aplicoop"
        return super()._get_name_portal_content_view()
