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.

38 lines
1.3 KiB

  1. '''
  2. Created on 25 nov. 2014
  3. @author: openerp
  4. '''
  5. from openerp import models, fields, api
  6. import openerplib
  7. from openerp.exceptions import Warning
  8. class odoo_connection_data(models.Model):
  9. _name = 'import.odoo.connection'
  10. name = fields.Char("Name", required=True)
  11. host = fields.Char("Host", required=True)
  12. port = fields.Integer("Port", required=True, default=8069)
  13. database = fields.Char("Database", required=True)
  14. user = fields.Char("Login", required=True, default="admin")
  15. password = fields.Char("Password", required=True)
  16. protocol = fields.Selection([('xmlrpc', 'Xmlrpc'), ('jsonrpc', 'Jsonrpc'),('xmlrpcs', 'Xmlrpcs'), ('jsonrpcs', 'Jsonrpcs')], string="Protocol", default="xmlrpc")
  17. active = fields.Boolean("Active", default=True)
  18. @api.multi
  19. def test_connection(self):
  20. connection = self._get_connection()
  21. connection.check_login(force=True)
  22. raise Warning("Connection Successful")
  23. def _get_connection(self):
  24. return openerplib.get_connection(hostname=self.host,
  25. port=self.port,
  26. database=self.database,
  27. login=self.user,
  28. password=self.password,
  29. protocol=self.protocol)