|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # Copyright 2013 XCG Consulting (http://odoo.consulting) |
3 | 3 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
4 | | -import os |
5 | 4 | import logging |
6 | 5 | from odoo import api, fields, models, _ |
7 | | -from odoo.report.interface import report_int |
8 | 6 | from odoo.exceptions import ValidationError |
9 | | -from odoo import addons |
10 | | -from ..py3o_parser import Py3oParser |
11 | 7 |
|
12 | 8 | logger = logging.getLogger(__name__) |
13 | 9 |
|
@@ -85,43 +81,14 @@ def _get_py3o_filetypes(self): |
85 | 81 | )) |
86 | 82 | report_type = fields.Selection(selection_add=[('py3o', "Py3o")]) |
87 | 83 |
|
88 | | - @api.model_cr |
89 | | - def _lookup_report(self, name): |
90 | | - """Look up a report definition. |
91 | | - """ |
92 | | - # START section copied from odoo/addons/base/ir/ir_actions.py |
93 | | - # with small adaptations |
94 | | - # First lookup in the deprecated place, because if the report |
95 | | - # definition has not been updated, it is more likely the correct |
96 | | - # definition is there. Only reports with custom parser |
97 | | - # specified in Python are still there. |
98 | | - if 'report.' + name in report_int._reports: |
99 | | - new_report = report_int._reports['report.' + name] |
100 | | - if not isinstance(new_report, Py3oParser): |
101 | | - new_report = None |
102 | | - else: |
103 | | - self._cr.execute( |
104 | | - "SELECT * FROM ir_act_report_xml " |
105 | | - "WHERE report_name=%s AND report_type=%s", (name, 'py3o')) |
106 | | - report_data = self._cr.dictfetchone() |
107 | | - # END section copied from odoo/addons/base/ir/ir_actions.py |
108 | | - if report_data: |
109 | | - kwargs = {} |
110 | | - if report_data['parser']: |
111 | | - kwargs['parser'] = getattr(addons, report_data['parser']) |
112 | | - |
113 | | - new_report = Py3oParser( |
114 | | - 'report.' + report_data['report_name'], |
115 | | - report_data['model'], |
116 | | - os.path.join('addons', report_data['report_rml'] or '/'), |
117 | | - header=report_data['header'], |
118 | | - register=False, |
119 | | - **kwargs |
120 | | - ) |
121 | | - else: |
122 | | - new_report = None |
123 | | - |
124 | | - if new_report: |
125 | | - return new_report |
126 | | - else: |
127 | | - return super(IrActionsReportXml, self)._lookup_report(name) |
| 84 | + @api.model |
| 85 | + def render_report(self, res_ids, name, data): |
| 86 | + action_py3o_report = self.search( |
| 87 | + [("report_name", "=", name), |
| 88 | + ("report_type", "=", "py3o")]) |
| 89 | + if action_py3o_report: |
| 90 | + return self.env['py3o.report'].create({ |
| 91 | + 'ir_actions_report_xml_id': action_py3o_report.id |
| 92 | + }).create_report(res_ids, data) |
| 93 | + return super(IrActionsReportXml, self).render_report( |
| 94 | + res_ids, name, data) |
0 commit comments