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.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=_attachment_location_selection,
  33. string='Storage Location',
  34. required=True,
  35. help="Attachment storage location.")
  36. attachment_location_changed = fields.Boolean(
  37. compute='_compute_attachment_location_changed',
  38. string='Storage Location Changed')
  39. #----------------------------------------------------------
  40. # Functions
  41. #----------------------------------------------------------
  42. @api.multi
  43. def set_values(self):
  44. res = super(ResConfigSettings, self).set_values()
  45. param = self.env['ir.config_parameter'].sudo()
  46. param.set_param('ir_attachment.location', self.attachment_location)
  47. return res
  48. @api.model
  49. def get_values(self):
  50. res = super(ResConfigSettings, self).get_values()
  51. params = self.env['ir.config_parameter'].sudo()
  52. res.update(attachment_location=params.get_param('ir_attachment.location', 'file'))
  53. return res
  54. def attachment_force_storage(self):
  55. self.env['ir.attachment'].force_storage()
  56. #----------------------------------------------------------
  57. # Read
  58. #----------------------------------------------------------
  59. @api.depends('attachment_location')
  60. def _compute_attachment_location_changed(self):
  61. params = self.env['ir.config_parameter'].sudo()
  62. attachment_location = params.get_param('ir_attachment.location', 'file')
  63. for record in self:
  64. record.attachment_location_changed = attachment_location != self.attachment_location