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.

103 lines
4.4 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 set_params(self, params):
  45. for key, value in params.items():
  46. self.set_param(key, value)
  47. @api.model
  48. def get_branding_param(self, key, default=""):
  49. return self.sudo().get_param(key, default=default) if key in BRANDING_PARAMS else None
  50. @api.model
  51. @ormcache()
  52. def get_branding_params(self):
  53. return {key: self.get_branding_param(key) for key in BRANDING_PARAMS}
  54. @api.model
  55. @ormcache()
  56. def get_branding_settings_params(self):
  57. return {
  58. 'branding_system_name': self.get_branding_param('muk_branding.system_name'),
  59. 'branding_publisher': self.get_branding_param('muk_branding.publisher'),
  60. 'branding_website': self.get_branding_param('muk_branding.website'),
  61. 'branding_documentation': self.get_branding_param('muk_branding.documentation'),
  62. 'branding_support': self.get_branding_param('muk_branding.support'),
  63. 'branding_store': self.get_branding_param('muk_branding.store'),
  64. 'branding_share': self.get_branding_param('muk_branding.share'),
  65. }
  66. @api.model
  67. @ormcache()
  68. def get_branding_dashboard_params(self):
  69. return {
  70. 'store': self.get_branding_param('muk_branding.store'),
  71. 'share': self.get_branding_param('muk_branding.share'),
  72. 'system': self.get_branding_param('muk_branding.system_name'),
  73. 'publisher': self.get_branding_param('muk_branding.publisher'),
  74. }
  75. @api.model
  76. @ormcache()
  77. def get_branding_session_params(self):
  78. return {
  79. 'muk_branding_system_name': self.get_branding_param('muk_branding.system_name'),
  80. 'muk_branding_documentation': self.get_branding_param('muk_branding.documentation'),
  81. 'muk_branding_website': self.get_branding_param('muk_branding.website'),
  82. 'muk_branding_support': self.get_branding_param('muk_branding.support')
  83. }
  84. @api.model
  85. @ormcache()
  86. def get_branding_debrand_params(self):
  87. return {
  88. 'system_name': self.get_branding_param('muk_branding.system_name'),
  89. 'documentation': self.get_branding_param('muk_branding.documentation'),
  90. 'website': self.get_branding_param('muk_branding.website'),
  91. }