[ADD] website_sale_aplicoop: serve Eskaera per website
A co-op can run the plain shop on one website and the group orders on another, but routes are registered process-wide: every /eskaera page answered on every website of the database, and Odoo had already copied the Eskaera menu to all of them. `website.eskaera_enabled` decides which websites serve it, on by default so installing changes nothing. It reaches the settings screen through `website_id`, so it follows the website selector there. Where it is off the routes raise NotFound and the menu is hidden. The menu is hidden rather than deleted, by extending `_compute_visible`. That keeps the record and any manual rename or reordering, so switching the feature back on restores it as it was. Note that a JSON route reports the 404 inside the JSON-RPC payload and still answers HTTP 200; that is the transport, not a hole in the guard, and a test pins it so the next reader does not take it for one. The three remaining settings (lazy loading, products per page, low stock threshold) are still `config_parameter`, so they stay global to the database. Two websites share their values. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
817ff31d39
commit
5a2f5d120f
9 changed files with 313 additions and 0 deletions
40
website_sale_aplicoop/models/website.py
Normal file
40
website_sale_aplicoop/models/website.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2025-Today Criptomart
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
|
||||
from odoo import fields
|
||||
from odoo import models
|
||||
|
||||
ESKAERA_URL_PREFIX = "/eskaera"
|
||||
|
||||
|
||||
class Website(models.Model):
|
||||
_inherit = "website"
|
||||
|
||||
eskaera_enabled = fields.Boolean(
|
||||
string="Eskaera Group Orders",
|
||||
default=True,
|
||||
help="Serve the Eskaera collaborative purchasing pages on this website. "
|
||||
"Turn it off on a website that only runs the regular shop: its "
|
||||
"/eskaera pages answer 404 and its Eskaera menu is hidden.",
|
||||
)
|
||||
|
||||
|
||||
class WebsiteMenu(models.Model):
|
||||
_inherit = "website.menu"
|
||||
|
||||
def _compute_visible(self):
|
||||
"""Hide the Eskaera menu on websites that do not serve it.
|
||||
|
||||
Hiding rather than deleting the menu keeps the entry (and any manual
|
||||
rename or reordering) around, so switching the feature back on
|
||||
restores it as it was.
|
||||
"""
|
||||
res = super()._compute_visible()
|
||||
for menu in self:
|
||||
if not menu.is_visible or not menu.website_id:
|
||||
continue
|
||||
if menu.website_id.eskaera_enabled:
|
||||
continue
|
||||
if (menu.url or "").startswith(ESKAERA_URL_PREFIX):
|
||||
menu.is_visible = False
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue