Files
odoo_source/addons/base_setup/models/res_config_settings.py
T
Christophe Simonis 886eca0131 [IMP] *: remove usage of oldname attribute
This attribute is misleading as it is insufficient to correctly upgrade
the database. It only renames the column in the database, but other
operations are needed, like updating the corresponding `ir.model.fields`
record (and its xmlid). The default values and the translations are also
lost during the upgrade.

Moreover, this feature was misused. It was:
 - left on fields during multiple versions.
 - used on reports (SQL views). This would be ok if the feature was
   complete, but, as is, it was useless.
 - kept unchanged after a second renaming of the field (which can happen
   versions later the first rename).
 - used, even when the meaning of the field changed. i.e. the field
   `archived` has been renamed to the classic `active`, but the value
   in the database should be switched.
2019-08-05 09:36:41 +00:00

105 lines
5.0 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
company_id = fields.Many2one('res.company', string='Company', required=True,
default=lambda self: self.env.company)
user_default_rights = fields.Boolean(
"Default Access Rights",
config_parameter='base_setup.default_user_rights')
external_email_server_default = fields.Boolean(
"External Email Servers",
config_parameter='base_setup.default_external_email_server')
module_base_import = fields.Boolean("Allow users to import data from CSV/XLS/XLSX/ODS files")
module_google_calendar = fields.Boolean(
string='Allow the users to synchronize their calendar with Google Calendar')
module_google_drive = fields.Boolean("Attach Google documents to any record")
module_google_spreadsheet = fields.Boolean("Google Spreadsheet")
module_auth_oauth = fields.Boolean("Use external authentication providers (OAuth)")
module_auth_ldap = fields.Boolean("LDAP Authentication")
module_base_gengo = fields.Boolean("Translate Your Website with Gengo")
module_inter_company_rules = fields.Boolean("Manage Inter Company")
module_pad = fields.Boolean("Collaborative Pads")
module_voip = fields.Boolean("Asterisk (VoIP)")
module_web_unsplash = fields.Boolean("Unsplash Image Library")
module_partner_autocomplete = fields.Boolean("Partner Autocomplete")
module_sms = fields.Boolean("Send SMS")
module_base_geolocalize = fields.Boolean("GeoLocalize")
company_share_partner = fields.Boolean(string='Share partners to all companies',
help="Share your partners to all companies defined in your instance.\n"
" * Checked : Partners are visible for every companies, even if a company is defined on the partner.\n"
" * Unchecked : Each company can see only its partner (partners where company is defined). Partners not related to a company are visible for all companies.")
report_footer = fields.Text(related="company_id.report_footer", string='Custom Report Footer', help="Footer text displayed at the bottom of all reports.", readonly=False)
group_multi_currency = fields.Boolean(string='Multi-Currencies',
implied_group='base.group_multi_currency',
help="Allows to work in a multi currency environment")
paperformat_id = fields.Many2one(related="company_id.paperformat_id", string='Paper format', readonly=False)
external_report_layout_id = fields.Many2one(related="company_id.external_report_layout_id", readonly=False)
show_effect = fields.Boolean(string="Show Effect", config_parameter='base_setup.show_effect')
company_count = fields.Integer('Number of Companies', readonly=True, compute="_compute_company_count")
language_count = fields.Integer('Number of Languages', compute="_compute_language_count")
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update({
'company_share_partner': not self.env.ref('base.res_partner_rule').active,
})
return res
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env.ref('base.res_partner_rule').write({'active': not self.company_share_partner})
def open_company(self):
return {
'type': 'ir.actions.act_window',
'name': 'My Company',
'view_mode': 'form',
'res_model': 'res.company',
'res_id': self.env.company.id,
'target': 'current',
}
def open_default_user(self):
action = self.env.ref('base.action_res_users').read()[0]
action['res_id'] = self.env.ref('base.default_user').id
action['views'] = [[self.env.ref('base.view_users_form').id, 'form']]
return action
@api.model
def _prepare_report_view_action(self, template):
template_id = self.env.ref(template)
return {
'type': 'ir.actions.act_window',
'res_model': 'ir.ui.view',
'view_mode': 'form',
'res_id': template_id.id,
}
def edit_external_header(self):
if not self.external_report_layout_id:
return False
return self._prepare_report_view_action(self.external_report_layout_id.key)
# NOTE: These fields depend on the context, if we want them to be computed
# we have to make them depend on a field. This is because we are on a TransientModel.
@api.depends('company_id')
def _compute_company_count(self):
company_count = self.env['res.company'].sudo().search_count([])
for record in self:
record.company_count = company_count
@api.depends('company_id')
def _compute_language_count(self):
language_count = self.env['res.lang'].search_count([
('active', '=', True),
])
for record in self:
record.language_count = language_count