Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] integrator: new module #223

Open
wants to merge 4 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integrator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
44 changes: 44 additions & 0 deletions integrator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Odoo Integrator',
'version': "16.0.1.0.0",
'category': 'SaaS',
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'depends': [
'base', 'mail',
],
'data': [
'data/ir_server_action.xml',
'security/integrator_security.xml',
'security/ir.model.access.csv',
'views/ir_ui_menuitem.xml',
'views/integrator_account_views.xml',
'views/integrator_integration_views.xml',
'views/integrator_integration_script_views.xml',
],
'installable': True,
'auto_install': False,
'application': True,
'demo': [
],
}
14 changes: 14 additions & 0 deletions integrator/data/ir_server_action.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="action_cron_execution_call" model="ir.actions.server">
<field name="name">Adelantar ejecución de cron</field>
<field name="model_id" ref="integrator.model_integrator_integration"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
record.cron_id.sudo().write({'nextcall': datetime.datetime.now()})
</field>
</record>

</odoo>
4 changes: 4 additions & 0 deletions integrator/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import integrator_account
from . import integrator_integration_script
from . import integrator_integration
from . import integrator_integration_script_line
84 changes: 84 additions & 0 deletions integrator/models/integrator_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from odoo import api, models, fields, _
from odoo.exceptions import UserError
from odooly import Client
import logging
_logger = logging.getLogger(__name__)


class IntegratorAccount(models.Model):

_name = 'integrator.account'
_inherit = ['mail.composer.mixin', 'mail.thread', 'mail.activity.mixin']
_description = 'Integration Account'
_mailing_enabled = True

name = fields.Char(required=True, tracking=True, store=True, compute='_compute_name', default=lambda self: _('New'))
odoo_hostname = fields.Char("Hostname", required=True, tracking=True)
odoo_db_name = fields.Char("Database Name", required=True, tracking=True)
odoo_user = fields.Char("Username or E-Mail", required=True, tracking=True)
odoo_password = fields.Char("Password", required=True,)
state = fields.Selection([('draft', 'Draft'), ('confirmed', 'Confirmed')], copy=False, default='draft',
required=True, tracking=True)
channel_alias = fields.Char('Alias', default=False)

@api.depends('odoo_db_name')
def _compute_name(self):
for rec in self:
rec.name = rec.odoo_db_name

def back_to_draft(self):
self.write({'state': 'draft'})

def test_and_confirm(self):
self.test_connection()
self.write({'state': 'confirmed'})

def test_connection(self):
""" Odoo Connection Test.
Returns True if successful.
Raises a UserError otherwise.
"""
self.ensure_one()
try:
# Attempt to get client
client = self._odoo_get_client()
except Exception as e:
raise UserError("Unable to connect to Odoo. "
"The server responded: {}".format(str(e)))
# Make sure version is correct
self._odoo_ensure_version(client)
# Notify Success
result = "Connection with Odoo was successful!"
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('Success'),
'type': 'success',
'message': result,
'sticky': False,
}
}

def _odoo_get_client(self):
self.ensure_one()
try:
return Client(
# Use JSONRPC to prevent error when server responds with None
self.odoo_hostname.strip("/") + "/jsonrpc",
db=self.odoo_db_name,
user=self.odoo_user,
password=self.odoo_password,
)
except Exception as e:
raise UserError("Unable to Connect to Database. Error: %s" % e)

def _odoo_ensure_version(self, client):
""" Makes sure Odoo version is supported
"""
odoo_version = int(client.server_version.split(".")[0])
if odoo_version < 13:
raise UserError(
"The Odoo version on the remote system is not supported. "
"Please upgrade to v13.0 or higher")
return True
Loading