[MIG] report_csv: Migration to 16.0

This commit is contained in:
Zina Rasoamanana
2022-11-08 14:35:39 +01:00
parent 9686db699e
commit 355981cf4e
4 changed files with 16 additions and 16 deletions

View File

@@ -6,7 +6,7 @@
"author": "Creu Blanca, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"category": "Reporting",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": ["base", "web"],
"demo": ["demo/report.xml"],

View File

@@ -15,7 +15,7 @@ from odoo.http import (
from odoo.tools import html_escape
from odoo.tools.safe_eval import safe_eval, time
from odoo.addons.web.controllers import main as report
from odoo.addons.web.controllers import report
_logger = logging.getLogger(__name__)
@@ -38,7 +38,9 @@ class ReportController(report.ReportController):
if data["context"].get("lang"):
del data["context"]["lang"]
context.update(data["context"])
csv = report.with_context(**context)._render_csv(docids, data=data)[0]
csv = report.with_context(**context)._render_csv(
reportname, docids, data=data
)[0]
csvhttpheaders = [
("Content-Type", "text/csv"),
("Content-Length", len(csv)),

View File

@@ -1,8 +1,7 @@
# Copyright 2019 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import api, fields, models
class ReportAction(models.Model):
@@ -13,14 +12,13 @@ class ReportAction(models.Model):
)
@api.model
def _render_csv(self, docids, data):
report_model_name = "report.%s" % self.report_name
report_model = self.env.get(report_model_name)
if report_model is None:
raise UserError(_("%s model was not found") % report_model_name)
return report_model.with_context(active_model=self.model).create_csv_report(
docids, data
)
def _render_csv(self, report_ref, docids, data):
report_sudo = self._get_report(report_ref)
report_model_name = "report.%s" % report_sudo.report_name
report_model = self.env[report_model_name]
return report_model.with_context(
active_model=report_sudo.model
).create_csv_report(docids, data)
@api.model
def _get_report_from_name(self, report_name):

View File

@@ -15,19 +15,19 @@ except ImportError:
class TestReport(common.TransactionCase):
def setUp(self):
super().setUp()
report_object = self.env["ir.actions.report"]
self.report_object = self.env["ir.actions.report"]
self.csv_report = self.env["report.report_csv.abstract"].with_context(
active_model="res.partner"
)
self.report_name = "report_csv.partner_csv"
self.report = report_object._get_report_from_name(self.report_name)
self.report = self.report_object._get_report_from_name(self.report_name)
self.docs = self.env["res.company"].search([], limit=1).partner_id
def test_report(self):
# Test if not res:
report = self.report
self.assertEqual(report.report_type, "csv")
rep = report._render(self.docs.ids, {})
rep = self.report_object._render(self.report_name, self.docs.ids, {})
str_io = StringIO(rep[0])
dict_report = list(csv.DictReader(str_io, delimiter=";", quoting=csv.QUOTE_ALL))
self.assertEqual(self.docs.name, dict(dict_report[0])["name"])