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.

68 lines
2.1 KiB

  1. # coding: utf-8
  2. # @ 2015 Valentin CHEMIERE @ Akretion
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, fields, api
  5. from ..tasks.filestore import FileStoreTask
  6. from ..tasks.ftp import FtpTask
  7. from ..tasks.sftp import SftpTask
  8. class Location(models.Model):
  9. _name = 'external.file.location'
  10. _description = 'Location'
  11. name = fields.Char(string='Name', required=True)
  12. protocol = fields.Selection(selection='_get_protocol', required=True)
  13. address = fields.Char(
  14. string='Address')
  15. filestore_rootpath = fields.Char(
  16. string='FileStore Root Path',
  17. help="Server's root path")
  18. port = fields.Integer()
  19. login = fields.Char()
  20. password = fields.Char()
  21. task_ids = fields.One2many('external.file.task', 'location_id')
  22. hide_login = fields.Boolean()
  23. hide_password = fields.Boolean()
  24. hide_port = fields.Boolean()
  25. company_id = fields.Many2one(
  26. 'res.company', 'Company',
  27. default=lambda self: self.env['res.company']._company_default_get(
  28. 'external.file.location'))
  29. @api.model
  30. def _get_classes(self):
  31. "surcharge this method to add new protocols"
  32. return {
  33. 'ftp': ('FTP', FtpTask),
  34. 'sftp': ('SFTP', SftpTask),
  35. 'file_store': ('File Store', FileStoreTask),
  36. }
  37. @api.model
  38. def _get_protocol(self):
  39. protocols = self._get_classes()
  40. selection = []
  41. for key, val in protocols.iteritems():
  42. selection.append((key, val[0]))
  43. return selection
  44. @api.onchange('protocol')
  45. def onchange_protocol(self):
  46. protocols = self._get_classes()
  47. if self.protocol:
  48. cls = protocols.get(self.protocol)[1]
  49. self.port = cls._default_port
  50. if cls._hide_login:
  51. self.hide_login = True
  52. else:
  53. self.hide_login = False
  54. if cls._hide_password:
  55. self.hide_password = True
  56. else:
  57. self.hide_password = False
  58. if cls._hide_port:
  59. self.hide_port = True
  60. else:
  61. self.hide_port = False