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.

63 lines
2.4 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=_attachment_location_selection,
  33. string='Storage Location',
  34. required=True,
  35. help="Attachment storage location.")
  36. #----------------------------------------------------------
  37. # Functions
  38. #----------------------------------------------------------
  39. @api.multi
  40. def set_values(self):
  41. res = super(ResConfigSettings, self).set_values()
  42. param = self.env['ir.config_parameter'].sudo()
  43. param.set_param('ir_attachment.location', self.attachment_location)
  44. return res
  45. @api.model
  46. def get_values(self):
  47. res = super(ResConfigSettings, self).get_values()
  48. params = self.env['ir.config_parameter'].sudo()
  49. res.update(attachment_location=params.get_param('ir_attachment.location', 'file'))
  50. return res
  51. @api.multi
  52. def attachment_force_storage(self):
  53. self.env['ir.attachment'].force_storage()