mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_xlsx_helper_demo: Migration to 14.0
This commit is contained in:
@@ -264,7 +264,6 @@ class ReportXlsxAbstract(models.AbstractModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# formats for worksheet table column headers
|
# formats for worksheet table column headers
|
||||||
<<<<<<< HEAD
|
|
||||||
FORMATS["format_theader_grey_left"] = workbook.add_format(theader_grey)
|
FORMATS["format_theader_grey_left"] = workbook.add_format(theader_grey)
|
||||||
FORMATS["format_theader_grey_center"] = workbook.add_format(
|
FORMATS["format_theader_grey_center"] = workbook.add_format(
|
||||||
dict(theader_grey, align="center")
|
dict(theader_grey, align="center")
|
||||||
@@ -328,8 +327,6 @@ class ReportXlsxAbstract(models.AbstractModel):
|
|||||||
dict(theader_grey, num_format=int_format_conditional, align="right")
|
dict(theader_grey, num_format=int_format_conditional, align="right")
|
||||||
)
|
)
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> [IMP] format xlsx to global files
|
|
||||||
FORMATS["format_theader_yellow_left"] = workbook.add_format(theader_yellow)
|
FORMATS["format_theader_yellow_left"] = workbook.add_format(theader_yellow)
|
||||||
FORMATS["format_theader_yellow_center"] = workbook.add_format(
|
FORMATS["format_theader_yellow_center"] = workbook.add_format(
|
||||||
dict(theader_yellow, align="center")
|
dict(theader_yellow, align="center")
|
||||||
|
|||||||
@@ -162,4 +162,3 @@ FORMATS = {
|
|||||||
"format_tcell_date_center_bold": False,
|
"format_tcell_date_center_bold": False,
|
||||||
"format_tcell_date_right_bold": False,
|
"format_tcell_date_right_bold": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
# Copyright 2009-2019 Noviat.
|
# Copyright 2009-2020 Noviat.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Report xlsx helpers - demo',
|
"name": "Report xlsx helpers - demo",
|
||||||
'author': 'Noviat,'
|
"author": "Noviat, Odoo Community Association (OCA)",
|
||||||
'Odoo Community Association (OCA)',
|
"website": "https://github.com/OCA/reporting-engine",
|
||||||
'category': 'Reporting',
|
"category": "Reporting",
|
||||||
'version': '12.0.1.1.0',
|
"version": "14.0.1.0.0",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'depends': [
|
"depends": [
|
||||||
'report_xlsx_helper',
|
"report_xlsx_helper",
|
||||||
],
|
],
|
||||||
'data': [
|
"data": [
|
||||||
'views/res_partner.xml',
|
"views/res_partner.xml",
|
||||||
],
|
],
|
||||||
'installable': True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
# Copyright 2009-2018 Noviat
|
# Copyright 2009-2020 Noviat
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, models
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
class ResPartner(models.Model):
|
class ResPartner(models.Model):
|
||||||
_inherit = 'res.partner'
|
_inherit = "res.partner"
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def export_xls(self):
|
def export_xls(self):
|
||||||
module = __name__.split('addons.')[1].split('.')[0]
|
module = __name__.split("addons.")[1].split(".")[0]
|
||||||
report_name = '{}.partner_export_xlsx'.format(module)
|
report_name = "{}.partner_export_xlsx".format(module)
|
||||||
report = {
|
report = {
|
||||||
'type': 'ir.actions.report',
|
"type": "ir.actions.report",
|
||||||
'report_type': 'xlsx',
|
"report_type": "xlsx",
|
||||||
'report_name': report_name,
|
"report_name": report_name,
|
||||||
# model name will be used if no report_file passed via context
|
# model name will be used if no report_file passed via context
|
||||||
'context': dict(self.env.context, report_file='partner'),
|
"context": dict(self.env.context, report_file="partner"),
|
||||||
# report_xlsx doesn't pass the context if the data dict is empty
|
# report_xlsx doesn't pass the context if the data dict is empty
|
||||||
# cf. report_xlsx\static\src\js\report\qwebactionmanager.js
|
# cf. report_xlsx\static\src\js\report\qwebactionmanager.js
|
||||||
# TODO: create PR on report_xlsx to fix this
|
# TODO: create PR on report_xlsx to fix this
|
||||||
'data': {'dynamic_report': True},
|
"data": {"dynamic_report": True},
|
||||||
}
|
}
|
||||||
return report
|
return report
|
||||||
|
|||||||
1
report_xlsx_helper_demo/readme/CONTRIBUTORS.rst
Normal file
1
report_xlsx_helper_demo/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* Luc De Meyer <luc.demeyer@noviat.com>
|
||||||
2
report_xlsx_helper_demo/readme/DESCRIPTION.rst
Normal file
2
report_xlsx_helper_demo/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
This module demonstrates the capabilities or the report_xlsx_helper module via
|
||||||
|
a basic example.
|
||||||
1
report_xlsx_helper_demo/readme/INSTALL.rst
Normal file
1
report_xlsx_helper_demo/readme/INSTALL.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
There is no specific installation procedure for this module.
|
||||||
1
report_xlsx_helper_demo/readme/USAGE.rst
Normal file
1
report_xlsx_helper_demo/readme/USAGE.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Open a partner record and click on the 'Export XLS' button.
|
||||||
@@ -1,64 +1,68 @@
|
|||||||
# Copyright 2009-2018 Noviat.
|
# Copyright 2009-2020 Noviat.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import models
|
from odoo import models
|
||||||
|
|
||||||
|
from odoo.addons.report_xlsx_helper.report.report_xlsx_format import (
|
||||||
|
FORMATS,
|
||||||
|
XLS_HEADERS,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PartnerExportXlsx(models.AbstractModel):
|
class PartnerExportXlsx(models.AbstractModel):
|
||||||
_name = 'report.report_xlsx_helper_demo.partner_export_xlsx'
|
_name = "report.report_xlsx_helper_demo.partner_export_xlsx"
|
||||||
_inherit = 'report.report_xlsx.abstract'
|
_description = "Report xlsx helpers"
|
||||||
|
_inherit = "report.report_xlsx.abstract"
|
||||||
|
|
||||||
def _get_ws_params(self, wb, data, partners):
|
def _get_ws_params(self, wb, data, partners):
|
||||||
|
|
||||||
partner_template = {
|
partner_template = {
|
||||||
'name': {
|
"name": {
|
||||||
'header': {
|
"header": {
|
||||||
'value': 'Name',
|
"value": "Name",
|
||||||
},
|
},
|
||||||
'data': {
|
"data": {
|
||||||
'value': self._render("partner.name"),
|
"value": self._render("partner.name"),
|
||||||
},
|
},
|
||||||
'width': 20,
|
"width": 20,
|
||||||
},
|
},
|
||||||
'number_of_contacts': {
|
"number_of_contacts": {
|
||||||
'header': {
|
"header": {
|
||||||
'value': '# Contacts',
|
"value": "# Contacts",
|
||||||
},
|
},
|
||||||
'data': {
|
"data": {
|
||||||
'value': self._render("len(partner.child_ids)"),
|
"value": self._render("len(partner.child_ids)"),
|
||||||
},
|
},
|
||||||
'width': 10,
|
"width": 10,
|
||||||
},
|
},
|
||||||
'is_customer': {
|
"is_company": {
|
||||||
'header': {
|
"header": {
|
||||||
'value': 'Customer',
|
"value": "Company",
|
||||||
},
|
},
|
||||||
'data': {
|
"data": {
|
||||||
'value': self._render("partner.customer"),
|
"value": self._render("partner.is_company"),
|
||||||
},
|
},
|
||||||
'width': 10,
|
"width": 10,
|
||||||
},
|
},
|
||||||
'is_customer_formula': {
|
"is_company_formula": {
|
||||||
'header': {
|
"header": {
|
||||||
'value': 'Customer Y/N ?',
|
"value": "Company Y/N ?",
|
||||||
},
|
},
|
||||||
'data': {
|
"data": {
|
||||||
'type': 'formula',
|
"type": "formula",
|
||||||
'value': self._render("customer_formula"),
|
"value": self._render("company_formula"),
|
||||||
},
|
},
|
||||||
'width': 14,
|
"width": 14,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
wanted_list = [
|
wanted_list = ["name", "number_of_contacts", "is_company", "is_company_formula"]
|
||||||
'name', 'number_of_contacts', 'is_customer',
|
|
||||||
'is_customer_formula']
|
|
||||||
ws_params = {
|
ws_params = {
|
||||||
'ws_name': 'Partners',
|
"ws_name": "Partners",
|
||||||
'generate_ws_method': '_partner_report',
|
"generate_ws_method": "_partner_report",
|
||||||
'title': 'Partners',
|
"title": "Partners",
|
||||||
'wanted_list': wanted_list,
|
"wanted_list": wanted_list,
|
||||||
'col_specs': partner_template,
|
"col_specs": partner_template,
|
||||||
}
|
}
|
||||||
|
|
||||||
return [ws_params]
|
return [ws_params]
|
||||||
@@ -67,32 +71,38 @@ class PartnerExportXlsx(models.AbstractModel):
|
|||||||
|
|
||||||
ws.set_portrait()
|
ws.set_portrait()
|
||||||
ws.fit_to_pages(1, 0)
|
ws.fit_to_pages(1, 0)
|
||||||
ws.set_header(self.xls_headers['standard'])
|
ws.set_header(XLS_HEADERS["xls_headers"]["standard"])
|
||||||
ws.set_footer(self.xls_footers['standard'])
|
ws.set_footer(XLS_HEADERS["xls_footers"]["standard"])
|
||||||
|
|
||||||
self._set_column_width(ws, ws_params)
|
self._set_column_width(ws, ws_params)
|
||||||
|
|
||||||
row_pos = 0
|
row_pos = 0
|
||||||
if len(partners) == 1:
|
if len(partners) == 1:
|
||||||
ws_params['title'] = partners.name
|
ws_params["title"] = partners.name
|
||||||
row_pos = self._write_ws_title(ws, row_pos, ws_params)
|
row_pos = self._write_ws_title(ws, row_pos, ws_params)
|
||||||
row_pos = self._write_line(
|
row_pos = self._write_line(
|
||||||
ws, row_pos, ws_params, col_specs_section='header',
|
ws,
|
||||||
default_format=self.format_theader_yellow_left)
|
row_pos,
|
||||||
|
ws_params,
|
||||||
|
col_specs_section="header",
|
||||||
|
default_format=FORMATS["format_theader_yellow_left"],
|
||||||
|
)
|
||||||
ws.freeze_panes(row_pos, 0)
|
ws.freeze_panes(row_pos, 0)
|
||||||
|
|
||||||
wl = ws_params['wanted_list']
|
wl = ws_params["wanted_list"]
|
||||||
|
|
||||||
for partner in partners:
|
for partner in partners:
|
||||||
is_customer_pos = 'is_customer' in wl and \
|
is_company_pos = "is_company" in wl and wl.index("is_company")
|
||||||
wl.index('is_customer')
|
is_company_cell = self._rowcol_to_cell(row_pos, is_company_pos)
|
||||||
is_customer_cell = self._rowcol_to_cell(
|
company_formula = 'IF({},"Y", "N")'.format(is_company_cell)
|
||||||
row_pos, is_customer_pos)
|
|
||||||
customer_formula = 'IF({},"Y", "N")'.format(is_customer_cell)
|
|
||||||
row_pos = self._write_line(
|
row_pos = self._write_line(
|
||||||
ws, row_pos, ws_params, col_specs_section='data',
|
ws,
|
||||||
|
row_pos,
|
||||||
|
ws_params,
|
||||||
|
col_specs_section="data",
|
||||||
render_space={
|
render_space={
|
||||||
'partner': partner,
|
"partner": partner,
|
||||||
'customer_formula': customer_formula,
|
"company_formula": company_formula,
|
||||||
},
|
},
|
||||||
default_format=self.format_tcell_left)
|
default_format=FORMATS["format_tcell_left"],
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="view_partner_form" model="ir.ui.view">
|
<record id="view_partner_form" model="ir.ui.view">
|
||||||
<field name="name">res.partner.test_xlsx</field>
|
<field name="name">res.partner.test_xlsx</field>
|
||||||
<field name="model">res.partner</field>
|
<field name="model">res.partner</field>
|
||||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
<field name="inherit_id" ref="base.view_partner_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<div name="button_box" position="inside">
|
<div name="button_box" position="inside">
|
||||||
<button type="object" class="oe_stat_button" icon="fa-file-excel-o" name="export_xls">
|
<button
|
||||||
|
type="object"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-file-excel-o"
|
||||||
|
name="export_xls"
|
||||||
|
>
|
||||||
<div class="o_form_field o_stat_info">
|
<div class="o_form_field o_stat_info">
|
||||||
<span class="o_stat_text">Export XLS</span>
|
<span class="o_stat_text">Export XLS</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../report_xlsx_helper_demo
|
||||||
6
setup/report_xlsx_helper_demo/setup.py
Normal file
6
setup/report_xlsx_helper_demo/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user