[ADD] - report substitute
This addon give the possibility to substitute a report action by another based on some criteria.pull/307/head
parent
7018a186d2
commit
cd0c96016f
|
@ -0,0 +1 @@
|
|||
from . import models
|
|
@ -0,0 +1,20 @@
|
|||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Report Substitute',
|
||||
'summary': """
|
||||
This addon give the possibility to substitute a report action by
|
||||
another based on some criteria.
|
||||
""",
|
||||
'version': '12.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'ACSONE SA/NV,'
|
||||
'Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/acsone/reporting-engine',
|
||||
'depends': ['base'],
|
||||
'data': [
|
||||
'security/ir_actions_report_substitution_criteria.xml',
|
||||
'views/ir_actions_report.xml',
|
||||
],
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
from . import ir_actions_report
|
||||
from . import ir_actions_report_substitution_criteria
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class IrActionReport(models.Model):
|
||||
|
||||
_inherit = 'ir.actions.report'
|
||||
|
||||
action_report_substitution_criteria_ids = fields.One2many(
|
||||
comodel_name="ir.actions.report.substitution.criteria",
|
||||
inverse_name="action_report_id",
|
||||
string="Substitution Criteria",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _get_substitution_report(self, model, active_ids):
|
||||
self.ensure_one()
|
||||
model = self.env[model]
|
||||
for (
|
||||
substitution_report_criteria
|
||||
) in self.action_report_substitution_criteria_ids:
|
||||
domain = safe_eval(substitution_report_criteria.domain)
|
||||
domain.append(('id', 'in', active_ids))
|
||||
if set(model.search(domain).ids) == set(active_ids):
|
||||
return (
|
||||
substitution_report_criteria.substitution_action_report_id
|
||||
)
|
||||
return False
|
||||
|
||||
@api.multi
|
||||
def render(self, res_ids, data=None):
|
||||
substitution_report = self._get_substitution_report(
|
||||
self.model, res_ids
|
||||
)
|
||||
if substitution_report:
|
||||
return substitution_report.render(res_ids)
|
||||
return super().render(res_ids, data)
|
|
@ -0,0 +1,28 @@
|
|||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ActionsReportSubstitutionCriteria(models.Model):
|
||||
|
||||
_name = 'ir.actions.report.substitution.criteria'
|
||||
_description = 'Action Report Substitution Criteria'
|
||||
_order = 'sequence ASC'
|
||||
|
||||
sequence = fields.Integer(default=10)
|
||||
action_report_id = fields.Many2one(
|
||||
comodel_name="ir.actions.report",
|
||||
string="Report Action",
|
||||
required=True,
|
||||
ondelete="cascade",
|
||||
)
|
||||
model = fields.Char(related="action_report_id.model", store=True)
|
||||
domain = fields.Char(string="Domain", required=True, default="[]")
|
||||
substitution_action_report_id = fields.Many2one(
|
||||
comodel_name="ir.actions.report",
|
||||
string="Substitution Report Action",
|
||||
required=True,
|
||||
ondelete="cascade",
|
||||
domain="[('model', '=', model)]"
|
||||
)
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record model="ir.model.access" id="action_report_substitution_criteria_user_access">
|
||||
<field name="name">action.report.substitution.criteria user access</field>
|
||||
<field name="model_id" ref="model_ir_actions_report_substitution_criteria"/>
|
||||
<field name="perm_read" eval="1"/>
|
||||
<field name="perm_create" eval="0"/>
|
||||
<field name="perm_write" eval="0"/>
|
||||
<field name="perm_unlink" eval="0"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="action_report_substitution_criteria_manager_access">
|
||||
<field name="name">action.report.substitution.criteria manager access</field>
|
||||
<field name="model_id" ref="model_ir_actions_report_substitution_criteria"/>
|
||||
<field name="group_id" ref="base.group_system"/>
|
||||
<field name="perm_read" eval="1"/>
|
||||
<field name="perm_create" eval="1"/>
|
||||
<field name="perm_write" eval="1"/>
|
||||
<field name="perm_unlink" eval="1"/>
|
||||
</record>
|
||||
</odoo>
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="ir_actions_report_form_view">
|
||||
<field name="name">ir.actions.report.form (in report_dispatch_base)
|
||||
</field>
|
||||
<field name="model">ir.actions.report</field>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[@name='advanced']" position="after">
|
||||
<page name="report_substitution_criteria" string="Substitution Criteria">
|
||||
<field name="action_report_substitution_criteria_ids">
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="substitution_action_report_id"/>
|
||||
<field name="domain"/>
|
||||
</tree>
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="action_report_id"
|
||||
invisible="1" readonly="1"
|
||||
required="0"/>
|
||||
<field name="model" invisible="1"/>
|
||||
<field name="substitution_action_report_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="domain" widget="domain"
|
||||
options="{'model': 'model'}"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
|
@ -0,0 +1 @@
|
|||
../../../../report_substitute
|
|
@ -0,0 +1,6 @@
|
|||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
Loading…
Reference in New Issue