[ADD] Data BI

This commit is contained in:
Jose Luis
2019-04-29 12:55:54 +02:00
parent adbab85ced
commit 7dbe789e01
12 changed files with 382 additions and 0 deletions

74
hotel_data_bi/README.rst Normal file
View File

@@ -0,0 +1,74 @@
REVENUE EXPORTER
=============
Export Odoo data for Revenue MyDataBI
Usage
=======
To use this module, you need to:
Create a user and give the "Hotel Management / Export data BI" permission.
To connect to Odoo via xmlrpc there are examples in https://www.odoo.com/documentation/10.0/api_integration.html in the "Calling methods" section with examples in several languages.
A python example:
import xmlrpclib
url = 'https://www.example.org'
username = 'username@example.org'
password = '123passwordexample'
db = 'example_db_name'
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password,'data_bi','export_data_bi', [ 8, '2018-01-01'])
In the parameters of export_data_bi:
archivo == 1 'Tarifa'
archivo == 2 'Canal'
archivo == 3 'Hotel'
archivo == 4 'Pais'
archivo == 5 'Regimen'
archivo == 6 'Reservas'
archivo == 7 'Capacidad'
archivo == 8 'Tipo Habitación'
archivo == 9 'Budget'
archivo == 10 'Bloqueos'
archivo == 11 'Motivo Bloqueo'
archivo == 12 'Segmentos'
archivo == 13 'Clientes'
archivo == 14 'Estado Reservas'
fechafoto = start date to take data
in the example recive 8 'Tipo Habitación' from '2018-01-01'
Credits
=======
Creator
------------
* Jose Luis Algara (Alda hotels) <osotranquilo@gmail.com>

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright 2018-2019 Jose Luis Algara Toledo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Hotel Data Bi',
'description': """
Export hotel data for business intelligence
To use this module you need to:
Create a user and give the 'Hotel Management/Export data BI' permission.
""",
'summary': "Export hotel data for business intelligence",
'version': '2.0',
'license': 'AGPL-3',
'author': "Jose Luis Algara (Alda hotels) <osotranquilo@gmail.com>",
'website': 'www.aldahotels.com',
'depends': ['hotel', 'hotel_l10n_es'],
'category': 'hotel/revenue',
'data': [
'views/budget.xml',
'views/inherit_res_company.xml',
'security/data_bi.xml',
'security/ir.model.access.csv',
],
'demo': [
],
'installable': True,
'auto_install': False,
'application': False,
}

View File

@@ -0,0 +1,3 @@
from . import inherit_res_company
from . import budget
from . import data_bi

View File

@@ -0,0 +1,48 @@
# Copyright 2019 Jose Luis Algara (Alda hotels) <osotranquilo@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from datetime import date
def get_years():
"""Return a year list, to select in year field."""
year_list = []
for i in range(2018, 2036):
year_list.append((i, str(i)))
return year_list
class Budget(models.Model):
"""Establish and save the budget for DataBI control by revenue"""
_name = 'budget'
# fecha Primer día del mes
month = fields.Selection([(1, 'January'), (2, 'February'), (3, 'March'),
(4, 'April'), (5, 'May'), (6, 'June'),
(7, 'July'), (8, 'August'), (9, 'September'),
(10, 'October'), (11, 'November'),
(12, 'December'), ],
string='Month', required=True)
year = fields.Selection(get_years(), string='Year', required=True)
room_nights = fields.Float("Room Nights", required=True, digits=(6, 2))
# Número de Room Nights
room_revenue = fields.Float("Room Revenue", required=True, digits=(6, 2))
# Ingresos por Reservas
estancias = fields.Integer("Number of Stays") # Número de Estancias
# ID_Tarifa numérico Código de la Tarifa
# ID_Canal numérico Código del Canal
# ID_Pais numérico Código del País
# ID_Regimen numérico Cóigo del Régimen
# ID_Tipo_Habitacion numérico Código del Tipo de Habitación
# iD_Segmento numérico Código del Segmento
# ID_Cliente numérico Código del Cliente
# Pension_Revenue numérico con dos decimales Ingresos por Pensión
@api.model
def export_data_bi(self,
archivo=False,
fechafoto=date.today().strftime('%Y-%m-%d')):
apidata = self.env['data_bi']
return apidata.export_data_bi(self)

View File

@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2018 -2019 Alda Hotels <informatica@aldahotels.com>
# Jose Luis Algara <osotranquilo@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api, _
from datetime import date, datetime, timedelta
import json
import logging
_logger = logging.getLogger(__name__)
def inv_percent(amount, percent):
"""Return the amount to which a percentage was applied."""
return round(amount*(100/float(100-percent)) - amount, 2)
class Data_Bi(models.Model):
"""Management and export data for MopSolution MyDataBI."""
_name = 'data_bi'
@api.model
def export_data_bi(self,
archivo=False,
fechafoto=date.today().strftime('%Y-%m-%d')):
u"""Prepare a Json Objet to export data for MyDataBI.
Generate a dicctionary to by send in JSON
archivo = response file type
archivo == 1 'Tarifa'
archivo == 2 'Canal'
archivo == 3 'Hotel'
archivo == 4 'Pais'
archivo == 5 'Regimen'
archivo == 6 'Reservas'
archivo == 7 'Capacidad'
archivo == 8 'Tipo Habitación'
archivo == 9 'Budget'
archivo == 10 'Bloqueos'
archivo == 11 'Motivo Bloqueo'
archivo == 12 'Segmentos'
archivo == 13 'Clientes'
archivo == 14 'Estado Reservas'
fechafoto = start date to take data
"""
if type(fechafoto) is dict:
fechafoto = date.today()
else:
fechafoto = datetime.strptime(fechafoto, '%Y-%m-%d').date()
_logger.warning("Init Export Data_Bi Module")
dic_export = [] # Diccionario con todo lo necesario para exportar.
# if (archivo == 0) or (archivo == 1):
# dic_export.append({'Tarifa': dic_tarifa})
# if (archivo == 0) or (archivo == 2):
# dic_export.append({'Canal': dic_canal})
# if (archivo == 0) or (archivo == 3):
# dic_export.append({'Hotel': dic_hotel})
# if (archivo == 0) or (archivo == 4):
# dic_export.append({'Pais': dic_pais})
# if (archivo == 0) or (archivo == 5):
# dic_export.append({'Regimen': dic_regimen})
# if (archivo == 0) or (archivo == 6):
# dic_export.append({'Reservas': dic_reservas})
# if (archivo == 0) or (archivo == 7):
# dic_export.append({'Capacidad': dic_capacidad})
# if (archivo == 0) or (archivo == 8):
# dic_export.append({'Tipo Habitación': dic_tipo_habitacion})
# if (archivo == 0) or (archivo == 9):
# dic_export.append({'Budget': dic_budget})
# if (archivo == 0) or (archivo == 10):
# dic_export.append({'Bloqueos': dic_bloqueos})
# if (archivo == 0) or (archivo == 11):
# dic_export.append({'Motivo Bloqueo': dic_moti_bloq})
# if (archivo == 0) or (archivo == 12):
# dic_export.append({'Segmentos': dic_segmentos})
# if (archivo == 0) or (archivo == 13):
# dic_export.append({'Clientes': dic_clientes})
# if (archivo == 0) or (archivo == 14):
# dic_export.append({'Estado Reservas': dic_estados})
dictionaryToJson = json.dumps(dic_export)
_logger.warning("End Export Data_Bi Module to Json")
# Debug Stop -------------------
# import wdb; wdb.set_trace()
# Debug Stop -------------------
return dictionaryToJson

View File

@@ -0,0 +1,13 @@
# Copyright 2019 Jose Luis Algara (Alda hotels) <osotranquilo@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class Inherit_res_company(models.Model):
_inherit = 'res.company'
id_hotel = fields.Integer(
'Unique ID for DataBI', default=0,
help='It must be unique to be able to identify the hotel, \
within a hotel group.')

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--Group for hotel export data bi -->
<record id="group_hotel_export_data" model="res.groups">
<field name="name">Hotel Management / Export data BI</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
ir_model_hotel_budget,hoteldatabi.budget.manager,hotel_data_bi.model_budget,hotel.group_hotel_manager,1,1,1,1
ir_model_hotel_budget_user,hoteldatabi.budget.user,hotel_data_bi.model_budget,hotel.group_hotel_user,0,0,0,0
ir_model_hotel_data_bi_export_data,hoteldatabi.data_bi.export_data,hotel_data_bi.model_data_bi,hotel_data_bi.group_hotel_export_data,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 ir_model_hotel_budget hoteldatabi.budget.manager hotel_data_bi.model_budget hotel.group_hotel_manager 1 1 1 1
3 ir_model_hotel_budget_user hoteldatabi.budget.user hotel_data_bi.model_budget hotel.group_hotel_user 0 0 0 0
4 ir_model_hotel_data_bi_export_data hoteldatabi.data_bi.export_data hotel_data_bi.model_data_bi hotel_data_bi.group_hotel_export_data 1 0 0 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 Jose Luis Algara (Alda hotels) <osotranquilo@gmail.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<act_window
id="budget_act_window"
name="Budget for DataBI"
res_model="budget"
view_mode="tree,form"
/>
<menuitem
id="budget_menu"
name="Budget for DataBI"
parent="hotel.configuration_others"
sequence="36"
action="budget_act_window"
groups="hotel.group_hotel_manager"
/>
<record model="ir.ui.view" id="budget_form_view">
<field name="name">budget.form (in hotel_data_bi)</field>
<field name="model">budget</field>
<field name="arch" type="xml">
<form>
<sheet>
<group string="Hotel Budget:" colspan="1">
<group name="group_top">
<group>
<div>
<label for="month" string="Period:"
style="font-weight: bold !important;margin-right:107px;margin-left: 0px;"/>
<field name="month" style="width:110px"/>
<field name="year" style="width:110px;margin-left: 34px;"/>
</div>
</group>
<group>
<field name="room_nights"/>
<field name="room_revenue"/>
<field name="estancias"/>
</group>
</group>
</group>
<div>
<button name="export_data_bi" class="oe_form_button_save btn btn-primary btn-sm" type="object" string="Generate Conexion"
groups="base.group_system"/>
</div>
</sheet>
<div class="oe_chatter"></div>
</form>
</field>
</record>
<record model="ir.ui.view" id="budget_tree_view">
<field name="name">budget.tree (in hotel_data_bi)</field>
<field name="model">budget</field>
<field name="arch" type="xml">
<tree>
<field name="month"/>
<field name="year"/>
<field name="room_nights"/>
<field name="room_revenue"/>
<field name="estancias"/>
</tree>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Hotel Settings -->
<data>
<!-- Inherit Company view to add 'Hotel dataBI' -->
<record id="data_bi_view_company_form" model="ir.ui.view">
<field name="name">databi.config.view_company_form</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='cardex_warning']" position="after">
<field name="id_hotel" />
</xpath>
</field>
</record>
</data>
</odoo>