* = test_website, website_blog, website_event, website_forum, website_sale, website_slides `_search_get_details` extension in other modules can now be performed with fewer lines of code by updating a search type-to-model mapping, without the need for method override. This will also have the benefit of slightly reducing the call stack length, avoiding some unnecessary `if` statements and list lookups at runtime. Task-2957361 closes odoo/odoo#98423 Related: odoo/enterprise#30946 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models, fields, api, _
|
|
from odoo.addons.http_routing.models.ir_http import url_for
|
|
from odoo.addons.website.models.website import SEARCH_TYPE_MODELS
|
|
|
|
SEARCH_TYPE_MODELS['forums'] |= 'forum.forum', 'forum.post'
|
|
SEARCH_TYPE_MODELS['forums_only'] |= 'forum.forum',
|
|
SEARCH_TYPE_MODELS['forum_posts_only'] |= 'forum.post',
|
|
|
|
|
|
class Website(models.Model):
|
|
_inherit = 'website'
|
|
|
|
@api.model
|
|
def get_default_forum_count(self):
|
|
self.forums_count = self.env['forum.forum'].search_count(self.website_domain())
|
|
|
|
forums_count = fields.Integer(readonly=True, default=get_default_forum_count)
|
|
|
|
def get_suggested_controllers(self):
|
|
suggested_controllers = super(Website, self).get_suggested_controllers()
|
|
suggested_controllers.append((_('Forum'), url_for('/forum'), 'website_forum'))
|
|
return suggested_controllers
|
|
|
|
def configurator_get_footer_links(self):
|
|
links = super().configurator_get_footer_links()
|
|
links.append({'text': _("Forum"), 'href': '/forum'})
|
|
return links
|
|
|
|
def configurator_set_menu_links(self, menu_company, module_data):
|
|
# Forum menu should only be a footer link, not a menu
|
|
forum_menu = self.env['website.menu'].search([('url', '=', '/forum'), ('website_id', '=', self.id)])
|
|
forum_menu.unlink()
|
|
super().configurator_set_menu_links(menu_company, module_data)
|