diff --git a/report_substitute/__init__.py b/report_substitute/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/report_substitute/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/report_substitute/__manifest__.py b/report_substitute/__manifest__.py new file mode 100644 index 00000000..a9ad3ca7 --- /dev/null +++ b/report_substitute/__manifest__.py @@ -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', + ], +} diff --git a/report_substitute/models/__init__.py b/report_substitute/models/__init__.py new file mode 100644 index 00000000..d1a25e84 --- /dev/null +++ b/report_substitute/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_actions_report +from . import ir_actions_report_substitution_criteria diff --git a/report_substitute/models/ir_actions_report.py b/report_substitute/models/ir_actions_report.py new file mode 100644 index 00000000..ca2e7ce8 --- /dev/null +++ b/report_substitute/models/ir_actions_report.py @@ -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) diff --git a/report_substitute/models/ir_actions_report_substitution_criteria.py b/report_substitute/models/ir_actions_report_substitution_criteria.py new file mode 100644 index 00000000..04430aed --- /dev/null +++ b/report_substitute/models/ir_actions_report_substitution_criteria.py @@ -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)]" + ) diff --git a/report_substitute/security/ir_actions_report_substitution_criteria.xml b/report_substitute/security/ir_actions_report_substitution_criteria.xml new file mode 100644 index 00000000..b74770b8 --- /dev/null +++ b/report_substitute/security/ir_actions_report_substitution_criteria.xml @@ -0,0 +1,25 @@ + + + + + + + action.report.substitution.criteria user access + + + + + + + + + action.report.substitution.criteria manager access + + + + + + + + diff --git a/report_substitute/views/ir_actions_report.xml b/report_substitute/views/ir_actions_report.xml new file mode 100644 index 00000000..750aeb74 --- /dev/null +++ b/report_substitute/views/ir_actions_report.xml @@ -0,0 +1,43 @@ + + + + + + + ir.actions.report.form (in report_dispatch_base) + + ir.actions.report + + + + + + + + + + +
+ + + + + + + + + + +
+
+
+
+
+
+ + +
diff --git a/setup/report_substitute/odoo/addons/report_substitute b/setup/report_substitute/odoo/addons/report_substitute new file mode 120000 index 00000000..b85da0ba --- /dev/null +++ b/setup/report_substitute/odoo/addons/report_substitute @@ -0,0 +1 @@ +../../../../report_substitute \ No newline at end of file diff --git a/setup/report_substitute/setup.py b/setup/report_substitute/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/report_substitute/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)