mirror of
https://github.com/bringout/oca-report.git
synced 2026-04-22 18:42:00 +02:00
Initial commit: OCA Report packages (45 packages)
This commit is contained in:
commit
2f4db400df
2543 changed files with 469120 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
from . import ir_actions_report
|
||||
from . import ir_actions_report_substitution_rule
|
||||
from . import mail_thread
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
# 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_rule_ids = fields.One2many(
|
||||
"ir.actions.report.substitution.rule",
|
||||
"action_report_id",
|
||||
string="Substitution Rules",
|
||||
)
|
||||
|
||||
def _get_substitution_report(self, model, active_ids):
|
||||
self.ensure_one()
|
||||
model = self.env[model]
|
||||
for substitution_report_rule in self.action_report_substitution_rule_ids:
|
||||
domain = safe_eval(substitution_report_rule.domain)
|
||||
domain.append(("id", "in", active_ids))
|
||||
if set(model.search(domain).ids) == set(active_ids):
|
||||
return substitution_report_rule.substitution_action_report_id
|
||||
return False
|
||||
|
||||
def get_substitution_report(self, active_ids):
|
||||
self.ensure_one()
|
||||
action_report = self
|
||||
substitution_report = action_report
|
||||
while substitution_report:
|
||||
action_report = substitution_report
|
||||
substitution_report = action_report._get_substitution_report(
|
||||
action_report.model, active_ids
|
||||
)
|
||||
return action_report
|
||||
|
||||
@api.model
|
||||
def get_substitution_report_action(self, action, active_ids):
|
||||
if action.get("id"):
|
||||
action_report = self.browse(action["id"])
|
||||
substitution_report = action_report
|
||||
while substitution_report:
|
||||
action_report = substitution_report
|
||||
substitution_report = action_report._get_substitution_report(
|
||||
action_report.model, active_ids
|
||||
)
|
||||
action.update(action_report.read()[0])
|
||||
|
||||
return action
|
||||
|
||||
def _render(self, report_ref, res_ids, data=None):
|
||||
report = self._get_report(report_ref)
|
||||
substitution_report = report.get_substitution_report(res_ids)
|
||||
return super(IrActionReport, self)._render(
|
||||
substitution_report.report_name, res_ids, data=data
|
||||
)
|
||||
|
||||
def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
|
||||
report = self._get_report(report_ref)
|
||||
substitution_report = report.get_substitution_report(res_ids)
|
||||
if substitution_report.filtered(lambda r: r.report_type == "qweb-pdf"):
|
||||
return super(IrActionReport, self)._render_qweb_pdf(
|
||||
substitution_report, res_ids=res_ids, data=data
|
||||
)
|
||||
return super(IrActionReport, self)._render_qweb_pdf(
|
||||
report_ref, res_ids=res_ids, data=data
|
||||
)
|
||||
|
||||
def report_action(self, docids, data=None, config=True):
|
||||
if docids:
|
||||
if isinstance(docids, models.Model):
|
||||
active_ids = docids.ids
|
||||
elif isinstance(docids, int):
|
||||
active_ids = [docids]
|
||||
elif isinstance(docids, list):
|
||||
active_ids = docids
|
||||
substitution_report = self.get_substitution_report(active_ids)
|
||||
return super(IrActionReport, substitution_report).report_action(
|
||||
docids, data, config
|
||||
)
|
||||
return super().report_action(docids, data, config)
|
||||
|
||||
def get_action_report_substitution_rule_ids(self):
|
||||
return self.action_report_substitution_rule_ids.ids
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
# 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.exceptions import ValidationError
|
||||
|
||||
|
||||
class ActionsReportSubstitutionRule(models.Model):
|
||||
|
||||
_name = "ir.actions.report.substitution.rule"
|
||||
_description = "Action Report Substitution Rule"
|
||||
_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(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)]",
|
||||
)
|
||||
|
||||
@api.constrains("substitution_action_report_id", "action_report_id")
|
||||
def _check_substitution_infinite_loop(self):
|
||||
def _check_infinite_loop(original_report, substitution_report):
|
||||
if original_report == substitution_report:
|
||||
raise ValidationError(_("Substitution infinite loop detected"))
|
||||
for (
|
||||
substitution_rule
|
||||
) in substitution_report.action_report_substitution_rule_ids:
|
||||
_check_infinite_loop(
|
||||
original_report,
|
||||
substitution_rule.substitution_action_report_id,
|
||||
)
|
||||
|
||||
for rec in self:
|
||||
_check_infinite_loop(
|
||||
rec.action_report_id, rec.substitution_action_report_id
|
||||
)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MailThread(models.AbstractModel):
|
||||
|
||||
_inherit = "mail.thread"
|
||||
|
||||
def message_post_with_template(self, template_id, **kwargs):
|
||||
template = self.env["mail.template"].browse(template_id)
|
||||
if template and template.report_template and self.ids:
|
||||
active_ids = self.ids
|
||||
report_template = template.report_template.get_substitution_report(
|
||||
active_ids
|
||||
)
|
||||
return super(
|
||||
MailThread, self.with_context(default_report_template=report_template)
|
||||
).message_post_with_template(template_id, **kwargs)
|
||||
return super().message_post_with_template(template_id, **kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue