Private methods for scripts
Use sudo() in scripts that require admin access
This commit is contained in:
@@ -121,7 +121,8 @@ class AccountInvoice(models.Model):
|
|||||||
lines.unlink()
|
lines.unlink()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def fix_invoice_attachment_filename(self):
|
@api.model
|
||||||
|
def _fix_invoice_attachment_filename(self):
|
||||||
# This script is designed to fix attachment of invoices
|
# This script is designed to fix attachment of invoices
|
||||||
# badly generated by Odoo v8. I found this problem in Nov 2018 at
|
# badly generated by Odoo v8. I found this problem in Nov 2018 at
|
||||||
# Encres Dubuit when investigating a bug where Odoo would create a
|
# Encres Dubuit when investigating a bug where Odoo would create a
|
||||||
@@ -240,19 +241,19 @@ class AccountAccount(models.Model):
|
|||||||
return super(AccountAccount, self).name_get()
|
return super(AccountAccount, self).name_get()
|
||||||
|
|
||||||
# https://github.com/odoo/odoo/issues/23040
|
# https://github.com/odoo/odoo/issues/23040
|
||||||
def fix_bank_account_types(self):
|
@api.model
|
||||||
aao = self.env['account.account']
|
def _fix_bank_account_types(self):
|
||||||
companies = self.env['res.company'].search([])
|
companies = self.env['res.company'].search([])
|
||||||
if len(companies) > 1 and self.env.user.id != SUPERUSER_ID:
|
if len(companies) > 1 and self.env.user.id != SUPERUSER_ID:
|
||||||
raise UserError(
|
logger.info(
|
||||||
"In multi-company setups, you should run this "
|
"Multi-company setup detected, running script with sudo ")
|
||||||
"script as admin user")
|
self = self.sudo()
|
||||||
logger.info("START the script 'fix bank and cash account types'")
|
logger.info("START the script 'fix bank and cash account types'")
|
||||||
bank_type = self.env.ref('account.data_account_type_liquidity')
|
bank_type = self.env.ref('account.data_account_type_liquidity')
|
||||||
asset_type = self.env.ref('account.data_account_type_current_assets')
|
asset_type = self.env.ref('account.data_account_type_current_assets')
|
||||||
journals = self.env['account.journal'].search(
|
journals = self.env['account.journal'].search(
|
||||||
[('type', 'in', ('bank', 'cash'))], order='company_id')
|
[('type', 'in', ('bank', 'cash'))], order='company_id')
|
||||||
journal_accounts_bank_type = aao
|
journal_accounts_bank_type = self
|
||||||
for journal in journals:
|
for journal in journals:
|
||||||
for account in [
|
for account in [
|
||||||
journal.default_credit_account_id,
|
journal.default_credit_account_id,
|
||||||
@@ -266,7 +267,7 @@ class AccountAccount(models.Model):
|
|||||||
account.company_id.display_name, account.code)
|
account.company_id.display_name, account.code)
|
||||||
if account not in journal_accounts_bank_type:
|
if account not in journal_accounts_bank_type:
|
||||||
journal_accounts_bank_type += account
|
journal_accounts_bank_type += account
|
||||||
accounts = aao.search([
|
accounts = self.search([
|
||||||
('user_type_id', '=', bank_type.id)], order='company_id, code')
|
('user_type_id', '=', bank_type.id)], order='company_id, code')
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
if account not in journal_accounts_bank_type:
|
if account not in journal_accounts_bank_type:
|
||||||
@@ -278,7 +279,7 @@ class AccountAccount(models.Model):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create_account_groups(self, level=2, name_prefix=u'Comptes '):
|
def _create_account_groups(self, level=2, name_prefix=u'Comptes '):
|
||||||
'''Should be launched by a script. Make sure the account_group module is installed
|
'''Should be launched by a script. Make sure the account_group module is installed
|
||||||
(the account_usability module doesn't depend on it currently'''
|
(the account_usability module doesn't depend on it currently'''
|
||||||
assert level >= 1
|
assert level >= 1
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class ResUsers(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def _script_partners_linked_to_users_no_company(self):
|
def _script_partners_linked_to_users_no_company(self):
|
||||||
if self.env.user.id != SUPERUSER_ID:
|
if self.env.user.id != SUPERUSER_ID:
|
||||||
raise UserError(_('You must run this script as admin user'))
|
self = self.sudo()
|
||||||
logger.info(
|
logger.info(
|
||||||
'START to set company_id=False on partners related to users')
|
'START to set company_id=False on partners related to users')
|
||||||
users = self.search(
|
users = self.search(
|
||||||
|
|||||||
Reference in New Issue
Block a user