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.

95 lines
4.3 KiB

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