odoo_management_config.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, models, fields
  3. class OdooManagementConfig(models.TransientModel):
  4. _inherit = 'res.config.settings'
  5. _name = 'odoo.management.config'
  6. field_types = (
  7. ('docker_socket_path', 'char'),
  8. ('docker_exclusion_list', 'list'),
  9. ('odoo_docker_image', 'char'),
  10. ('odoo_network', 'char'),
  11. ('odoo_ports_range', 'list'),
  12. ('odoo_root_path', 'char'),
  13. ('odoo_db_link', 'char'),
  14. ('modules_git_path', 'char'),
  15. )
  16. docker_socket_path = fields.Char(string='Socket', size=100, default='/var/run/docker.sock')
  17. docker_exclusion_list = fields.Char(string='Lista de exclusión', size=160)
  18. odoo_docker_image = fields.Char(string='Imagen docker', size=50)
  19. odoo_network = fields.Char(string='Red virtual', size=50, default='eiru')
  20. odoo_ports_range = fields.Char(string='Rango de puertos', size=50)
  21. odoo_root_path = fields.Char(string='Ruta raíz', size=50, default='/opt/odoo')
  22. odoo_db_link = fields.Char(string='Base de datos', size=50, default='db')
  23. modules_git_path = fields.Char(string='Ruta del repositorio', size=100, default='/opt/gogs/git/gogs-repositories')
  24. @api.multi
  25. def set_default_settings(self, values):
  26. ir_values_obj = self.env['ir.values']
  27. types = dict(self.field_types)
  28. for v in values:
  29. value = None
  30. if types[v] == 'char':
  31. value = values[v]
  32. if types[v] == 'list':
  33. value = ','.join(map(lambda x: x.strip(), values[v]))
  34. value = value or ''
  35. ir_values_obj.set_default('odoo.instance', v, value)
  36. @api.model
  37. def get_default_settings(self, fields):
  38. ir_values = self.env['ir.values'].get_defaults_dict('odoo.instance')
  39. types = dict(self.field_types)
  40. defaults = {}
  41. for v in ir_values:
  42. value = None
  43. if types[v] == 'char':
  44. value = ir_values[v]
  45. if types[v] == 'list':
  46. value = filter(lambda x: x != '', ir_values[v].split(','))
  47. defaults[v] = value or ''
  48. return defaults