[FIX] website: Delete the current website

Steps to reproduce the bug:

- Delete the current website
- Go to homepage

Bug:

An error 500 was displayrd

opw:2381929

closes odoo/odoo#61959

X-original-commit: ae6515a5fb849a4b561b87eaa5c78035771a17b8
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2020-11-18 15:36:38 +00:00
parent 183bb633c2
commit 315c293b6c
2 changed files with 10 additions and 0 deletions
+6
View File
@@ -8678,6 +8678,12 @@ msgstr ""
msgid "valuation, rank"
msgstr ""
#. module: website
#: code:addons/website/models/website.py:162
#, python-format
msgid "You must keep at least one website."
msgstr ""
#. module: website
#: model:ir.model.fields,field_description:website.field_res_config_settings__website_id
msgid "website"
+4
View File
@@ -16,6 +16,7 @@ from odoo import api, fields, models, tools
from odoo.addons.http_routing.models.ir_http import slugify, _guess_mimetype, url_for
from odoo.addons.website.models.ir_http import sitemap_qs2dom
from odoo.addons.portal.controllers.portal import pager
from odoo.exceptions import UserError
from odoo.http import request
from odoo.modules.module import get_resource_path
from odoo.osv.expression import FALSE_DOMAIN
@@ -221,6 +222,9 @@ class Website(models.Model):
vals['favicon'] = tools.image_process(vals['favicon'], size=(256, 256), crop='center', output_format='ICO')
def unlink(self):
website = self.search([('id', 'not in', self.ids)], limit=1)
if not website:
raise UserError(_('You must keep at least one website.'))
# Do not delete invoices, delete what's strictly necessary
attachments_to_unlink = self.env['ir.attachment'].search([
('website_id', 'in', self.ids),