[MiG] port from 19
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_init_hook(cr, registry):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
Website = env['website'].sudo()
|
||||
WebsitePage = env['website.page'].sudo()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 1. Get the generic TEST page template
|
||||
# ---------------------------------------------------------
|
||||
test_view = env.ref(
|
||||
'testserver_website_o2b.testserver_page_website',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
|
||||
if not test_view:
|
||||
_logger.error(
|
||||
"Testserver website template "
|
||||
"'testserver_website_o2b.testserver_page_website' not found."
|
||||
)
|
||||
return
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 2. Unpublish all existing website pages
|
||||
# ---------------------------------------------------------
|
||||
pages = WebsitePage.search([])
|
||||
|
||||
if pages:
|
||||
_logger.info(
|
||||
"Unpublishing %s existing website pages.",
|
||||
len(pages),
|
||||
)
|
||||
|
||||
pages.write({
|
||||
'website_published': False,
|
||||
})
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 3. Create a TEST homepage for every website
|
||||
# ---------------------------------------------------------
|
||||
websites = Website.search([])
|
||||
|
||||
for website in websites:
|
||||
_logger.info(
|
||||
"Creating test homepage for website %s (%s).",
|
||||
website.name,
|
||||
website.id,
|
||||
)
|
||||
|
||||
# Each website gets its own ir.ui.view.
|
||||
#
|
||||
# In Odoo 15 website.page.website_id is related to
|
||||
# view_id.website_id. Therefore we should not use the same
|
||||
# ir.ui.view for multiple websites.
|
||||
website_test_view = test_view.copy({
|
||||
'name': 'Test environment - %s' % website.name,
|
||||
'key': '%s.website_%s' % (test_view.key, website.id),
|
||||
'website_id': website.id,
|
||||
})
|
||||
|
||||
test_page = WebsitePage.create({
|
||||
'url': '/testmodus',
|
||||
'view_id': website_test_view.id,
|
||||
'website_published': True,
|
||||
'website_indexed': False,
|
||||
})
|
||||
|
||||
# Odoo 15 uses homepage_id, NOT homepage_url.
|
||||
website.write({
|
||||
'domain': False,
|
||||
'homepage_id': test_page.id,
|
||||
})
|
||||
|
||||
_logger.info(
|
||||
"Test homepage %s assigned to website %s.",
|
||||
test_page.id,
|
||||
website.id,
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 4. Disable all payment acquirers
|
||||
# ---------------------------------------------------------
|
||||
#
|
||||
# Odoo 15 uses payment.acquirer.
|
||||
# payment.provider belongs to later Odoo versions.
|
||||
#
|
||||
if env.registry.get('payment.acquirer'):
|
||||
payment_acquirers = env['payment.acquirer'].sudo().search([
|
||||
('state', '!=', 'disabled'),
|
||||
])
|
||||
|
||||
if payment_acquirers:
|
||||
_logger.info(
|
||||
"Disabling %s payment acquirers.",
|
||||
len(payment_acquirers),
|
||||
)
|
||||
|
||||
payment_acquirers.write({
|
||||
'state': 'disabled',
|
||||
})
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 5. Unpublish all webshop products
|
||||
# ---------------------------------------------------------
|
||||
#
|
||||
# website_published only exists on product.template when the
|
||||
# relevant website/eCommerce functionality is installed.
|
||||
#
|
||||
if env.registry.get('product.template'):
|
||||
ProductTemplate = env['product.template'].sudo()
|
||||
|
||||
if 'website_published' in ProductTemplate._fields:
|
||||
published_products = ProductTemplate.search([
|
||||
('website_published', '=', True),
|
||||
])
|
||||
|
||||
if published_products:
|
||||
_logger.info(
|
||||
"Unpublishing %s webshop products.",
|
||||
len(published_products),
|
||||
)
|
||||
|
||||
published_products.write({
|
||||
'website_published': False,
|
||||
})
|
||||
|
||||
_logger.info(
|
||||
"Testserver website neutralization completed successfully."
|
||||
)
|
||||
Reference in New Issue
Block a user