[MIG] report_csv: Migration to 14.0
parent
cde41788de
commit
3902c7f68a
|
@ -4,11 +4,10 @@
|
|||
"name": "Base report csv",
|
||||
"summary": "Base module to create csv report",
|
||||
"author": "Creu Blanca, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/oca/reporting-engine",
|
||||
"website": "https://github.com/OCA/reporting-engine",
|
||||
"category": "Reporting",
|
||||
"version": "13.0.1.0.1",
|
||||
"version": "14.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"external_dependencies": {"python": ["csv"]},
|
||||
"depends": ["base", "web"],
|
||||
"data": ["views/webclient_templates.xml"],
|
||||
"demo": ["demo/report.xml"],
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from odoo.http import content_disposition, request, route
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
@ -28,14 +27,14 @@ 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(docids, data=data)[0]
|
||||
filename = "{}.{}".format(report.name, "csv")
|
||||
if docids:
|
||||
obj = request.env[report.model].browse(docids)
|
||||
if report.print_report_name and not len(obj) > 1:
|
||||
report_name = safe_eval(
|
||||
report.print_report_name,
|
||||
{"object": obj, "time": time, "multi": False},
|
||||
{"object": obj},
|
||||
)
|
||||
filename = "{}.{}".format(report_name, "csv")
|
||||
# When we print multiple records we still allow a custom
|
||||
|
@ -43,7 +42,7 @@ class ReportController(report.ReportController):
|
|||
elif report.print_report_name and len(obj) > 1:
|
||||
report_name = safe_eval(
|
||||
report.print_report_name,
|
||||
{"objects": obj, "time": time, "multi": True},
|
||||
{"object": obj},
|
||||
)
|
||||
filename = "{}.{}".format(report_name, "csv")
|
||||
csvhttpheaders = [
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
Copyright 2019 Creu Blanca
|
||||
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
-->
|
||||
<report
|
||||
id="partner_csv"
|
||||
model="res.partner"
|
||||
string="Print to CSV"
|
||||
report_type="csv"
|
||||
name="report_csv.partner_csv"
|
||||
file="res_partner"
|
||||
attachment_use="False"
|
||||
/>
|
||||
<record id="partner_csv" model="ir.actions.report">
|
||||
<field name="name">Print to CSV</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="report_type">csv</field>
|
||||
<field name="report_name">report_csv.partner_csv</field>
|
||||
<field name="report_file">res_partner</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
|
@ -8,10 +8,12 @@ from odoo.exceptions import UserError
|
|||
class ReportAction(models.Model):
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
report_type = fields.Selection(selection_add=[("csv", "csv")])
|
||||
report_type = fields.Selection(
|
||||
selection_add=[("csv", "csv")], ondelete={"csv": "set default"}
|
||||
)
|
||||
|
||||
@api.model
|
||||
def render_csv(self, docids, data):
|
||||
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:
|
||||
|
|
|
@ -25,10 +25,9 @@ class TestReport(common.TransactionCase):
|
|||
|
||||
def test_report(self):
|
||||
# Test if not res:
|
||||
self.env["ir.actions.report"]._get_report_from_name("TEST")
|
||||
report = self.report
|
||||
self.assertEqual(report.report_type, "csv")
|
||||
rep = report.render(self.docs.ids, {})
|
||||
rep = report._render(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"])
|
||||
|
@ -39,20 +38,20 @@ class TestReport(common.TransactionCase):
|
|||
objs = self.csv_report._get_objs_for_report(
|
||||
False, {"context": {"active_ids": self.docs.ids}}
|
||||
)
|
||||
self.assertEquals(objs, self.docs)
|
||||
self.assertEqual(objs, self.docs)
|
||||
|
||||
# Typical call from within code not to report_action
|
||||
objs = self.csv_report.with_context(
|
||||
active_ids=self.docs.ids
|
||||
)._get_objs_for_report(False, False)
|
||||
self.assertEquals(objs, self.docs)
|
||||
self.assertEqual(objs, self.docs)
|
||||
|
||||
# Typical call from WebUI
|
||||
objs = self.csv_report._get_objs_for_report(
|
||||
self.docs.ids, {"data": [self.report_name, self.report.report_type]}
|
||||
)
|
||||
self.assertEquals(objs, self.docs)
|
||||
self.assertEqual(objs, self.docs)
|
||||
|
||||
# Typical call from render
|
||||
objs = self.csv_report._get_objs_for_report(self.docs.ids, {})
|
||||
self.assertEquals(objs, self.docs)
|
||||
self.assertEqual(objs, self.docs)
|
||||
|
|
Loading…
Reference in New Issue