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.

51 lines
1.7 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 .abstract_task import AbstractTask
  6. from .helper import itersubclasses
  7. class Location(models.Model):
  8. _name = 'external.file.location'
  9. _description = 'Description'
  10. name = fields.Char(string='Name', required=True)
  11. protocol = fields.Selection(selection='_get_protocol', required=True)
  12. address = fields.Char(string='Address', required=True)
  13. port = fields.Integer()
  14. login = fields.Char()
  15. password = fields.Char()
  16. task_ids = fields.One2many('external.file.task', 'location_id')
  17. hide_login = fields.Boolean()
  18. hide_password = fields.Boolean()
  19. hide_port = fields.Boolean()
  20. def _get_protocol(self):
  21. res = []
  22. for cls in itersubclasses(AbstractTask):
  23. if not cls._synchronize_type:
  24. cls_info = (cls._key, cls._name)
  25. res.append(cls_info)
  26. elif not cls._synchronize_type and cls._key and cls._name:
  27. pass
  28. return res
  29. @api.onchange('protocol')
  30. def onchange_protocol(self):
  31. for cls in itersubclasses(AbstractTask):
  32. if cls._key == self.protocol:
  33. self.port = cls._default_port
  34. if cls._hide_login:
  35. self.hide_login = True
  36. else:
  37. self.hide_login = False
  38. if cls._hide_password:
  39. self.hide_password = True
  40. else:
  41. self.hide_password = False
  42. if cls._hide_port:
  43. self.hide_port = True
  44. else:
  45. self.hide_port = False