From 4f6ec1cd2a9253bb0c6c17d304490c7809facf8a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Sun, 12 Aug 2018 22:40:50 +0200 Subject: [IMP] website,*: support multiple websites This implements support to administer multiple websites. Although the core functionality already existed, managing multiple websites was fairly technical. In the interest of database updates and migration this attempts to keep duplicated data to a minimum. To do this the usual generic records are rendered unless some website-specific record exists that replaces it. Copy-on-write (COW) is used to create these website-specific records. Through this mechanism creating a website-specific record is delayed until necessary. A COW mechanism has been implemented on 4 models: ir.ui.view, website.page, website.menu and ir.attachment. These COW mechanisms are activated when editing data through the website (aka frontend). These frontend edits (e.g. with web_editor) will be website-specific, possibly creating a website-specific record when necessary. When editing data in the backend nothing special will happen, even when editing a generic record. Note that because of this mechanism also facilitates the ability to create new, uncustomized websites because the generic data is kept. Support is provided for a website to have any theme. Themes are fairly complex to handle. Standalone themes can depend on other standalone themes (e.g. theme_beauty depends on theme_loftspace) and themes usually modify some data of the themes they depend on. Because a theme can be installed on multiple websites, using website_id m2o fields does not work well. It would require duplicate data, making updates and migration harder. Because of this, data for themes (ir.ui.view and ir.attachment specifically) have a theme_id m2o. website has a theme_ids m2m that identifies all theme modules currently installed on it. Through these fields we figure out what to render. A theme is only fully uninstalled when it's no longer active on any website. The advantage of this approach is that upgrading or migrating theme data is no different from the single-website case. The website.published.mixin class was modified to handle multiple websites. A wizard was added in the backend to easily manage this for multiple website. Although not used anywhere in this commit, a 'website_id' variable has been added in the evaluation context of ir.rule. It allows to easily make any model multi-website aware, all that's needed is a custom website_id m2o field on a model and a custom record rule. --- addons/website/static/src/js/content/website_root.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'addons/website/static/src/js/content/website_root.js') diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index 29163838f7a..162bd42c07b 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -40,6 +40,7 @@ var WebsiteRoot = BodyManager.extend({ 'click .js_publish_management .js_publish_btn': '_onPublishBtnClick', 'submit .js_website_submit_form': '_onWebsiteFormSubmit', 'click .js_disable_on_click': '_onDisableOnClick', + 'click .js_multi_website_switch': '_multiWebsiteSwitch', }), custom_events: _.extend({}, BodyManager.prototype.custom_events || {}, { animation_start_demand: '_onAnimationStartDemand', @@ -279,6 +280,23 @@ var WebsiteRoot = BodyManager.extend({ _onDisableOnClick: function (ev) { $(ev.currentTarget).addClass('disabled'); }, + + /** + * Called when clicking on the multi-website switcher. + * + * @param {OdooEvent} ev + */ + _multiWebsiteSwitch: function (ev) { + var website_id_to_switch_to = ev.target.getAttribute('website-id'); + this._rpc({ + route: '/website/set_session_website', + params: { + website_id: website_id_to_switch_to || false, + }, + }).then(function () { + window.location.reload(true); + }); + }, }); return { -- cgit v1.2.3 From ff26b20a48e17966ffc72867b7342160c2766283 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 24 Jul 2018 11:02:40 +0200 Subject: [REF] website: small diff pep, renaming, make generic function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit should not change the behaviour in most cases. Co-authored-by: Derie Romain Co-authored-by: Kersten Jérémy --- addons/website/static/src/js/content/website_root.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/website/static/src/js/content/website_root.js') diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index 162bd42c07b..0f3fff53dfc 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -289,7 +289,7 @@ var WebsiteRoot = BodyManager.extend({ _multiWebsiteSwitch: function (ev) { var website_id_to_switch_to = ev.target.getAttribute('website-id'); this._rpc({ - route: '/website/set_session_website', + route: '/website/force_website', params: { website_id: website_id_to_switch_to || false, }, -- cgit v1.2.3 From 602807acdf20ff4f75a1abb7f5fa1be4db3f532d Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 24 Jul 2018 17:01:44 +0200 Subject: [FIX] website: improve/fix menu, copy on unlink, clone page, unique_path, sale_report, ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix bug from the initial poc of JOV Fix menu creation - creating a menu would create a 'container' menu in the DB (.create is call without website_id) then writing on it would copy (if condition to cow) the menu with a website_id leaving the first one as a menu container unused. - website_menu should always have a website_id we dont want to support the multiwebsite system that allow to have generic/specific menu unlink/write is useless now since we always have a website_id Make unique_path website dependent, 2 distinct website can have a page with same name Make Sale report multiwebsite compliant Make website_id on sale_order / account.invoice as a related stored from partner_id. Co-authored-by: Derie Romain Co-authored-by: Kersten Jérémy --- addons/website/static/src/js/content/website_root.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/website/static/src/js/content/website_root.js') diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index 0f3fff53dfc..a51c8011e92 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -287,7 +287,7 @@ var WebsiteRoot = BodyManager.extend({ * @param {OdooEvent} ev */ _multiWebsiteSwitch: function (ev) { - var website_id_to_switch_to = ev.target.getAttribute('website-id'); + var website_id_to_switch_to = ev.currentTarget.getAttribute('website-id'); this._rpc({ route: '/website/force_website', params: { -- cgit v1.2.3