Skip to content

Commit

Permalink
[IMP] integrator: new module
Browse files Browse the repository at this point in the history
  • Loading branch information
augusto-weiss committed Nov 15, 2024
1 parent 51200e6 commit 0f21905
Show file tree
Hide file tree
Showing 16 changed files with 1,330 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integrator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# from .patch import *
from . import models
# from . import controllers
# from . import wizards
64 changes: 64 additions & 0 deletions integrator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
##############################################################################
#
# 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',
],
# Lo estamos agregando a la imagen ??
# 'external_dependencies': {
# 'python': [
# 'odooly',
# ],
# },
'data': [
# 'data/mail_message_subtype_data.xml',
'data/ir_server_action.xml',
# 'data/mail_templates.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',
# 'data/log_cleaning_cron.xml',
# 'data/integration_type_data.xml',
# 'wizards/integrator_account_wizard_view.xml',
],
# Este asset lo agregamos para poder usar html en las notificaciones usando el tag odumbo_notification
# En versiones futuras revisar si sigue siendo necesario, si no pasar a display_notification
# 'assets': {
# 'web.assets_backend': [
# 'integrator/static/src/webclient/actions/client_action.js',
# ]
# },
# Esto no lo agrego porque entiendo ya lo hacemos en repo de odooly
# 'post_load': 'patch_odooly',
'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
114 changes: 114 additions & 0 deletions integrator/models/integrator_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
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):
# for rec in self:
# _logger.info("Testing Connection on '%s'" % (rec.name))
# if hasattr(rec, '%s_test_connection' % rec.account_type):
# getattr(rec, '%s_test_connection' % rec.account_type)()
# else:
# _logger.warning("Account '%s' has no test method!" %
# rec.account_type)

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

# def _get_alias(self):
# if not self.channel_alias:
# odoo = self._odoo_get_client()
# channel = odoo.env.ref("__integrator__.odumbo_channel")
# channel_id = channel.id if channel else False
# if not channel:
# fields = ['id', 'name', 'description']
# data = ["__integrator__.odumbo_channel", 'Odumbo', 'Errors communicated by Odumbo integrations']
# channel = odoo.env['mail.channel'].load(fields, [data])
# channel_id = channel.get('ids')[0]

# alias = odoo.env.ref("__integrator__.odumbo_channel_alias")
# if not alias:
# fields = ['id', 'alias_name', 'alias_model_id/.id', 'alias_force_thread_id']
# data = ["__integrator__.odumbo_channel_alias", 'odumbo', odoo.env.ref("mail.model_mail_channel").id, channel_id]
# alias = odoo.env['mail.alias'].load(fields, [data])
# alias_id = alias.get('ids')[0]
# alias = odoo.env['mail.alias'].browse(alias_id)
# self.channel_alias = alias.name_get()[1]
# return self.channel_alias
Loading

0 comments on commit 0f21905

Please sign in to comment.