Add script to fix partners related to users in multi-company setup where partners are NOT shared between companies
This commit is contained in:
@@ -31,6 +31,7 @@ A group by 'State' is added to module search view.
|
|||||||
'security/group.xml',
|
'security/group.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'partner_view.xml',
|
'partner_view.xml',
|
||||||
|
'users_view.xml',
|
||||||
'country_view.xml',
|
'country_view.xml',
|
||||||
'module_view.xml',
|
'module_view.xml',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -2,7 +2,10 @@
|
|||||||
# Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
# Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# 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):
|
class ResUsers(models.Model):
|
||||||
@@ -18,3 +21,21 @@ class ResUsers(models.Model):
|
|||||||
'supplier': True,
|
'supplier': True,
|
||||||
})
|
})
|
||||||
return res
|
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
|
||||||
|
|||||||
21
base_usability/users_view.xml
Normal file
21
base_usability/users_view.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2018 Akretion (http://www.akretion.com/)
|
||||||
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_users_tree" model="ir.ui.view">
|
||||||
|
<field name="name">base_usability.res.users.tree</field>
|
||||||
|
<field name="model">res.users</field>
|
||||||
|
<field name="inherit_id" ref="base.view_users_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="login_date" position="after">
|
||||||
|
<field name="company_id" groups="base.group_multi_company"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user