Files
odoo_source/addons/test_website/models/model.py
T
Romain Derie 50e27b3c84 [FIX] website, *: make custom search model work when no website_id
*: test_website

Commit [1] modified the custom page search model so it is adding the
current website in the search domain.

But it was not considering the case of models not having a website_id
field.
The only case was the appoitment.type model.

Steps to reproduce:
- Install website_appointment (enterprise)
- Click on Website > Site > Appointments
- Crash

[1]: https://github.com/odoo/odoo/commit/db670f64f4c2190f1655f9077ea62885049a3c84

closes odoo/odoo#151686

X-original-commit: 247a5e157f14ce2cd8fbbe8d191abcb3c2e4ec0d
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2024-01-31 06:59:10 +00:00

59 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class TestModel(models.Model):
_name = 'test.model'
_inherit = [
'website.seo.metadata',
'website.published.mixin',
'website.searchable.mixin',
]
_description = 'Website Model Test'
name = fields.Char(required=True)
@api.model
def _search_get_detail(self, website, order, options):
return {
'model': 'test.model',
'base_domain': [],
'search_fields': ['name'],
'fetch_fields': ['name'],
'mapping': {
'name': {'name': 'name', 'type': 'text', 'match': True},
'website_url': {'name': 'name', 'type': 'text', 'truncate': False},
},
'icon': 'fa-check-square-o',
'order': 'name asc, id desc',
}
class TestModelMultiWebsite(models.Model):
_name = 'test.model.multi.website'
_inherit = [
'website.published.multi.mixin',
]
_description = 'Multi Website Model Test'
name = fields.Char(required=True)
# `cascade` is needed as there is demo data for this model which are bound
# to website 2 (demo website). But some tests are unlinking the website 2,
# which would fail if the `cascade` is not set. Note that the website 2 is
# never set on any records in all other modules.
website_id = fields.Many2one('website', string='Website', ondelete='cascade')
class TestModelExposed(models.Model):
_name = "test.model.exposed"
_inherit = [
'website.seo.metadata',
'website.published.mixin',
]
_description = 'Website Model Test Exposed'
_rec_name = "name"
name = fields.Char()