[MIG] report_xlsx: Migration to 14.0
parent
200fe0d15b
commit
32b35467f7
|
@ -4,9 +4,9 @@
|
|||
"name": "Base report xlsx",
|
||||
"summary": "Base module to create xlsx report",
|
||||
"author": "ACSONE SA/NV," "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": ["xlsxwriter", "xlrd"]},
|
||||
"depends": ["base", "web"],
|
||||
|
|
|
@ -28,7 +28,7 @@ class ReportController(report.ReportController):
|
|||
if data["context"].get("lang"):
|
||||
del data["context"]["lang"]
|
||||
context.update(data["context"])
|
||||
xlsx = report.with_context(context).render_xlsx(docids, data=data)[0]
|
||||
xlsx = report.with_context(context)._render_xlsx(docids, data=data)[0]
|
||||
report_name = report.report_file
|
||||
if report.print_report_name and not len(docids) > 1:
|
||||
obj = request.env[report.model].browse(docids[0])
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
© 2017 Creu Blanca
|
||||
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
-->
|
||||
<report
|
||||
id="partner_xlsx"
|
||||
model="res.partner"
|
||||
string="Print to XLSX"
|
||||
report_type="xlsx"
|
||||
name="report_xlsx.partner_xlsx"
|
||||
file="res_partner"
|
||||
attachment_use="False"
|
||||
/>
|
||||
<record id="partner_xlsx" model="ir.actions.report">
|
||||
<field name="name">Print to XLSX</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="report_type">xlsx</field>
|
||||
<field name="report_name">report_xlsx.partner_xlsx</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=[("xlsx", "XLSX")])
|
||||
report_type = fields.Selection(
|
||||
selection_add=[("xlsx", "XLSX")], ondelete={"xlsx": "set default"}
|
||||
)
|
||||
|
||||
@api.model
|
||||
def render_xlsx(self, docids, data):
|
||||
def _render_xlsx(self, docids, data):
|
||||
report_model_name = "report.%s" % self.report_name
|
||||
report_model = self.env.get(report_model_name)
|
||||
if report_model is None:
|
||||
|
|
|
@ -10,7 +10,9 @@ class PartnerXlsx(models.AbstractModel):
|
|||
_description = "Partner XLSX Report"
|
||||
|
||||
def generate_xlsx_report(self, workbook, data, partners):
|
||||
sheet = workbook.add_worksheet("Report")
|
||||
i = 0
|
||||
for obj in partners:
|
||||
sheet = workbook.add_worksheet("Report")
|
||||
bold = workbook.add_format({"bold": True})
|
||||
sheet.write(0, 0, obj.name, bold)
|
||||
sheet.write(i, 0, obj.name, bold)
|
||||
i += 1
|
||||
|
|
|
@ -27,7 +27,7 @@ class TestReport(common.TransactionCase):
|
|||
def test_report(self):
|
||||
report = self.report
|
||||
self.assertEqual(report.report_type, "xlsx")
|
||||
rep = report.render(self.docs.ids, {})
|
||||
rep = report._render(self.docs.ids, {})
|
||||
wb = open_workbook(file_contents=rep[0])
|
||||
sheet = wb.sheet_by_index(0)
|
||||
self.assertEqual(sheet.cell(0, 0).value, self.docs.name)
|
||||
|
@ -38,20 +38,20 @@ class TestReport(common.TransactionCase):
|
|||
objs = self.xlsx_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.xlsx_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.xlsx_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.xlsx_report._get_objs_for_report(self.docs.ids, {})
|
||||
self.assertEquals(objs, self.docs)
|
||||
self.assertEqual(objs, self.docs)
|
||||
|
|
Loading…
Reference in New Issue