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.

79 lines
3.2 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. @api.multi
  45. def set_values(self):
  46. res = super(ResConfigSettings, self).set_values()
  47. param = self.env['ir.config_parameter'].sudo()
  48. param.set_param('muk_web_utils.binary_max_size', self.binary_max_size)
  49. return res
  50. @api.model
  51. def get_values(self):
  52. res = super(ResConfigSettings, self).get_values()
  53. params = self.env['ir.config_parameter'].sudo()
  54. res.update(binary_max_size=int(params.get_param('muk_web_utils.binary_max_size', 25)))
  55. return res
  56. @api.model
  57. def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
  58. ret_val = super(ResConfigSettings, self).fields_view_get(
  59. view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
  60. modules = self.env['ir.module.module'].sudo().search([]).mapped('name')
  61. document = etree.XML(ret_val['arch'])
  62. for field in ret_val['fields']:
  63. if field.startswith("module_") and field[len("module_"):] not in modules:
  64. for node in document.xpath("//field[@name='%s']" % field):
  65. if node.get("widget") != 'upgrade_boolean':
  66. node.set("widget", "module_boolean")
  67. ret_val['arch'] = etree.tostring(document, encoding='unicode')
  68. return ret_val