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.

78 lines
3.3 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Web Utils
  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. import re
  23. import json
  24. import logging
  25. from lxml import etree
  26. from odoo import api, fields, models
  27. _logger = logging.getLogger(__name__)
  28. class ResConfigSettings(models.TransientModel):
  29. _inherit = 'res.config.settings'
  30. #----------------------------------------------------------
  31. # Database
  32. #----------------------------------------------------------
  33. binary_max_size = fields.Integer(
  34. string='File Size Limit',
  35. required=True,
  36. default=25,
  37. help="""Maximum allowed file size in megabytes. Note that this setting only adjusts
  38. the binary widgets accordingly. The maximum file size on your server can probably
  39. be restricted in several places. Note that a large file size limit and therefore
  40. large files in your system can significantly limit performance.""")
  41. #----------------------------------------------------------
  42. # Functions
  43. #----------------------------------------------------------
  44. def set_values(self):
  45. res = super(ResConfigSettings, self).set_values()
  46. param = self.env['ir.config_parameter'].with_user(self.env.ref('base.user_admin'))
  47. param.set_param('muk_web_utils.binary_max_size', self.binary_max_size)
  48. return res
  49. @api.model
  50. def get_values(self):
  51. res = super(ResConfigSettings, self).get_values()
  52. params = self.env['ir.config_parameter'].with_user(self.env.ref('base.user_admin'))
  53. res.update(binary_max_size=int(params.get_param('muk_web_utils.binary_max_size', 25)))
  54. return res
  55. @api.model
  56. def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
  57. ret_val = super(ResConfigSettings, self).fields_view_get(
  58. view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
  59. modules = self.env['ir.module.module'].with_user(self.env.ref('base.user_admin')).search([]).mapped('name')
  60. document = etree.XML(ret_val['arch'])
  61. for field in ret_val['fields']:
  62. if field.startswith("module_") and field[len("module_"):] not in modules:
  63. for node in document.xpath("//field[@name='%s']" % field):
  64. if node.get("widget") != 'upgrade_boolean':
  65. node.set("widget", "module_boolean")
  66. ret_val['arch'] = etree.tostring(document, encoding='unicode')
  67. return ret_val