-
-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
previous commits history: https://github.com/itpp-labs/misc-addons/commits/13.0/web_website > Made via .github/workflows/DINAR-PORT.yml
- Loading branch information
Showing
30 changed files
with
1,895 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 `<models/test_website.py>`_ and `<tests/test_website_dependent.py>`_ 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: [email protected] | ||
|
||
Contributors | ||
============ | ||
* `Ivan Yelizariev <https://it-projects.info/team/yelizariev>`__ | ||
|
||
|
||
Further information | ||
=================== | ||
|
||
Odoo Apps Store: https://apps.odoo.com/apps/modules/13.0/web_website/ | ||
|
||
|
||
Notifications on updates: `via Atom <https://github.com/it-projects-llc/misc-addons/commits/13.0/web_website.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/misc-addons/commits/13.0/web_website.atom>`_ | ||
|
||
Tested on `Odoo 13.0 <https://github.com/odoo/odoo/commit/8ebb5bdb4b63927a302f0d057b2f4db535d93829>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2018,2020 Ivan Yelizariev <https://it-projects.info/team/yelizariev> | ||
# Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr> | ||
# Copyright 2019 Eugene Molotov <https://it-projects.info/team/em234018> | ||
# 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": "[email protected]", | ||
"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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" ?> | ||
<!-- Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev> | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).--> | ||
<odoo> | ||
<template id="assets_backend_demo" inherit_id="web.assets_backend"> | ||
<xpath expr="." position="inside"> | ||
<script type="text/javascript" src="/web_website/static/src/js/tour.js" /> | ||
</xpath> | ||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" ?> | ||
<!-- Copyright 2018,2020 Ivan Yelizariev <https://it-projects.info/team/yelizariev> | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).--> | ||
<odoo> | ||
<!-- test_ui is assumed that the user has multi-website access --> | ||
<record id="base.user_demo" model="res.users"> | ||
<field name="groups_id" eval="[(4,ref('web_website.group_multi_website'))]" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
`4.0.2` | ||
------- | ||
- **Fix:** ``website_depedent`` misfunctioning after refactoring | ||
|
||
`4.0.1` | ||
------- | ||
- **Fix:** error on using ``env.website`` | ||
|
||
`4.0.0` | ||
------- | ||
- **New:** Allow selecting multiple websites in backend | ||
- **New:** Allow restricting user access to websites | ||
|
||
`3.0.6` | ||
------- | ||
- **Fix:** ``env.company`` must depend on current website | ||
|
||
`3.0.5` | ||
------- | ||
- **Fix:** All right menus were disapperated when Website Switcher shall not be visible | ||
|
||
`3.0.4` | ||
------- | ||
- **Fix:** Incorrect return data in get_multi in case of 'many2one' field, id instead of a record | ||
|
||
`3.0.3` | ||
------- | ||
- **Fix:** Error related to incorrect getting properties for html fields | ||
|
||
`3.0.2` | ||
------- | ||
- **Fix:** Error related to incorrect SQL request | ||
|
||
`3.0.1` | ||
------- | ||
- **Fix:** Incorrect website priority after odoo updates https://github.com/odoo/odoo/commit/b6d32de31e0e18a506ae06dc27561d1d078f3ab1 | ||
|
||
`3.0.0` | ||
------- | ||
- **New:** set website value automatically in case 1 company = 1 website | ||
|
||
`2.1.4` | ||
------- | ||
- **New:** Computing default company in multi-website environment is moved to | ||
this module from website_multi_company | ||
- **Fix:** Default value was updated for random field in _force_default method | ||
- **Fix:** updating many2one field to empty value raised error | ||
- **Fix:** Rare error on reading non-text fields | ||
|
||
`2.1.3` | ||
------- | ||
- **Improvement:** better names in *Company Properties* menu | ||
|
||
`2.1.2` | ||
------- | ||
- **Fix:** Error on creating record with non-empty value in website-depedent many2one field | ||
|
||
`2.1.1` | ||
------- | ||
- **Fix:** Error on searching by website_dependent or company_dependent fields | ||
|
||
`2.1.0` | ||
------- | ||
- **Fix:** fix API, which affects new modules | ||
- **Improvement:** allow convert html fields to website-dependent ones | ||
|
||
`2.0.0` | ||
------- | ||
- **Improvement:** Code is refactored to convert existing field to website-dependent one in a more easy way | ||
|
||
`1.0.2` | ||
------- | ||
|
||
- **Fix:** Website Switcher didn't work for non-admin users | ||
|
||
`1.0.1` | ||
------- | ||
- **Fix:** Website Switcher didn't work for non-admin users | ||
|
||
`1.0.0` | ||
------- | ||
|
||
- **Init version** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
===================== | ||
Multi-Brand Backend | ||
===================== | ||
|
||
Installation | ||
============ | ||
|
||
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way | ||
* As this is a technical module, consider to install other modules that use this one, for example `ir_config_parameter_multi_company <https://apps.odoo.com/apps/modules/13.0/ir_config_parameter_multi_company/>`_ | ||
|
||
Configuration | ||
============= | ||
|
||
Activate **Multi Websites for Backend**: | ||
|
||
* Activate `Developer mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__ | ||
* Navigate to ``[[ Settings ]] >> Users >> Users`` and set ``[x] Multi Websites for Backend`` for selected users | ||
|
||
Usage | ||
===== | ||
|
||
Website Switcher | ||
---------------- | ||
Once you activated **Multi Websites for Backend**, will see *Website Switcher* in top right-hand corner. | ||
|
||
Company Properties | ||
------------------ | ||
Via menu ``[[ Settings ]] >> Technical >> Parameters >> Company Properties`` (available in `Developer mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__) you can find exact values for *Website-dependent* fields. The menu shows normal *Company-dependent* fields too. To filter them out use new filter *Website-dependent*. | ||
|
||
How it works | ||
~~~~~~~~~~~~ | ||
|
||
For a given record field and context (Company, Website), priority of the *properties* to be used as field's value is as following: | ||
|
||
#. **Website** and **Resource** are matched | ||
#. **Website** is matched, **Resource** is empty | ||
#. **Company** and **Resource** are matched, **Website** is empty | ||
#. **Company** is matched, **Resource** and **Website** are empty | ||
#. **Company**, **Resource** and **Website** are empty (i.e. only **Field** is matched) | ||
|
||
Note, that when **Company** and **Website** are both set, **Website**'s Company | ||
must be equal to **Company** or Empty. Otherwise such records are ignored. | ||
|
||
On computing in non-website specific context it works as without the module, i.e.: | ||
|
||
#. **Company** and **Resource** are matched | ||
#. **Company** is matched, **Resource** is empty | ||
#. **Company** and **Resource** are empty (i.e. only **Field** is matched) |
Oops, something went wrong.