diff --git a/web_website/README.rst b/web_website/README.rst new file mode 100644 index 0000000000..f0476b6168 --- /dev/null +++ b/web_website/README.rst @@ -0,0 +1,72 @@ +.. image:: https://itpp.dev/images/infinity-readme.png + :alt: Tested and maintained by IT Projects Labs + :target: https://itpp.dev + +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl + :alt: License: LGPL-3.0 + +===================== + Multi-Brand Backend +===================== + +Technical module to properly handle multi-website setup. + +The modules sets context variable **allowed_website_ids**: + +* in backend: selected websites +* in frontend: current website (as a list) + +The module adds ``env`` properties: + +* ``env.website`` -- first website from the list: ``browse(context["allowed_website_ids"][0])`` +* ``env.websites`` -- all websites: ``browse(context["allowed_website_ids"])`` + +website_dependent +================= + +The module adds new field attribute ``website_dependent``, which is analog of ``company_dependent``, but for websites. + +See ``_ and ``_ to understand how it works. + +If you need to convert existing field to a website-dependent field it's not +enough just to add the attributes. You need additional stuff to make your module +safely installable and uninstallable. See module +``ir_config_parameter_multi_company`` as an example. Things to do: + +* extend ``ir.property``'s ``write`` to call ``_update_db_value_website_dependent`` +* Add to the field both ``company_dependent=True`` and ``website_dependent=True`` +* In the field's module extend following methods: + + * ``create`` -- call ``_force_default`` + * ``write`` -- call ``_update_properties_label`` + * ``_auto_init`` -- call ``_auto_init_website_dependent`` + +* In the field's module add ``uninstall_hook``: + + * remove field's properties + +Roadmap +======= + +* TODO: Since odoo 12, there is another switcher at ``[[ Website ]] >> Dashboard`` menu. It has to be syncronized with the switcher of this module, i.e. hide default one and use value of this module switcher. + +Questions? +========== + +To get an assistance on this module contact us by email :arrow_right: help@itpp.dev + +Contributors +============ +* `Ivan Yelizariev `__ + + +Further information +=================== + +Odoo Apps Store: https://apps.odoo.com/apps/modules/13.0/web_website/ + + +Notifications on updates: `via Atom `_, `by Email `_ + +Tested on `Odoo 13.0 `_ diff --git a/web_website/__init__.py b/web_website/__init__.py new file mode 100644 index 0000000000..44979cb486 --- /dev/null +++ b/web_website/__init__.py @@ -0,0 +1,16 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from . import models + + +def post_init_hook(cr, registry): + from odoo import api, SUPERUSER_ID + + env = api.Environment(cr, SUPERUSER_ID, {}) + + # emulate updating existing field to website-dependent one + env.cr.execute("ALTER TABLE test_website_dependent ADD COLUMN foo VARCHAR") + env.cr.execute("ALTER TABLE test_website_dependent ADD COLUMN user_id INTEGER") + + +def post_load(): + from . import api diff --git a/web_website/__manifest__.py b/web_website/__manifest__.py new file mode 100644 index 0000000000..36c66fe689 --- /dev/null +++ b/web_website/__manifest__.py @@ -0,0 +1,36 @@ +# Copyright 2018,2020 Ivan Yelizariev +# Copyright 2018 Kolushov Alexandr +# Copyright 2019 Eugene Molotov +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": """Multi-Brand Backend""", + "summary": """Technical module to switch Websites in Backend similarly to Company Switcher""", + "category": "Hidden", + # "live_test_url": "", + "images": [], + "version": "13.0.4.0.2", + "application": False, + "author": "IT-Projects LLC, Ivan Yelizariev", + "support": "apps@itpp.dev", + "website": "https://itpp.dev", + "license": "LGPL-3", + # "price": 0.00, + # "currency": "EUR", + "depends": ["web", "website", "base_setup"], + "external_dependencies": {"python": [], "bin": []}, + "data": [ + "views/res_users_views.xml", + "security/security.xml", + "security/ir.model.access.csv", + "views/ir_property_views.xml", + "views/assets.xml", + ], + "demo": ["demo/assets_demo.xml", "demo/res_users_demo.xml"], + "qweb": ["static/src/xml/qweb.xml"], + "post_load": "post_load", + "pre_init_hook": None, + "post_init_hook": "post_init_hook", + "uninstall_hook": None, + "auto_install": False, + "installable": True, +} diff --git a/web_website/api.py b/web_website/api.py new file mode 100644 index 0000000000..383d1f1c89 --- /dev/null +++ b/web_website/api.py @@ -0,0 +1,38 @@ +# Copyright 2020 Ivan Yelizariev +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo import _ +from odoo.api import Environment +from odoo.exceptions import AccessError +from odoo.tools import lazy_property + + +@lazy_property +def website(self): + """Like env.company, but for website""" + website_ids = self.context.get("allowed_website_ids", []) + if website_ids: + if not self.su: + user_website_ids = self.user.backend_website_ids.ids + if any(cid not in user_website_ids for cid in website_ids): + raise AccessError(_("Access to unauthorized or invalid websites.")) + return self["website"].browse(website_ids[0]) + return self.user.backend_website_id + + +@lazy_property +def websites(self): + """Like env.companies, but for websites""" + website_ids = self.context.get("allowed_website_ids", []) + if website_ids: + if not self.su: + user_website_ids = self.user.website_ids.ids + if user_website_ids and any( + cid not in user_website_ids for cid in website_ids + ): + raise AccessError(_("Access to unauthorized or invalid websites.")) + return self["website"].browse(website_ids) + return self.user.backend_website_ids + + +Environment.website = website +Environment.websites = websites diff --git a/web_website/demo/assets_demo.xml b/web_website/demo/assets_demo.xml new file mode 100644 index 0000000000..3f314baf8f --- /dev/null +++ b/web_website/demo/assets_demo.xml @@ -0,0 +1,10 @@ + + + +