Add ir_action_server on sql view generated

pull/561/head
Valentin 2021-12-13 14:57:09 +01:00
parent a77de56567
commit 88a2a24d47
11 changed files with 168 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

View File

@ -0,0 +1,18 @@
# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "BI SQL Editor Server Actions",
"summary": "Add server actions on BI Views builder module",
"version": "13.0.1.0.1",
"license": "AGPL-3",
"category": "Reporting",
"author": "GRAP,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"depends": ["base", "bi_sql_editor"],
"data": ["views/ir_actions_server_view.xml", "views/view_bi_sql_view.xml"],
"demo": [],
"maintainers": ["vnahaulogy"],
"installable": True,
}

View File

@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import ir_actions_server
from . import bi_sql_view

View File

@ -0,0 +1,37 @@
# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID, _, api, fields, models
class BiSQLView(models.Model):
_name = "bi.sql.view"
_inherit = ["bi.sql.view"]
server_action_ids = fields.Many2many(
comodel_name="ir.actions.server",
readonly=True,
states={"model_valid": [("readonly", False)]},
)
def unlink(self):
if self.mapped("server_action_ids"):
self.mapped("server_action_ids").unlink()
return super(BiSQLView, self).unlink()
def button_create_sql_view_and_model(self):
res = super(BiSQLView, self).button_create_sql_view_and_model()
for sql_view in self:
sql_view.server_action_ids.write({"model_id": sql_view.model_id.id})
return res
def button_set_draft(self):
self.mapped("server_action_ids").unlink_action()
# Avoid the on cascade delete
self.mapped("server_action_ids").write({"model_id": False})
return super(BiSQLView, self).button_set_draft()
def button_create_ui(self):
self.server_action_ids.create_action()
return super(BiSQLView, self).button_create_ui()

View File

@ -0,0 +1,11 @@
# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
class IrActionsServer(models.Model):
_inherit = "ir.actions.server"
model_id = fields.Many2one(required=False)

View File

@ -0,0 +1 @@
* Nagy Valentin <valentin.nagy@haulogy.net>

View File

@ -0,0 +1,7 @@
This module extends the functionality of bi_sql_editor module, to allow the addition
of server actions on the newly generated view.
Warning
-------
This module will set the required parameter of the 'model_id' field on the server action object
to false.

View File

@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_bi_sql_view_server_action

View File

@ -0,0 +1,44 @@
# Copyright 2017 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.exceptions import AccessError, UserError
from odoo.tests.common import SingleTransactionCase, at_install, post_install
@at_install(False)
@post_install(True)
class TestBiSqlViewEditorServerAction(SingleTransactionCase):
@classmethod
def setUpClass(cls):
super(TestBiSqlViewEditorServerAction, cls).setUpClass()
cls.bi_sql_view = cls.env["bi.sql.view"]
cls.ir_actions_server = cls.env["ir.actions.server"]
cls.server_action_ids = cls.ir_actions_server.create(
{"name": "x_server_action_name", "state": "code"}
)
cls.view = cls.bi_sql_view.create(
{
"name": "Partners View 3",
"is_materialized": True,
"technical_name": "partners_view_3",
"query": "SELECT name as x_name, street as x_street,"
"company_id as x_company_id FROM res_partner "
"ORDER BY name",
"server_action_ids": [(6, 0, cls.server_action_ids.ids)],
}
)
def test_server_actions_flow(self):
self.assertTrue(self.view.server_action_ids)
self.assertFalse(self.view.server_action_ids.model_id)
self.view.button_validate_sql_expression()
self.view.button_create_sql_view_and_model()
self.assertEqual(self.view.server_action_ids.model_id, self.view.model_id)
self.view.button_set_draft()
self.assertTrue(self.view.server_action_ids)
self.assertFalse(self.view.server_action_ids.model_id)
self.view.unlink()
server_action = self.ir_actions_server.search(
[("name", "=", "x_server_action_name")]
)
self.assertEqual(len(server_action), 0, "Server action not deleted")

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record model="ir.ui.view" id="view_server_action_inherited_form">
<field name="name">ir.actions.server.inherited.form</field>
<field name="model">ir.actions.server</field>
<field name="inherit_id" ref="base.view_server_action_form" />
<field name="arch" type="xml">
<field name="model_id" position="attributes">
<attribute name="required">True</attribute>
</field>
</field>
</record>
</odoo>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_bi_sql_action_server_view_form" model="ir.ui.view">
<field name="name">bi.sql.action.server.view.form</field>
<field name="model">bi.sql.view</field>
<field name="inherit_id" ref="bi_sql_editor.view_bi_sql_view_form" />
<field name="arch" type="xml">
<notebook position="inside">
<page string="Server actions" attrs="{'invisible': [('state', 'in', ['draft', 'sql_valid'])]}">
<field name="server_action_ids"
nolabel="1"
colspan="4"
context="{'default_model_id': model_id}"/>
</page>
</notebook>
</field>
</record>
</odoo>