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.1 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (C) 2017 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 api, fields, models
  20. class ResConfigSettings(models.TransientModel):
  21. _inherit = 'res.config.settings'
  22. #----------------------------------------------------------
  23. # Selections
  24. #----------------------------------------------------------
  25. def _attachment_location_selection(self):
  26. locations = self.env['ir.attachment'].storage_locations()
  27. return list(map(lambda location: (location, location.upper()), locations))
  28. #----------------------------------------------------------
  29. # Database
  30. #----------------------------------------------------------
  31. attachment_location = fields.Selection(
  32. selection=lambda self: self._attachment_location_selection(),
  33. string='Storage Location',
  34. required=True,
  35. default='file',
  36. help="Attachment storage location.")
  37. attachment_location_changed = fields.Boolean(
  38. compute='_compute_attachment_location_changed',
  39. string='Storage Location Changed')
  40. #----------------------------------------------------------
  41. # Functions
  42. #----------------------------------------------------------
  43. @api.multi
  44. def set_values(self):
  45. res = super(ResConfigSettings, self).set_values()
  46. param = self.env['ir.config_parameter'].sudo()
  47. param.set_param('ir_attachment.location', self.attachment_location)
  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'].sudo()
  53. res.update(attachment_location=params.get_param('ir_attachment.location', 'file'))
  54. return res
  55. def attachment_force_storage(self):
  56. self.env['ir.attachment'].force_storage()
  57. #----------------------------------------------------------
  58. # Read
  59. #----------------------------------------------------------
  60. @api.depends('attachment_location')
  61. def _compute_attachment_location_changed(self):
  62. params = self.env['ir.config_parameter'].sudo()
  63. location = params.get_param('ir_attachment.location', 'file')
  64. for record in self:
  65. record.attachment_location_changed = location != self.attachment_location