[IMP] website: add missing theme models fields
Before this commit, there were multiple issues related to the creation of `theme.website.menu` records in a theme: - Not possible to add a menu in the existing website's navbar - When one would try to create a `theme.website.menu` that menu would be created for every website when instaling the theme on a particular website, which is terribly wrong as it goes against the multi-website holy grail rule: when editing a website, do not impact other websites. - Not possible to create a mega menu Now, one can create a menu: - as a navbar top menu - as a child menu of another theme menu - as a whole new menu hierarchy (top level container) This is not possible to create a menu as a child of a website.menu, like adding 2 submenu to the existing contact us menu. First, this is technically impossible to do without introducing yet another hack code in the `website.menu` write. Indeed, there is no way to identify a generic menu's website copies. Neither through a direct DB field, neither through a persistent info like we do with the `key` attribute of views. So there is no reliable way to tell the system to add a menu below the "Contact Us" menu of the website, as this is just a menu copied when the website was created. We could obviously later add a `key` field or something like that to identify an XML menu's copies. Second, there is a workaround as one has to recreate the website.menu and delete the original one (through a `<function/>` record). Third, this should not be the main use case about menu creation in themes. ---------- Some fields were also missing regarding the `website.page` model. ---------- A stable attempt is done at [1], this is where the current commit originates from. As the Odoo 17 release is quickly approaching, it was decided to first write the proper IMP in master from which we will see what can be backported and how, if needed. [1]: https://github.com/odoo/odoo/pull/86669 Part-of: odoo/odoo#99099
This commit is contained in:
@@ -144,12 +144,22 @@ class ThemeMenu(models.Model):
|
||||
new_window = fields.Boolean('New Window')
|
||||
sequence = fields.Integer()
|
||||
parent_id = fields.Many2one('theme.website.menu', index=True, ondelete="cascade")
|
||||
mega_menu_content = fields.Html()
|
||||
mega_menu_classes = fields.Char()
|
||||
|
||||
use_main_menu_as_parent = fields.Boolean(default=True)
|
||||
copy_ids = fields.One2many('website.menu', 'theme_template_id', 'Menu using a copy of me', copy=False, readonly=True)
|
||||
|
||||
def _convert_to_base_model(self, website, **kwargs):
|
||||
self.ensure_one()
|
||||
page_id = self.page_id.copy_ids.filtered(lambda x: x.website_id == website)
|
||||
parent_id = self.copy_ids.filtered(lambda x: x.website_id == website)
|
||||
|
||||
parent_id = False
|
||||
if self.parent_id:
|
||||
parent_id = self.parent_id.copy_ids.filtered(lambda x: x.website_id == website)
|
||||
elif self.use_main_menu_as_parent:
|
||||
parent_id = website.menu_id
|
||||
|
||||
new_menu = {
|
||||
'name': self.name,
|
||||
'url': self.url,
|
||||
@@ -157,6 +167,9 @@ class ThemeMenu(models.Model):
|
||||
'new_window': self.new_window,
|
||||
'sequence': self.sequence,
|
||||
'parent_id': parent_id and parent_id.id or False,
|
||||
'website_id': website.id,
|
||||
'mega_menu_content': self.mega_menu_content,
|
||||
'mega_menu_classes': self.mega_menu_classes,
|
||||
'theme_template_id': self.id,
|
||||
}
|
||||
return new_menu
|
||||
@@ -169,6 +182,14 @@ class ThemePage(models.Model):
|
||||
url = fields.Char()
|
||||
view_id = fields.Many2one('theme.ir.ui.view', required=True, ondelete="cascade")
|
||||
website_indexed = fields.Boolean('Page Indexed', default=True)
|
||||
is_published = fields.Boolean()
|
||||
|
||||
# Page options
|
||||
header_overlay = fields.Boolean()
|
||||
header_color = fields.Char()
|
||||
header_visible = fields.Boolean(default=True)
|
||||
footer_visible = fields.Boolean(default=True)
|
||||
|
||||
copy_ids = fields.One2many('website.page', 'theme_template_id', 'Page using a copy of me', copy=False, readonly=True)
|
||||
|
||||
def _convert_to_base_model(self, website, **kwargs):
|
||||
@@ -182,6 +203,11 @@ class ThemePage(models.Model):
|
||||
'url': self.url,
|
||||
'view_id': view_id.id,
|
||||
'website_indexed': self.website_indexed,
|
||||
'is_published': self.is_published,
|
||||
'header_overlay': self.header_overlay,
|
||||
'header_color': self.header_color,
|
||||
'header_visible': self.header_visible,
|
||||
'footer_visible': self.footer_visible,
|
||||
'theme_template_id': self.id,
|
||||
}
|
||||
return new_page
|
||||
@@ -362,11 +388,13 @@ class IrUiView(models.Model):
|
||||
res &= super(IrUiView, no_arch_updated_views).write(vals)
|
||||
return res
|
||||
|
||||
|
||||
class IrAsset(models.Model):
|
||||
_inherit = 'ir.asset'
|
||||
|
||||
theme_template_id = fields.Many2one('theme.ir.asset', copy=False)
|
||||
|
||||
|
||||
class IrAttachment(models.Model):
|
||||
_inherit = 'ir.attachment'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user