Skip to content

Commit

Permalink
⚡ different template users for each website
Browse files Browse the repository at this point in the history
  • Loading branch information
KolushovAlexandr committed May 28, 2020
1 parent 63a51a9 commit 3f94df0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
3 changes: 2 additions & 1 deletion web_website/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2020 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# License MIT (https://opensource.org/licenses/MIT).
{
"name": """Website Switcher in Backend""",
"summary": """Technical module to switch Websites in Backend similarly to Company Switcher""",
"category": "Hidden",
# "live_test_url": "",
"images": [],
"version": "11.0.3.0.4",
"version": "11.0.3.1.0",
"application": False,
"author": "IT-Projects LLC, Ivan Yelizariev",
"support": "[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions web_website/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
`3.1.0`
-------
- **New:** Different template users for each website

`3.0.4`
-------
- **Fix:** Incorrect return data in get_multi in case of 'many2one' field, id instead of a record
Expand Down
1 change: 1 addition & 0 deletions web_website/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import res_config
from . import res_users
from . import ir_http
from . import website
29 changes: 28 additions & 1 deletion web_website/models/res_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2020 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# License MIT (https://opensource.org/licenses/MIT).
from odoo import fields, models
from odoo import api, fields, models


class WebWebsiteConfigSettings(models.TransientModel):
Expand All @@ -12,3 +13,29 @@ class WebWebsiteConfigSettings(models.TransientModel):
help="Show Website Switcher in backend",
implied_group="web_website.group_multi_website",
)

@api.multi
def open_template_user(self):
IrConfigParameter = self.env['ir.config_parameter'].sudo()
IrProperty = self.env['ir.property'].sudo()
ResUsers = self.env['res.users'].sudo()

# search for all properties for that case
param_id = IrConfigParameter.search([
('key', '=', 'auth_signup.template_user_id')
], limit=1)
field = self.env["ir.model.fields"].search([
("model", "=", 'ir.config_parameter'),
("name", "=", "value")
], limit=1)
prop_ids = IrProperty.search([
('fields_id', '=', field.id),
('res_id', '=', '{},{}'.format(IrConfigParameter._name, param_id.id)),
])

website_id = ResUsers.browse(self._context['uid']).backend_website_id
# Is it needed?? if param_id.value in prop_ids.filtered(lambda p: not p.website_id).mapped('value_text') and ...
if website_id not in prop_ids.mapped('website_id'):
# Template user was not created/set for current website
website_id.create_new_template_user_id()
return super(WebWebsiteConfigSettings, self).open_template_user()
31 changes: 31 additions & 0 deletions web_website/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2020 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# License MIT (https://opensource.org/licenses/MIT).

from odoo import api, models


class Website(models.Model):
_inherit = "website"

@api.model
def create(self, vals):
website = super(Website, self).create(vals)
website.create_new_template_user_id()
return website

@api.multi
def create_new_template_user_id(self):
IrConfigParameter = self.env['ir.config_parameter'].sudo()
user_id = IrConfigParameter.get_param('auth_signup.template_user_id', 'False')
user_id = self.env['res.users'].sudo().browse(user_id and int(user_id))
for record in self:
company_id = record.company_id.id
new_user_id = user_id.sudo().copy({
"login": "{} - {}".format(user_id.login, record.name),
"company_id": company_id,
"company_ids": [(6, 0, [company_id])],
"backend_website_ids": [(6, 0, record.ids)]
})
IrConfigParameter. \
with_context(dict(website_id=record.id)). \
set_param('auth_signup.template_user_id', new_user_id.id)

0 comments on commit 3f94df0

Please sign in to comment.