OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

  1. # Copyright 2019 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, models
  4. class MailComposeMessage(models.TransientModel):
  5. _inherit = 'mail.compose.message'
  6. @api.multi
  7. @api.onchange('template_id')
  8. def onchange_template_id_wrapper(self):
  9. if self.template_id:
  10. report_template = self.template_id.report_template
  11. active_ids = []
  12. if self.env.context.get('active_ids'):
  13. active_ids = self.env.context.get('active_ids')
  14. elif self.env.context.get('default_res_id'):
  15. active_ids = [self.env.context.get('default_res_id')]
  16. if (
  17. report_template
  18. and report_template.action_report_substitution_rule_ids
  19. and active_ids
  20. ):
  21. old_report_template = report_template
  22. self.template_id.report_template = (
  23. old_report_template.get_substitution_report(active_ids)
  24. )
  25. onchange_result_with_substituted_report = (
  26. super().onchange_template_id_wrapper()
  27. )
  28. self.template_id.report_template = old_report_template
  29. return onchange_result_with_substituted_report
  30. return super().onchange_template_id_wrapper()