diff --git a/base_usability/__manifest__.py b/base_usability/__manifest__.py index 094c5f9..df9bbc7 100644 --- a/base_usability/__manifest__.py +++ b/base_usability/__manifest__.py @@ -31,6 +31,7 @@ A group by 'State' is added to module search view. 'security/group.xml', 'security/ir.model.access.csv', 'partner_view.xml', + 'users_view.xml', 'country_view.xml', 'module_view.xml', ], diff --git a/base_usability/fix-odoo-base-multi-company-partners-not-shared.diff b/base_usability/fix-odoo-base-multi-company-partners-not-shared.diff new file mode 100644 index 0000000..f8529eb --- /dev/null +++ b/base_usability/fix-odoo-base-multi-company-partners-not-shared.diff @@ -0,0 +1,18 @@ +diff --git a/odoo/addons/base/res/res_users.py b/odoo/addons/base/res/res_users.py +index c621ca4..d3880fe 100644 +--- a/odoo/addons/base/res/res_users.py ++++ b/odoo/addons/base/res/res_users.py +@@ -334,7 +334,12 @@ class Users(models.Model): + user = super(Users, self).create(vals) + user.partner_id.active = user.active + if user.partner_id.company_id: +- user.partner_id.write({'company_id': user.company_id.id}) ++ # AKRETION HACK: if you have a multi-company setup where ++ # partners are NOT shared between companies, having ++ # company_id=False on partners related to users ++ # avoids a lot of trouble (you should also disable 'read' ++ # on the ir.rule 'user rule' (XMLID base.res_users_rule) ++ user.partner_id.write({'company_id': False}) + return user + + @api.multi diff --git a/base_usability/users.py b/base_usability/users.py index 78bf333..2621d05 100644 --- a/base_usability/users.py +++ b/base_usability/users.py @@ -2,7 +2,10 @@ # Copyright 2018 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, api +from odoo import models, api, SUPERUSER_ID, _ +from odoo.exceptions import UserError +import logging +logger = logging.getLogger(__name__) class ResUsers(models.Model): @@ -18,3 +21,21 @@ class ResUsers(models.Model): 'supplier': True, }) return res + + @api.model + def _script_partners_linked_to_users_no_company(self): + if self.env.user.id != SUPERUSER_ID: + raise UserError(_('You must run this script as admin user')) + logger.info( + 'START to set company_id=False on partners related to users') + users = self.search( + ['|', ('active', '=', True), ('active', '=', False)]) + for user in users: + if user.partner_id.company_id: + user.partner_id.company_id = False + logger.info( + 'Wrote company_id=False on user %s ID %d', + user.login, user.id) + logger.info( + 'END setting company_id=False on partners related to users') + return True diff --git a/base_usability/users_view.xml b/base_usability/users_view.xml new file mode 100644 index 0000000..e692049 --- /dev/null +++ b/base_usability/users_view.xml @@ -0,0 +1,21 @@ + + + + + + + base_usability.res.users.tree + res.users + + + + + + + + +