You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
4.3 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Branding
  6. # (see https://mukit.at).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###################################################################################
  22. from odoo import _, models, api
  23. from odoo.modules import get_resource_path
  24. from odoo.tools import mute_logger, ormcache, config
  25. BRANDING_PARAMS = {
  26. 'muk_branding.system_name': config.get('branding_system_name', 'System'),
  27. 'muk_branding.publisher': config.get('branding_publisher', 'Example'),
  28. 'muk_branding.website': config.get('branding_website', 'https://www.example.com'),
  29. 'muk_branding.documentation': config.get('branding_documentation', 'https://www.example.com'),
  30. 'muk_branding.support': config.get('branding_support', 'https://www.example.com/support'),
  31. 'muk_branding.store': config.get('branding_store', 'https://www.example.com/store'),
  32. 'muk_branding.share': config.get('branding_share', 'https://www.example.com'),
  33. }
  34. class IrConfigParameter(models.Model):
  35. _inherit = 'ir.config_parameter'
  36. @api.model_cr
  37. @mute_logger('odoo.addons.base.models.ir_config_parameter')
  38. def init(self, force=False):
  39. super(IrConfigParameter, self).init(force=force)
  40. for key, value in BRANDING_PARAMS.items():
  41. if force or not self.sudo().search([('key', '=', key)]):
  42. self.sudo().set_param(key, value() if callable(value) else value)
  43. @api.model
  44. def get_branding_param(self, key, default=""):
  45. return self.sudo().get_param(key, default=default) if key in BRANDING_PARAMS else None
  46. @api.model
  47. @ormcache()
  48. def get_branding_params(self):
  49. return {key: self.get_branding_param(key) for key in BRANDING_PARAMS}
  50. @api.model
  51. @ormcache()
  52. def get_branding_settings_params(self):
  53. return {
  54. 'branding_system_name': self.get_branding_param('muk_branding.system_name'),
  55. 'branding_publisher': self.get_branding_param('muk_branding.publisher'),
  56. 'branding_website': self.get_branding_param('muk_branding.website'),
  57. 'branding_documentation': self.get_branding_param('muk_branding.documentation'),
  58. 'branding_support': self.get_branding_param('muk_branding.support'),
  59. 'branding_store': self.get_branding_param('muk_branding.store'),
  60. 'branding_share': self.get_branding_param('muk_branding.share'),
  61. }
  62. @api.model
  63. @ormcache()
  64. def get_branding_dashboard_params(self):
  65. return {
  66. 'store': self.get_branding_param('muk_branding.store'),
  67. 'share': self.get_branding_param('muk_branding.share'),
  68. 'system': self.get_branding_param('muk_branding.system_name'),
  69. 'publisher': self.get_branding_param('muk_branding.publisher'),
  70. }
  71. @api.model
  72. @ormcache()
  73. def get_branding_session_params(self):
  74. return {
  75. 'muk_branding_system_name': self.get_branding_param('muk_branding.system_name'),
  76. 'muk_branding_documentation': self.get_branding_param('muk_branding.documentation'),
  77. 'muk_branding_website': self.get_branding_param('muk_branding.website'),
  78. 'muk_branding_support': self.get_branding_param('muk_branding.support')
  79. }
  80. @api.model
  81. @ormcache()
  82. def get_branding_debrand_params(self):
  83. return {
  84. 'system_name': self.get_branding_param('muk_branding.system_name'),
  85. 'documentation': self.get_branding_param('muk_branding.documentation'),
  86. 'website': self.get_branding_param('muk_branding.website'),
  87. }