Add script to fix partners related to users in multi-company setup where partners are NOT shared between companies
This commit is contained in:
committed by
Raphaël Valyi
parent
78915ccf95
commit
6b16063692
@@ -2,7 +2,10 @@
|
||||
# Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user