addons-cm/website_sale_aplicoop/controllers/portal.py
snt 6fbc7b9456 [FIX] website_sale_aplicoop: Remove redundant string= attributes and fix OCA linting warnings
- Remove redundant string= from 17 field definitions where name matches string value (W8113)
- Convert @staticmethod to instance methods in selection methods for proper self.env._() access
- Fix W8161 (prefer-env-translation) by using self.env._() instead of standalone _()
- Fix W8301/W8115 (translation-not-lazy) by proper placement of % interpolation outside self.env._()
- Remove unused imports of odoo._ from group_order.py and sale_order_extension.py
- All OCA linting warnings in website_sale_aplicoop main models are now resolved

Changes:
- website_sale_aplicoop/models/group_order.py: 21 field definitions cleaned
- website_sale_aplicoop/models/sale_order_extension.py: 5 field definitions cleaned + @staticmethod conversion
- Consistent with OCA standards for addon submission
2026-02-18 17:54:43 +01:00

72 lines
2.3 KiB
Python

# Copyright 2025 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import logging
from odoo import _
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"] = [
_("Monday"),
_("Tuesday"),
_("Wednesday"),
_("Thursday"),
_("Friday"),
_("Saturday"),
_("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"] = [
_("Monday"),
_("Tuesday"),
_("Wednesday"),
_("Thursday"),
_("Friday"),
_("Saturday"),
_("Sunday"),
]
return response