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.

155 lines
6.0 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 api, fields, models
  23. class ResConfigSettings(models.TransientModel):
  24. _inherit = 'res.config.settings'
  25. #----------------------------------------------------------
  26. # Database
  27. #----------------------------------------------------------
  28. module_muk_web_branding = fields.Boolean(
  29. string="Web Branding",
  30. help="Customize the backend according to your needs.")
  31. module_muk_mail_branding = fields.Boolean(
  32. string="Mail Branding",
  33. help="Brand your outgoing mails with your own style.")
  34. module_muk_website_branding = fields.Boolean(
  35. string="Website Branding",
  36. help="Brand the website according to your needs.")
  37. module_muk_pos_branding = fields.Boolean(
  38. string="PoS Branding",
  39. help="Brand the PoS panel according to your needs.")
  40. branding_system_name = fields.Char(
  41. string='System Name')
  42. branding_publisher = fields.Char(
  43. string='Publisher')
  44. branding_website = fields.Char(
  45. string='Website URL')
  46. branding_documentation = fields.Char(
  47. string='Documentation URL')
  48. branding_support = fields.Char(
  49. string='Support URL')
  50. branding_store = fields.Char(
  51. string='Store URL')
  52. branding_share = fields.Char(
  53. string='Share URL')
  54. branding_company_name = fields.Char(
  55. string='Company Name',
  56. related='company_id.name',
  57. readonly=False)
  58. branding_company_logo = fields.Binary(
  59. string='Company Logo',
  60. related='company_id.logo',
  61. readonly=False)
  62. branding_company_favicon = fields.Binary(
  63. string='Company Favicon',
  64. related='company_id.favicon',
  65. readonly=False)
  66. #----------------------------------------------------------
  67. # Helper
  68. #----------------------------------------------------------
  69. @api.model
  70. def _delete_translations(self, value):
  71. self.env['ir.translation'].sudo().search([
  72. ('value', 'ilike', value)
  73. ]).unlink()
  74. #----------------------------------------------------------
  75. # Functions
  76. #----------------------------------------------------------
  77. @api.model
  78. def get_values(self):
  79. res = super(ResConfigSettings, self).get_values()
  80. params = self.env['ir.config_parameter'].sudo()
  81. res.update(params.get_branding_settings_params())
  82. return res
  83. @api.multi
  84. def set_values(self):
  85. translation_changed = False
  86. res = super(ResConfigSettings, self).set_values()
  87. params = self.env['ir.config_parameter'].sudo()
  88. values = params.get_branding_settings_params()
  89. if self.branding_system_name != values.get('branding_system_name'):
  90. self._delete_translations(values.get('branding_system_name'))
  91. translation_changed = True
  92. if self.branding_publisher != values.get('branding_publisher'):
  93. self._delete_translations(values.get('branding_publisher'))
  94. translation_changed = True
  95. if self.branding_website != values.get('branding_website'):
  96. self._delete_translations(values.get('branding_website'))
  97. translation_changed = True
  98. if self.branding_documentation != values.get('branding_documentation'):
  99. self._delete_translations(values.get('branding_documentation'))
  100. translation_changed = True
  101. if self.branding_support != values.get('branding_support'):
  102. self._delete_translations(values.get('branding_support'))
  103. translation_changed = True
  104. if self.branding_store != values.get('branding_store'):
  105. self._delete_translations(values.get('branding_store'))
  106. translation_changed = True
  107. if self.branding_share != values.get('branding_share'):
  108. self._delete_translations(values.get('branding_share'))
  109. translation_changed = True
  110. if translation_changed:
  111. self.env['ir.config_parameter'].set_params({
  112. 'muk_branding.system_name': self.branding_system_name or '',
  113. 'muk_branding.publisher': self.branding_publisher or '',
  114. 'muk_branding.website': self.branding_website or '',
  115. 'muk_branding.documentation': self.branding_documentation or '',
  116. 'muk_branding.support': self.branding_support or '',
  117. 'muk_branding.store': self.branding_store or '',
  118. 'muk_branding.share': self.branding_share or '',
  119. })
  120. self.translations_reload()
  121. return res
  122. def translations_reload(self):
  123. for lang in self.env['res.lang'].sudo().search([('active','=',True)]).mapped('code'):
  124. self.env['base.language.install'].sudo().create({
  125. 'lang': lang,
  126. 'overwrite': True
  127. }).lang_install()
  128. self.env['base.update.translations'].sudo().create({
  129. 'lang': lang
  130. }).act_update()
  131. self.env['ir.translation'].sudo().clear_caches