Browse Source

[MIG] report_xlsx: Migration to 14.0

14.0
Alex Cuellar 4 years ago
parent
commit
5231d53a21
  1. 4
      report_xlsx/__manifest__.py
  2. 2
      report_xlsx/controllers/main.py
  3. 16
      report_xlsx/demo/report.xml
  4. 6
      report_xlsx/models/ir_report.py
  5. 6
      report_xlsx/report/report_partner_xlsx.py
  6. 10
      report_xlsx/tests/test_report.py
  7. 3
      requirements.txt

4
report_xlsx/__manifest__.py

@ -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"],

2
report_xlsx/controllers/main.py

@ -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])

16
report_xlsx/demo/report.xml

@ -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>

6
report_xlsx/models/ir_report.py

@ -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:

6
report_xlsx/report/report_partner_xlsx.py

@ -10,7 +10,9 @@ class PartnerXlsx(models.AbstractModel):
_description = "Partner XLSX Report"
def generate_xlsx_report(self, workbook, data, partners):
for obj in partners:
sheet = workbook.add_worksheet("Report")
i = 0
for obj in partners:
bold = workbook.add_format({"bold": True})
sheet.write(0, 0, obj.name, bold)
sheet.write(i, 0, obj.name, bold)
i += 1

10
report_xlsx/tests/test_report.py

@ -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)

3
requirements.txt

@ -0,0 +1,3 @@
# generated from manifests external_dependencies
xlrd
xlsxwriter
Loading…
Cancel
Save