diff --git a/wazo_integration/__init__.py b/wazo_integration/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/wazo_integration/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/wazo_integration/__manifest__.py b/wazo_integration/__manifest__.py new file mode 100644 index 0000000..b56043b --- /dev/null +++ b/wazo_integration/__manifest__.py @@ -0,0 +1,19 @@ +{ + 'name': 'Wazo Configurator', + 'version': '17.0.0.1.0', + 'summary': 'Module to configure Wazo server from Odoo', + 'category': 'Tools', + 'author': 'Benoît Vézina', + 'website': 'http://www.bemade.org', + 'license': 'OPL-1', + 'depends': [ + 'base', + 'hr' + ], + 'data': [ + 'views/res_config_settings_views.xml' + ], + 'installable': True, + 'application': False, + 'auto_install': False, +} diff --git a/wazo_integration/models/__init__.py b/wazo_integration/models/__init__.py new file mode 100644 index 0000000..9e6feca --- /dev/null +++ b/wazo_integration/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_company +from . import res_config_settings \ No newline at end of file diff --git a/wazo_integration/models/res_company.py b/wazo_integration/models/res_company.py new file mode 100644 index 0000000..737ea79 --- /dev/null +++ b/wazo_integration/models/res_company.py @@ -0,0 +1,21 @@ +from odoo import models, fields + +class ResCompany(models.Model): + _inherit = 'res.company' + + wazo_active = fields.Char( + string='Wazo Tenant' + ) + + wazo_tenant = fields.Char( + string='Wazo Tenant' + ) + wazo_server_url = fields.Char( + string='Wazo Server URL' + ) + wazo_username = fields.Char( + string='Wazo Username' + ) + wazo_password = fields.Char( + string='Wazo Password' + ) diff --git a/wazo_integration/models/res_config_settings.py b/wazo_integration/models/res_config_settings.py new file mode 100644 index 0000000..83bf1af --- /dev/null +++ b/wazo_integration/models/res_config_settings.py @@ -0,0 +1,57 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError +import requests +import json + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + wazo_tenant = fields.Char( + related='company_id.wazo_tenant', + string='Wazo Tenant', + readonly=False + ) + wazo_server_url = fields.Char( + related='company_id.wazo_server_url', + string='Wazo Server URL', + readonly=False + ) + wazo_username = fields.Char( + related='company_id.wazo_username', + string='Wazo Username', + readonly=False + ) + wazo_password = fields.Char( + related='company_id.wazo_password', + string='Wazo Password', + readonly=False + ) + + def set_values(self): + super(ResConfigSettings, self).set_values() + company = self.env.user.company_id + url = self.wazo_server_url + username = self.wazo_username + password = self.wazo_password + tenant = self.wazo_tenant + if url and username and password and tenant: + try: + self._check_wazo_connection(url, username, password, tenant) + except ValidationError as e: + raise ValidationError(_("Failed to connect to Wazo server: %s") % e) + + def _check_wazo_connection(self, url, username, password, tenant): + payload = { + "backend": "wazo_user", + "expire": "3600", + "login": username, + "password": password, + } + headers = { + 'Content-Type': 'application/json', + 'Wazo-Tenant': tenant + } + response = requests.post(f"{url}/api/auth/0.1/token", headers=headers, json=payload, verify=False) + if response.status_code != 200: + raise ValidationError(response.json().get('message', 'Unknown error')) \ No newline at end of file diff --git a/wazo_integration/views/res_config_settings_views.xml b/wazo_integration/views/res_config_settings_views.xml new file mode 100644 index 0000000..9105a4e --- /dev/null +++ b/wazo_integration/views/res_config_settings_views.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + res.config.settings.inherit.wazo + res.config.settings + + + + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+
+