Skip to content

Commit

Permalink
Merge pull request #1 from open2bizz/10.0
Browse files Browse the repository at this point in the history
Update van eigen fork
  • Loading branch information
dochse authored Jan 2, 2018
2 parents 23cc1ad + fa62e39 commit 7504def
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
orbeon/services/persistence_server/*.cfg
*.pyc
1 change: 1 addition & 0 deletions orbeon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
import models
import services
import tests
import controllers
21 changes: 21 additions & 0 deletions orbeon/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# open2bizz
# Copyright (C) 2016 open2bizz (open2bizz.nl).
#
# 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/>.
#
##############################################################################
from . import orbeon
70 changes: 70 additions & 0 deletions orbeon/controllers/orbeon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) 2016 - Open2bizz
# Author: Open2bizz
#
# 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.
#
# A copy of the GNU General Public License is available at:
# <http://www.gnu.org/licenses/gpl.html>.
#
##############################################################################
import requests
from urlparse import urlparse
from werkzeug.wrappers import Response
from odoo import http
import base64
from odoo.tools import config
import logging
logger = logging.getLogger(__name__)

class Orbeon(http.Controller):
orbeon_base_route = 'orbeon'

@http.route('/%s/<path:path>' % orbeon_base_route, type='http', auth="user", csrf=False)
def render_orbeon_page(self, path, redirect=None, **kw):
orbeon_server = http.request.env["orbeon.server"].search_read([], ['url'])
if len(orbeon_server) == 0:
return 'Orbeon server not found'
else :
orbeon_server = orbeon_server[0]
o = urlparse(orbeon_server['url'])

odoo_session = http.request.session

orbeon_headers = ['cookie']
in_headers = { name : value for (name, value) in http.request.httprequest.headers.items()
if name.lower() in orbeon_headers}

in_headers.update({'Openerp-Server' : 'localhost'})
in_headers.update({'Openerp-Port' : str(config.get('xmlrpc_port'))})
in_headers.update({'Openerp-Database' : odoo_session.get('db') })
in_headers.update({'Authorization' : 'Basic %s' % base64.b64encode("%s:%s" % (odoo_session.get('login'), odoo_session.get('password')) ) } )

logger.debug('Calling Orbeon on url %s with header %s' % (o.netloc, in_headers))
curl = urlparse(http.request.httprequest.url)._replace(netloc=o.netloc)

resp = requests.request(
method=http.request.httprequest.method,
url=curl.geturl(),
headers=in_headers,
data=http.request.httprequest.get_data(),
#cookies=http.request.httprequest.cookies,
allow_redirects=False)

excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection'
, 'openerp-server', 'openerp-port', 'openerp-database', 'authorization' ]
headers = [(name, value) for (name, value) in resp.raw.headers.items()
if name.lower() not in excluded_headers]

response = Response(resp.content, resp.status_code, headers)
return response

2 changes: 1 addition & 1 deletion orbeon/i18n/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ msgstr "Start persistence"
#: model:ir.model.fields,field_description:orbeon.field_orbeon_builder_state
#: model:ir.model.fields,field_description:orbeon.field_orbeon_runner_state
msgid "State"
msgstr "Staat / Provincie"
msgstr "Status"

#. module: orbeon
#: model:ir.ui.view,arch_db:orbeon.orbeon_server_form
Expand Down
2 changes: 1 addition & 1 deletion orbeon/models/orbeon_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _get_url(self):
else:
builder_id = self.id

builder_url = "%s/%s" % (self.server_id.url, "fr/orbeon/builder")
builder_url = "/orbeon/%s" % ("fr/orbeon/builder")
get_mode = {STATE_NEW: 'edit'}
url = "%s/%s/%i" % (builder_url, get_mode.get(self.state, 'view'), builder_id)

Expand Down
5 changes: 2 additions & 3 deletions orbeon/models/orbeon_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ def _get_url(self):
if isinstance(rec.id, models.NewId) and not rec.builder_id.id:
return rec.url

server_url = rec.builder_id.server_id.url
base_path = 'fr/orbeon/runner'
base_url = "%s/%s" % (server_url, base_path)
base_path = 'fr/b!%s!%s/runner' % (rec.builder_id.id, rec.id)
base_url = "/orbeon/%s" % (base_path)

if isinstance(rec.id, models.NewId):
url = "%s/new" % base_url
Expand Down
15 changes: 1 addition & 14 deletions orbeon/models/orbeon_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ class OrbeonServer(models.Model):
)
url = fields.Char(
"URL",
help='URL relative to Odoo server, the Odoo server will open the URL and proxy the response',
required=True,
)
summary_url = fields.Char(
"Summary URL",
compute="_set_summary_url",
store=True,
)
description = fields.Text(
"Description"
)
Expand Down Expand Up @@ -138,15 +134,6 @@ def __init__(self, pool, cr):
self._autostart_persistence_servers(pool, cr)
return res

@api.one
@api.depends("url")
def _set_summary_url(self):
if self.url:
url = "%s/fr/orbeon/builder/summary" % self.url
else:
url = "Enter URL"
self.summary_url = url

@api.constrains("name")
def constraint_unique_name(self):
cur_record = self.search([("name", "=", self.name)])
Expand Down
7 changes: 2 additions & 5 deletions orbeon/services/persistence_server/orbeon_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,14 @@ def __init__(self, app, form, data_type, path=(), args={}, data=None):
super(RunnerHandler, self).__init__(app, form, data_type, path, args, data)

self.model = 'orbeon.runner'
self.form_doc_id = path[5] if len(path) > 5 else None
self.form_doc_id = path[2].split('!')[2]
self.form_data_id = path[6] if len(path) > 6 else None

def read(self):
"""Get Orbeon-Runner data by read (i.e. HTTP GET)"""

if self.data_type == 'form':
# Builder form data (definition)
form_doc_id = self.args.get('document')
record = self.xmlrpc.runner_search_read_builder(
[[("id", "=", form_doc_id)]],
[[("id", "=", self.form_doc_id)]],
["xml"],
)
return record.get("xml")
Expand Down
2 changes: 1 addition & 1 deletion orbeon/views/orbeon_runner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<form>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="open_orbeon_runner" type="object" attrs="{'invisible':[('id','=',False)]}"
<button name="action_open_orbeon_runner" type="object" attrs="{'invisible':[('id','=',False)]}"
string="Edit" class="oe_stat_button" icon="fa-edit" />
<button name="merge_current_builder" type="object"
attrs="{'invisible':['|', ('id','=',False), '|', ('is_merged','=',True), '|', ('any_new_current_builder','=',False)]}"
Expand Down
1 change: 0 additions & 1 deletion orbeon/views/orbeon_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<page name="configuration" string="Configuration">
<group string="Orbeon Server">
<field name="url" widget="url" string="URL" />
<field name="summary_url" widget="url" string="Summary URL" />
<field name="description"/>
</group>
<group string="Orbeon Persistence Server">
Expand Down
2 changes: 2 additions & 0 deletions orbeon_report_qweb/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"views/ir_actions_report_xml.xml",
"views/orbeon_builder.xml",
"views/orbeon_runner.xml",
"views/qweb_report_chooser.xml",
"views/orbeon_builder_report_xml.xml"
],
"application": False,
"installable": True,
Expand Down
2 changes: 2 additions & 0 deletions orbeon_report_qweb/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
from . import ir_actions_report_xml
from . import orbeon_builder_report_xml
from . import orbeon_builder
from . import orbeon_runner
from . import orbeon_report_qweb_chooser
43 changes: 43 additions & 0 deletions orbeon_report_qweb/models/orbeon_report_qweb_chooser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# open2bizz
# Copyright (C) 2017 open2bizz (open2bizz.nl).
#
# 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/>.
#
##############################################################################
from odoo import fields, models, _, api, osv
from openerp.exceptions import Warning


import logging

_logger = logging.getLogger(__name__)


class OrbeonReportQwebChooser(models.TransientModel):
_name = 'orbeon.report.qweb.chooser'
_description = "Choose QWEB report"

report_xml_id = fields.Many2one(
'ir.actions.report.xml',
string="Reports"
)

def run_report(self, context={}):
rep = self.env['orbeon.runner'].browse(context.get('orbeon_runner_id'))
return rep[0].run_qweb_report(self.report_xml_id.id)


77 changes: 77 additions & 0 deletions orbeon_report_qweb/models/orbeon_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# open2bizz
# Copyright (C) 2017 open2bizz (open2bizz.nl).
#
# 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/>.
#
##############################################################################
from odoo import fields, models, _, api, osv
from openerp.exceptions import Warning


import logging

_logger = logging.getLogger(__name__)


class OrbeonRunner(models.Model):
_inherit = ['orbeon.runner']

builder_reports_count = fields.Integer(
compute='_builder_reports_count',
string='Builder reports count'
)

@api.one
def _builder_reports_count(self):
self.builder_reports_count = len(self.builder_id.report_xml_ids)

def run_qweb_report(self, report_id):
rep = self.env['ir.actions.report.xml'].browse(report_id)
data = {
'ids': [self.id],
'model': 'orbeon.runner',
'form': [self.id],
'context':{}
}
return {
'type' : 'ir.actions.report.xml',
'report_name' : rep.report_name,
'datas' : data,
}



@api.multi
def report_button(self, context=None):
if self.builder_id.report_xml_ids:
if len(self.builder_id.report_xml_ids) > 1:
ids = [rec.ir_actions_report_xml_id.id for rec in self.builder_id.report_xml_ids ]
context.update({ 'rep_ids' : ids, 'orbeon_runner_id' : self.id })
return {
'name': 'Choose report',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'orbeon.report.qweb.chooser',
'type': 'ir.actions.act_window',
'target': 'new',
'context': context
}
else:
return self.run_qweb_report(self.builder_id.report_xml_ids[0].ir_actions_report_xml_id.id )



16 changes: 16 additions & 0 deletions orbeon_report_qweb/views/orbeon_builder_report_xml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="orbeon_builder_report_xml_form" model="ir.ui.view">
<field name="name">orbeon.builder.report.xml.form</field>
<field name="model">orbeon.builder.report.xml</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Report">
<group>
<field name="sequence"/>
<field name="ir_actions_report_xml_id"/>
</group>
</form>
</field>
</record>
</odoo>
25 changes: 25 additions & 0 deletions orbeon_report_qweb/views/orbeon_runner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>

<record id="orbeon_report_qweb_orbeon_runner_form" model="ir.ui.view">
<field name="name">orbeon.runner_form.kanban</field>
<field name="model">orbeon.runner</field>
<field name="priority" eval="20" />
<field name="inherit_id" ref="orbeon.orbeon_runner_form_kanban" />
<field name="arch" type="xml">
<data>
<xpath expr="//div[contains(@class, 'col-xs-6 o_kanban_primary_left')]" position="after">
<field name="builder_reports_count" invisible="1"/>

<a type="button">
<button class="btn btn-primary" name="report_button" type="object" attrs="{'invisible': [('builder_reports_count', '=', 0)]}">Report</button>
</a>
</xpath>
</data>
</field>
</record>


</data>
</odoo>
Loading

0 comments on commit 7504def

Please sign in to comment.