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.

43 lines
1.3 KiB

  1. # Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
  3. from odoo import fields, models, api
  4. class PrintReportWizard(models.TransientModel):
  5. _name = 'print.report.wizard'
  6. _description = 'Print Report Wizard'
  7. reference = fields.Reference(
  8. string='Document',
  9. selection='_reference_models',
  10. required=True,
  11. )
  12. action_report_id = fields.Many2one(
  13. comodel_name='ir.actions.report',
  14. string='Report Template',
  15. required=True,
  16. )
  17. @api.model
  18. def _reference_models(self):
  19. excludes = ['res.company']
  20. models = self.env['ir.model'].search([
  21. ('state', '!=', 'manual'), ('transient', '=', False),
  22. ('model', 'not in', excludes)])
  23. return [(model.model, model.name) for model in models]
  24. @api.onchange('reference')
  25. def _onchange_reference(self):
  26. self.ensure_one()
  27. domain = [('id', 'in', [])]
  28. self.action_report_id = False
  29. if self.reference:
  30. domain = [('model', '=', self.reference._name)]
  31. return {'domain': {'action_report_id': domain}}
  32. @api.multi
  33. def print_report(self):
  34. self.ensure_one()
  35. return self.action_report_id.report_action(self.reference,
  36. config=False)