- 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.
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
# Copyright 2025 Criptomart
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
|
|
|
import logging
|
|
|
|
from odoo.http import request
|
|
from odoo.http import route
|
|
|
|
from odoo.addons.sale.controllers import portal as sale_portal
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class CustomerPortal(sale_portal.CustomerPortal):
|
|
"""Extend sale portal to include draft orders."""
|
|
|
|
def _prepare_orders_domain(self, partner):
|
|
"""Override to include draft and done orders."""
|
|
return [
|
|
("message_partner_ids", "child_of", [partner.commercial_partner_id.id]),
|
|
("state", "in", ["draft", "sale", "done"]), # Include draft orders
|
|
]
|
|
|
|
@route(
|
|
["/my/orders", "/my/orders/page/<int:page>"],
|
|
type="http",
|
|
auth="user",
|
|
website=True,
|
|
)
|
|
def portal_my_orders(self, **kwargs):
|
|
"""Override to add translated day names to context."""
|
|
# Get values from parent
|
|
values = self._prepare_sale_portal_rendering_values(
|
|
quotation_page=False, **kwargs
|
|
)
|
|
|
|
# Add translated day names for pickup_day display
|
|
values["day_names"] = [
|
|
request.env._("Monday"),
|
|
request.env._("Tuesday"),
|
|
request.env._("Wednesday"),
|
|
request.env._("Thursday"),
|
|
request.env._("Friday"),
|
|
request.env._("Saturday"),
|
|
request.env._("Sunday"),
|
|
]
|
|
|
|
request.session["my_orders_history"] = values["orders"].ids[:100]
|
|
return request.render("sale.portal_my_orders", values)
|
|
|
|
@route(["/my/orders/<int:order_id>"], type="http", auth="public", website=True)
|
|
def portal_order_page(self, order_id, access_token=None, **kwargs):
|
|
"""Override to add translated day names for order detail page."""
|
|
# Call parent to get response
|
|
response = super().portal_order_page(
|
|
order_id, access_token=access_token, **kwargs
|
|
)
|
|
|
|
# If it's a template render (not a redirect), add day_names to the context
|
|
if hasattr(response, "qcontext"):
|
|
response.qcontext["day_names"] = [
|
|
request.env._("Monday"),
|
|
request.env._("Tuesday"),
|
|
request.env._("Wednesday"),
|
|
request.env._("Thursday"),
|
|
request.env._("Friday"),
|
|
request.env._("Saturday"),
|
|
request.env._("Sunday"),
|
|
]
|
|
|
|
return response
|