start of wazo bridge, no comm
This commit is contained in:
parent
737f3c0bd1
commit
c277ec4fe6
6 changed files with 162 additions and 0 deletions
1
wazo_integration/__init__.py
Normal file
1
wazo_integration/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
||||||
19
wazo_integration/__manifest__.py
Normal file
19
wazo_integration/__manifest__.py
Normal file
|
|
@ -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,
|
||||||
|
}
|
||||||
2
wazo_integration/models/__init__.py
Normal file
2
wazo_integration/models/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
from . import res_company
|
||||||
|
from . import res_config_settings
|
||||||
21
wazo_integration/models/res_company.py
Normal file
21
wazo_integration/models/res_company.py
Normal file
|
|
@ -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'
|
||||||
|
)
|
||||||
57
wazo_integration/models/res_config_settings.py
Normal file
57
wazo_integration/models/res_config_settings.py
Normal file
|
|
@ -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'))
|
||||||
62
wazo_integration/views/res_config_settings_views.xml
Normal file
62
wazo_integration/views/res_config_settings_views.xml
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<!--<odoo>-->
|
||||||
|
<!-- <record id="res_config_settings_view_form_inherit_wazo" model="ir.ui.view">-->
|
||||||
|
<!-- <field name="name">res.config.settings.inherit.wazo</field>-->
|
||||||
|
<!-- <field name="model">res.config.settings</field>-->
|
||||||
|
<!-- <field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>-->
|
||||||
|
<!-- <field name="arch" type="xml">-->
|
||||||
|
<!-- <xpath expr="//block[@name='integration']" position="inside">-->
|
||||||
|
<!-- <setting string="Wazo Configuration">-->
|
||||||
|
<!-- <div>-->
|
||||||
|
<!-- <div class="content-group mt16">-->
|
||||||
|
<!-- <label for="wazo_name" class="o_light_label mr8">Wazo Name</label>-->
|
||||||
|
<!-- <field name="wazo_name" placeholder="Enter Wazo Name"/>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- <div class="content-group mt16">-->
|
||||||
|
<!-- <label for="wazo_server_url" class="o_light_label mr8">Wazo Server URL</label>-->
|
||||||
|
<!-- <field name="wazo_server_url" placeholder="Enter Wazo Server URL"/>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- <div class="content-group mt16">-->
|
||||||
|
<!-- <label for="wazo_api_token" class="o_light_label mr8">Wazo API Token</label>-->
|
||||||
|
<!-- <field name="wazo_api_token" placeholder="Enter Wazo API Token"/>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- </setting>-->
|
||||||
|
<!-- </xpath>-->
|
||||||
|
<!-- </field>-->
|
||||||
|
<!-- </record>-->
|
||||||
|
<!--</odoo>-->
|
||||||
|
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
<record id="res_config_settings_view_form_inherit_wazo" model="ir.ui.view">
|
||||||
|
<field name="name">res.config.settings.inherit.wazo</field>
|
||||||
|
<field name="model">res.config.settings</field>
|
||||||
|
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//block[@name='integration']" position="inside">
|
||||||
|
<setting string="Wazo Configuration" name="wazo_settings">
|
||||||
|
<div class="row mt16 o_settings_container">
|
||||||
|
<div>
|
||||||
|
<div class="content-group mt16">
|
||||||
|
<label for="wazo_tenant" class="o_light_label mr8">Wazo Tenant</label>
|
||||||
|
<field name="wazo_tenant" placeholder="Enter Wazo Tenant"/>
|
||||||
|
</div>
|
||||||
|
<div class="content-group mt16">
|
||||||
|
<label for="wazo_server_url" class="o_light_label mr8">Wazo Server URL</label>
|
||||||
|
<field name="wazo_server_url" placeholder="Enter Wazo Server URL"/>
|
||||||
|
</div>
|
||||||
|
<div class="content-group mt16">
|
||||||
|
<label for="wazo_username" class="o_light_label mr8">Wazo Username</label>
|
||||||
|
<field name="wazo_username" placeholder="Enter Wazo Username"/>
|
||||||
|
</div>
|
||||||
|
<div class="content-group mt16">
|
||||||
|
<label for="wazo_password" class="o_light_label mr8">Wazo Password</label>
|
||||||
|
<field name="wazo_password" placeholder="Enter Wazo Password"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</setting>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in a new issue