From 97e530adeb7267a49b18d1634d67b1d270f635fb Mon Sep 17 00:00:00 2001 From: Saran440 Date: Thu, 19 Nov 2020 17:37:45 +0700 Subject: [PATCH] [IMP] format xlsx to global files --- report_xlsx_helper/README.rst | 10 +- report_xlsx_helper/controllers/main.py | 5 - report_xlsx_helper/report/__init__.py | 1 + .../report/report_xlsx_abstract.py | 373 +++++++++++------- .../report/report_xlsx_format.py | 164 ++++++++ .../report/test_partner_report_xlsx.py | 11 +- .../static/description/index.html | 6 +- 7 files changed, 408 insertions(+), 162 deletions(-) create mode 100644 report_xlsx_helper/report/report_xlsx_format.py diff --git a/report_xlsx_helper/README.rst b/report_xlsx_helper/README.rst index 68579dfe..e7bfaea6 100644 --- a/report_xlsx_helper/README.rst +++ b/report_xlsx_helper/README.rst @@ -14,13 +14,13 @@ Report xlsx helpers :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github - :target: https://github.com/OCA/reporting-engine/tree/13.0/report_xlsx_helper + :target: https://github.com/OCA/reporting-engine/tree/14.0/report_xlsx_helper :alt: OCA/reporting-engine .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/reporting-engine-13-0/reporting-engine-13-0-report_xlsx_helper + :target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_xlsx_helper :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/143/13.0 + :target: https://runbot.odoo-community.org/runbot/143/14.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -79,7 +79,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -111,6 +111,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/reporting-engine `_ project on GitHub. +This module is part of the `OCA/reporting-engine `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/report_xlsx_helper/controllers/main.py b/report_xlsx_helper/controllers/main.py index cc64289f..e8542d5d 100644 --- a/report_xlsx_helper/controllers/main.py +++ b/report_xlsx_helper/controllers/main.py @@ -28,12 +28,7 @@ class ReportController(ReportController): if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): - # Ignore 'lang' here, because the context in data is the one - # from the webclient *but* if the user explicitely wants to - # change the lang, this mechanism overwrites it. data["context"] = json.loads(data["context"]) - if data["context"].get("lang"): - del data["context"]["lang"] context.update(data["context"]) context["report_name"] = reportname diff --git a/report_xlsx_helper/report/__init__.py b/report_xlsx_helper/report/__init__.py index 3222e9d5..8fa0a419 100644 --- a/report_xlsx_helper/report/__init__.py +++ b/report_xlsx_helper/report/__init__.py @@ -1,2 +1,3 @@ +from . import report_xlsx_format from . import report_xlsx_abstract from . import test_partner_report_xlsx diff --git a/report_xlsx_helper/report/report_xlsx_abstract.py b/report_xlsx_helper/report/report_xlsx_abstract.py index bb028780..b4eb0dfc 100644 --- a/report_xlsx_helper/report/report_xlsx_abstract.py +++ b/report_xlsx_helper/report/report_xlsx_abstract.py @@ -10,7 +10,7 @@ from xlsxwriter.utility import xl_rowcol_to_cell from odoo import _, fields, models from odoo.exceptions import UserError -_xxx = {} +from .report_xlsx_format import FORMATS, XLS_HEADERS class ReportXlsxAbstract(models.AbstractModel): @@ -79,11 +79,11 @@ class ReportXlsxAbstract(models.AbstractModel): "font_size": 8, "font_style": "I", # B: Bold, I: Italic, U: Underline } - self.xls_headers = {"standard": ""} + XLS_HEADERS["xls_headers"] = {"standard": ""} report_date = fields.Datetime.context_timestamp( self.env.user, datetime.now() ).strftime("%Y-%m-%d %H:%M") - self.xls_footers = { + XLS_HEADERS["xls_footers"] = { "standard": ( "&L&%(font_size)s&%(font_style)s" + report_date @@ -103,6 +103,7 @@ class ReportXlsxAbstract(models.AbstractModel): border_grey = "#D3D3D3" border = {"border": True, "border_color": border_grey} theader = dict(border, bold=True) + bg_grey = "#CCCCCC" bg_yellow = "#FFFFCC" bg_blue = "#CCFFFF" num_format = "#,##0.00" @@ -112,411 +113,495 @@ class ReportXlsxAbstract(models.AbstractModel): int_format = "#,##0" int_format_conditional = "{0};[Red]-{0};{0}".format(int_format) date_format = "YYYY-MM-DD" + theader_grey = dict(theader, bg_color=bg_grey) theader_yellow = dict(theader, bg_color=bg_yellow) theader_blue = dict(theader, bg_color=bg_blue) # format for worksheet title - self.format_ws_title = workbook.add_format({"bold": True, "font_size": 14}) + FORMATS["format_ws_title"] = workbook.add_format( + {"bold": True, "font_size": 14} + ) # no border formats - self.format_left = workbook.add_format({"align": "left"}) - self.format_center = workbook.add_format({"align": "center"}) - self.format_right = workbook.add_format({"align": "right"}) - self.format_amount_left = workbook.add_format( + FORMATS["format_left"] = workbook.add_format({"align": "left"}) + FORMATS["format_center"] = workbook.add_format({"align": "center"}) + FORMATS["format_right"] = workbook.add_format({"align": "right"}) + FORMATS["format_amount_left"] = workbook.add_format( {"align": "left", "num_format": num_format} ) - self.format_amount_center = workbook.add_format( + FORMATS["format_amount_center"] = workbook.add_format( {"align": "center", "num_format": num_format} ) - self.format_amount_right = workbook.add_format( + FORMATS["format_amount_right"] = workbook.add_format( {"align": "right", "num_format": num_format} ) - self.format_amount_conditional_left = workbook.add_format( + FORMATS["format_amount_conditional_left"] = workbook.add_format( {"align": "left", "num_format": num_format_conditional} ) - self.format_amount_conditional_center = workbook.add_format( + FORMATS["format_amount_conditional_center"] = workbook.add_format( {"align": "center", "num_format": num_format_conditional} ) - self.format_amount_conditional_right = workbook.add_format( + FORMATS["format_amount_conditional_right"] = workbook.add_format( {"align": "right", "num_format": num_format_conditional} ) - self.format_percent_left = workbook.add_format( + FORMATS["format_percent_left"] = workbook.add_format( {"align": "left", "num_format": pct_format} ) - self.format_percent_center = workbook.add_format( + FORMATS["format_percent_center"] = workbook.add_format( {"align": "center", "num_format": pct_format} ) - self.format_percent_right = workbook.add_format( + FORMATS["format_percent_right"] = workbook.add_format( {"align": "right", "num_format": pct_format} ) - self.format_percent_conditional_left = workbook.add_format( + FORMATS["format_percent_conditional_left"] = workbook.add_format( {"align": "left", "num_format": pct_format_conditional} ) - self.format_percent_conditional_center = workbook.add_format( + FORMATS["format_percent_conditional_center"] = workbook.add_format( {"align": "center", "num_format": pct_format_conditional} ) - self.format_percent_conditional_right = workbook.add_format( + FORMATS["format_percent_conditional_right"] = workbook.add_format( {"align": "right", "num_format": pct_format_conditional} ) - self.format_integer_left = workbook.add_format( + FORMATS["format_integer_left"] = workbook.add_format( {"align": "left", "num_format": int_format} ) - self.format_integer_center = workbook.add_format( + FORMATS["format_integer_center"] = workbook.add_format( {"align": "center", "num_format": int_format} ) - self.format_integer_right = workbook.add_format( + FORMATS["format_integer_right"] = workbook.add_format( {"align": "right", "num_format": int_format} ) - self.format_integer_conditional_left = workbook.add_format( + FORMATS["format_integer_conditional_left"] = workbook.add_format( {"align": "right", "num_format": int_format_conditional} ) - self.format_integer_conditional_center = workbook.add_format( + FORMATS["format_integer_conditional_center"] = workbook.add_format( {"align": "center", "num_format": int_format_conditional} ) - self.format_integer_conditional_right = workbook.add_format( + FORMATS["format_integer_conditional_right"] = workbook.add_format( {"align": "right", "num_format": int_format_conditional} ) - self.format_date_left = workbook.add_format( + FORMATS["format_date_left"] = workbook.add_format( {"align": "left", "num_format": date_format} ) - self.format_date_center = workbook.add_format( + FORMATS["format_date_center"] = workbook.add_format( {"align": "center", "num_format": date_format} ) - self.format_date_right = workbook.add_format( + FORMATS["format_date_right"] = workbook.add_format( {"align": "right", "num_format": date_format} ) - self.format_left_bold = workbook.add_format({"align": "left", "bold": True}) - self.format_center_bold = workbook.add_format({"align": "center", "bold": True}) - self.format_right_bold = workbook.add_format({"align": "right", "bold": True}) - self.format_amount_left_bold = workbook.add_format( + FORMATS["format_left_bold"] = workbook.add_format( + {"align": "left", "bold": True} + ) + FORMATS["format_center_bold"] = workbook.add_format( + {"align": "center", "bold": True} + ) + FORMATS["format_right_bold"] = workbook.add_format( + {"align": "right", "bold": True} + ) + FORMATS["format_amount_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": num_format} ) - self.format_amount_center_bold = workbook.add_format( + FORMATS["format_amount_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": num_format} ) - self.format_amount_right_bold = workbook.add_format( + FORMATS["format_amount_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": num_format} ) - self.format_amount_conditional_left_bold = workbook.add_format( + FORMATS["format_amount_conditional_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": num_format_conditional} ) - self.format_amount_conditional_center_bold = workbook.add_format( + FORMATS["format_amount_conditional_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": num_format_conditional} ) - self.format_amount_conditional_right_bold = workbook.add_format( + FORMATS["format_amount_conditional_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": num_format_conditional} ) - self.format_percent_left_bold = workbook.add_format( + FORMATS["format_percent_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": pct_format} ) - self.format_percent_center_bold = workbook.add_format( + FORMATS["format_percent_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": pct_format} ) - self.format_percent_right_bold = workbook.add_format( + FORMATS["format_percent_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": pct_format} ) - self.format_percent_conditional_left_bold = workbook.add_format( + FORMATS["format_percent_conditional_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": pct_format_conditional} ) - self.format_percent_conditional_center_bold = workbook.add_format( + FORMATS["format_percent_conditional_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": pct_format_conditional} ) - self.format_percent_conditional_right_bold = workbook.add_format( + FORMATS["format_percent_conditional_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": pct_format_conditional} ) - self.format_integer_left_bold = workbook.add_format( + FORMATS["format_integer_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": int_format} ) - self.format_integer_center_bold = workbook.add_format( + FORMATS["format_integer_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": int_format} ) - self.format_integer_right_bold = workbook.add_format( + FORMATS["format_integer_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": int_format} ) - self.format_integer_conditional_left_bold = workbook.add_format( + FORMATS["format_integer_conditional_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": int_format_conditional} ) - self.format_integer_conditional_center_bold = workbook.add_format( + FORMATS["format_integer_conditional_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": int_format_conditional} ) - self.format_integer_conditional_right_bold = workbook.add_format( + FORMATS["format_integer_conditional_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": int_format_conditional} ) - self.format_date_left_bold = workbook.add_format( + FORMATS["format_date_left_bold"] = workbook.add_format( {"align": "left", "bold": True, "num_format": date_format} ) - self.format_date_center_bold = workbook.add_format( + FORMATS["format_date_center_bold"] = workbook.add_format( {"align": "center", "bold": True, "num_format": date_format} ) - self.format_date_right_bold = workbook.add_format( + FORMATS["format_date_right_bold"] = workbook.add_format( {"align": "right", "bold": True, "num_format": date_format} ) # formats for worksheet table column headers - self.format_theader_yellow_left = workbook.add_format(theader_yellow) - self.format_theader_yellow_center = workbook.add_format( + FORMATS["format_theader_grey_left"] = workbook.add_format(theader_grey) + FORMATS["format_theader_grey_center"] = workbook.add_format( + dict(theader_grey, align="center") + ) + FORMATS["format_theader_grey_right"] = workbook.add_format( + dict(theader_grey, align="right") + ) + FORMATS["format_theader_grey_amount_left"] = workbook.add_format( + dict(theader_grey, num_format=num_format, align="left") + ) + FORMATS["format_theader_grey_amount_center"] = workbook.add_format( + dict(theader_grey, num_format=num_format, align="center") + ) + FORMATS["format_theader_grey_amount_right"] = workbook.add_format( + dict(theader_grey, num_format=num_format, align="right") + ) + + FORMATS["format_theader_grey_amount_conditional_left"] = workbook.add_format( + dict(theader_grey, num_format=num_format_conditional, align="left") + ) + FORMATS["format_theader_grey_amount_conditional_center"] = workbook.add_format( + dict(theader_grey, num_format=num_format_conditional, align="center") + ) + FORMATS["format_theader_grey_amount_conditional_right"] = workbook.add_format( + dict(theader_grey, num_format=num_format_conditional, align="right") + ) + FORMATS["format_theader_grey_percent_left"] = workbook.add_format( + dict(theader_grey, num_format=pct_format, align="left") + ) + FORMATS["format_theader_grey_percent_center"] = workbook.add_format( + dict(theader_grey, num_format=pct_format, align="center") + ) + FORMATS["format_theader_grey_percent_right"] = workbook.add_format( + dict(theader_grey, num_format=pct_format, align="right") + ) + FORMATS["format_theader_grey_percent_conditional_left"] = workbook.add_format( + dict(theader_grey, num_format=pct_format_conditional, align="left") + ) + FORMATS["format_theader_grey_percent_conditional_center"] = workbook.add_format( + dict(theader_grey, num_format=pct_format_conditional, align="center") + ) + FORMATS["format_theader_grey_percent_conditional_right"] = workbook.add_format( + dict(theader_grey, num_format=pct_format_conditional, align="right") + ) + FORMATS["format_theader_grey_integer_left"] = workbook.add_format( + dict(theader_grey, num_format=int_format, align="left") + ) + FORMATS["format_theader_grey_integer_center"] = workbook.add_format( + dict(theader_grey, num_format=int_format, align="center") + ) + FORMATS["format_theader_grey_integer_right"] = workbook.add_format( + dict(theader_grey, num_format=int_format, align="right") + ) + FORMATS["format_theader_grey_integer_conditional_left"] = workbook.add_format( + dict(theader_grey, num_format=int_format_conditional, align="left") + ) + FORMATS["format_theader_grey_integer_conditional_center"] = workbook.add_format( + dict(theader_grey, num_format=int_format_conditional, align="center") + ) + FORMATS["format_theader_grey_integer_conditional_right"] = workbook.add_format( + dict(theader_grey, num_format=int_format_conditional, align="right") + ) + + FORMATS["format_theader_yellow_left"] = workbook.add_format(theader_yellow) + FORMATS["format_theader_yellow_center"] = workbook.add_format( dict(theader_yellow, align="center") ) - self.format_theader_yellow_right = workbook.add_format( + FORMATS["format_theader_yellow_right"] = workbook.add_format( dict(theader_yellow, align="right") ) - self.format_theader_yellow_amount_left = workbook.add_format( + FORMATS["format_theader_yellow_amount_left"] = workbook.add_format( dict(theader_yellow, num_format=num_format, align="left") ) - self.format_theader_yellow_amount_center = workbook.add_format( + FORMATS["format_theader_yellow_amount_center"] = workbook.add_format( dict(theader_yellow, num_format=num_format, align="center") ) - self.format_theader_yellow_amount_right = workbook.add_format( + FORMATS["format_theader_yellow_amount_right"] = workbook.add_format( dict(theader_yellow, num_format=num_format, align="right") ) - self.format_theader_yellow_amount_conditional_left = workbook.add_format( + FORMATS["format_theader_yellow_amount_conditional_left"] = workbook.add_format( dict(theader_yellow, num_format=num_format_conditional, align="left") ) - self.format_theader_yellow_amount_conditional_center = workbook.add_format( + FORMATS[ + "format_theader_yellow_amount_conditional_center" + ] = workbook.add_format( dict(theader_yellow, num_format=num_format_conditional, align="center") ) - self.format_theader_yellow_amount_conditional_right = workbook.add_format( + FORMATS["format_theader_yellow_amount_conditional_right"] = workbook.add_format( dict(theader_yellow, num_format=num_format_conditional, align="right") ) - self.format_theader_yellow_percent_left = workbook.add_format( + FORMATS["format_theader_yellow_percent_left"] = workbook.add_format( dict(theader_yellow, num_format=pct_format, align="left") ) - self.format_theader_yellow_percent_center = workbook.add_format( + FORMATS["format_theader_yellow_percent_center"] = workbook.add_format( dict(theader_yellow, num_format=pct_format, align="center") ) - self.format_theader_yellow_percent_right = workbook.add_format( + FORMATS["format_theader_yellow_percent_right"] = workbook.add_format( dict(theader_yellow, num_format=pct_format, align="right") ) - self.format_theader_yellow_percent_conditional_left = workbook.add_format( + FORMATS["format_theader_yellow_percent_conditional_left"] = workbook.add_format( dict(theader_yellow, num_format=pct_format_conditional, align="left") ) - self.format_theader_yellow_percent_conditional_center = workbook.add_format( + FORMATS[ + "format_theader_yellow_percent_conditional_center" + ] = workbook.add_format( dict(theader_yellow, num_format=pct_format_conditional, align="center") ) - self.format_theader_yellow_percent_conditional_right = workbook.add_format( + FORMATS[ + "format_theader_yellow_percent_conditional_right" + ] = workbook.add_format( dict(theader_yellow, num_format=pct_format_conditional, align="right") ) - self.format_theader_yellow_integer_left = workbook.add_format( + FORMATS["format_theader_yellow_integer_left"] = workbook.add_format( dict(theader_yellow, num_format=int_format, align="left") ) - self.format_theader_yellow_integer_center = workbook.add_format( + FORMATS["format_theader_yellow_integer_center"] = workbook.add_format( dict(theader_yellow, num_format=int_format, align="center") ) - self.format_theader_yellow_integer_right = workbook.add_format( + FORMATS["format_theader_yellow_integer_right"] = workbook.add_format( dict(theader_yellow, num_format=int_format, align="right") ) - self.format_theader_yellow_integer_conditional_left = workbook.add_format( + FORMATS["format_theader_yellow_integer_conditional_left"] = workbook.add_format( dict(theader_yellow, num_format=int_format_conditional, align="left") ) - self.format_theader_yellow_integer_conditional_center = workbook.add_format( + FORMATS[ + "format_theader_yellow_integer_conditional_center" + ] = workbook.add_format( dict(theader_yellow, num_format=int_format_conditional, align="center") ) - self.format_theader_yellow_integer_conditional_right = workbook.add_format( + FORMATS[ + "format_theader_yellow_integer_conditional_right" + ] = workbook.add_format( dict(theader_yellow, num_format=int_format_conditional, align="right") ) - self.format_theader_blue_left = workbook.add_format(theader_blue) - self.format_theader_blue_center = workbook.add_format( + FORMATS["format_theader_blue_left"] = workbook.add_format(theader_blue) + FORMATS["format_theader_blue_center"] = workbook.add_format( dict(theader_blue, align="center") ) - self.format_theader_blue_right = workbook.add_format( + FORMATS["format_theader_blue_right"] = workbook.add_format( dict(theader_blue, align="right") ) - self.format_theader_blue_amount_left = workbook.add_format( + FORMATS["format_theader_blue_amount_left"] = workbook.add_format( dict(theader_blue, num_format=num_format, align="left") ) - self.format_theader_blue_amount_center = workbook.add_format( + FORMATS["format_theader_blue_amount_center"] = workbook.add_format( dict(theader_blue, num_format=num_format, align="center") ) - self.format_theader_blue_amount_right = workbook.add_format( + FORMATS["format_theader_blue_amount_right"] = workbook.add_format( dict(theader_blue, num_format=num_format, align="right") ) - self.format_theader_blue_amount_conditional_left = workbook.add_format( + FORMATS["format_theader_blue_amount_conditional_left"] = workbook.add_format( dict(theader_blue, num_format=num_format_conditional, align="left") ) - self.format_theader_blue_amount_conditional_center = workbook.add_format( + FORMATS["format_theader_blue_amount_conditional_center"] = workbook.add_format( dict(theader_blue, num_format=num_format_conditional, align="center") ) - self.format_theader_blue_amount_conditional_right = workbook.add_format( + FORMATS["format_theader_blue_amount_conditional_right"] = workbook.add_format( dict(theader_blue, num_format=num_format_conditional, align="right") ) - self.format_theader_blue_percent_left = workbook.add_format( + FORMATS["format_theader_blue_percent_left"] = workbook.add_format( dict(theader_blue, num_format=pct_format, align="left") ) - self.format_theader_blue_percent_center = workbook.add_format( + FORMATS["format_theader_blue_percent_center"] = workbook.add_format( dict(theader_blue, num_format=pct_format, align="center") ) - self.format_theader_blue_percent_right = workbook.add_format( + FORMATS["format_theader_blue_percent_right"] = workbook.add_format( dict(theader_blue, num_format=pct_format, align="right") ) - self.format_theader_blue_percent_conditional_left = workbook.add_format( + FORMATS["format_theader_blue_percent_conditional_left"] = workbook.add_format( dict(theader_blue, num_format=pct_format_conditional, align="left") ) - self.format_theader_blue_percent_conditional_center = workbook.add_format( + FORMATS["format_theader_blue_percent_conditional_center"] = workbook.add_format( dict(theader_blue, num_format=pct_format_conditional, align="center") ) - self.format_theader_blue_percent_conditional_right = workbook.add_format( + FORMATS["format_theader_blue_percent_conditional_right"] = workbook.add_format( dict(theader_blue, num_format=pct_format_conditional, align="right") ) - self.format_theader_blue_integer_left = workbook.add_format( + FORMATS["format_theader_blue_integer_left"] = workbook.add_format( dict(theader_blue, num_format=int_format, align="left") ) - self.format_theader_blue_integer_center = workbook.add_format( + FORMATS["format_theader_blue_integer_center"] = workbook.add_format( dict(theader_blue, num_format=int_format, align="center") ) - self.format_theader_blue_integer_right = workbook.add_format( + FORMATS["format_theader_blue_integer_right"] = workbook.add_format( dict(theader_blue, num_format=int_format, align="right") ) - self.format_theader_blue_integer_conditional_left = workbook.add_format( + FORMATS["format_theader_blue_integer_conditional_left"] = workbook.add_format( dict(theader_blue, num_format=int_format_conditional, align="left") ) - self.format_theader_blue_integer_conditional_center = workbook.add_format( + FORMATS["format_theader_blue_integer_conditional_center"] = workbook.add_format( dict(theader_blue, num_format=int_format_conditional, align="center") ) - self.format_theader_blue_integer_conditional_right = workbook.add_format( + FORMATS["format_theader_blue_integer_conditional_right"] = workbook.add_format( dict(theader_blue, num_format=int_format_conditional, align="right") ) # formats for worksheet table cells - self.format_tcell_left = workbook.add_format(dict(border, align="left")) - self.format_tcell_center = workbook.add_format(dict(border, align="center")) - self.format_tcell_right = workbook.add_format(dict(border, align="right")) - self.format_tcell_amount_left = workbook.add_format( + FORMATS["format_tcell_left"] = workbook.add_format(dict(border, align="left")) + FORMATS["format_tcell_center"] = workbook.add_format( + dict(border, align="center") + ) + FORMATS["format_tcell_right"] = workbook.add_format(dict(border, align="right")) + FORMATS["format_tcell_amount_left"] = workbook.add_format( dict(border, num_format=num_format, align="left") ) - self.format_tcell_amount_center = workbook.add_format( + FORMATS["format_tcell_amount_center"] = workbook.add_format( dict(border, num_format=num_format, align="center") ) - self.format_tcell_amount_right = workbook.add_format( + FORMATS["format_tcell_amount_right"] = workbook.add_format( dict(border, num_format=num_format, align="right") ) - self.format_tcell_amount_conditional_left = workbook.add_format( + FORMATS["format_tcell_amount_conditional_left"] = workbook.add_format( dict(border, num_format=num_format_conditional, align="left") ) - self.format_tcell_amount_conditional_center = workbook.add_format( + FORMATS["format_tcell_amount_conditional_center"] = workbook.add_format( dict(border, num_format=num_format_conditional, align="center") ) - self.format_tcell_amount_conditional_right = workbook.add_format( + FORMATS["format_tcell_amount_conditional_right"] = workbook.add_format( dict(border, num_format=num_format_conditional, align="right") ) - self.format_tcell_percent_left = workbook.add_format( + FORMATS["format_tcell_percent_left"] = workbook.add_format( dict(border, num_format=pct_format, align="left") ) - self.format_tcell_percent_center = workbook.add_format( + FORMATS["format_tcell_percent_center"] = workbook.add_format( dict(border, num_format=pct_format, align="center") ) - self.format_tcell_percent_right = workbook.add_format( + FORMATS["format_tcell_percent_right"] = workbook.add_format( dict(border, num_format=pct_format, align="right") ) - self.format_tcell_percent_conditional_left = workbook.add_format( + FORMATS["format_tcell_percent_conditional_left"] = workbook.add_format( dict(border, num_format=pct_format_conditional, align="left") ) - self.format_tcell_percent_conditional_center = workbook.add_format( + FORMATS["format_tcell_percent_conditional_center"] = workbook.add_format( dict(border, num_format=pct_format_conditional, align="center") ) - self.format_tcell_percent_conditional_right = workbook.add_format( + FORMATS["format_tcell_percent_conditional_right"] = workbook.add_format( dict(border, num_format=pct_format_conditional, align="right") ) - self.format_tcell_integer_left = workbook.add_format( + FORMATS["format_tcell_integer_left"] = workbook.add_format( dict(border, num_format=int_format, align="left") ) - self.format_tcell_integer_center = workbook.add_format( + FORMATS["format_tcell_integer_center"] = workbook.add_format( dict(border, num_format=int_format, align="center") ) - self.format_tcell_integer_right = workbook.add_format( + FORMATS["format_tcell_integer_right"] = workbook.add_format( dict(border, num_format=int_format, align="right") ) - self.format_tcell_integer_conditional_left = workbook.add_format( + FORMATS["format_tcell_integer_conditional_left"] = workbook.add_format( dict(border, num_format=int_format_conditional, align="left") ) - self.format_tcell_integer_conditional_center = workbook.add_format( + FORMATS["format_tcell_integer_conditional_center"] = workbook.add_format( dict(border, num_format=int_format_conditional, align="center") ) - self.format_tcell_integer_conditional_right = workbook.add_format( + FORMATS["format_tcell_integer_conditional_right"] = workbook.add_format( dict(border, num_format=int_format_conditional, align="right") ) - self.format_tcell_date_left = workbook.add_format( + FORMATS["format_tcell_date_left"] = workbook.add_format( dict(border, num_format=date_format, align="left") ) - self.format_tcell_date_center = workbook.add_format( + FORMATS["format_tcell_date_center"] = workbook.add_format( dict(border, num_format=date_format, align="center") ) - self.format_tcell_date_right = workbook.add_format( + FORMATS["format_tcell_date_right"] = workbook.add_format( dict(border, num_format=date_format, align="right") ) - self.format_tcell_left_bold = workbook.add_format( + FORMATS["format_tcell_left_bold"] = workbook.add_format( dict(border, align="left", bold=True) ) - self.format_tcell_center_bold = workbook.add_format( + FORMATS["format_tcell_center_bold"] = workbook.add_format( dict(border, align="center", bold=True) ) - self.format_tcell_right_bold = workbook.add_format( + FORMATS["format_tcell_right_bold"] = workbook.add_format( dict(border, align="right", bold=True) ) - self.format_tcell_amount_left_bold = workbook.add_format( + FORMATS["format_tcell_amount_left_bold"] = workbook.add_format( dict(border, num_format=num_format, align="left", bold=True) ) - self.format_tcell_amount_center_bold = workbook.add_format( + FORMATS["format_tcell_amount_center_bold"] = workbook.add_format( dict(border, num_format=num_format, align="center", bold=True) ) - self.format_tcell_amount_right_bold = workbook.add_format( + FORMATS["format_tcell_amount_right_bold"] = workbook.add_format( dict(border, num_format=num_format, align="right", bold=True) ) - self.format_tcell_amount_conditional_left_bold = workbook.add_format( + FORMATS["format_tcell_amount_conditional_left_bold"] = workbook.add_format( dict(border, num_format=num_format_conditional, align="left", bold=True) ) - self.format_tcell_amount_conditional_center_bold = workbook.add_format( + FORMATS["format_tcell_amount_conditional_center_bold"] = workbook.add_format( dict(border, num_format=num_format_conditional, align="center", bold=True) ) - self.format_tcell_amount_conditional_right_bold = workbook.add_format( + FORMATS["format_tcell_amount_conditional_right_bold"] = workbook.add_format( dict(border, num_format=num_format_conditional, align="right", bold=True) ) - self.format_tcell_percent_left_bold = workbook.add_format( + FORMATS["format_tcell_percent_left_bold"] = workbook.add_format( dict(border, num_format=pct_format, align="left", bold=True) ) - self.format_tcell_percent_center_bold = workbook.add_format( + FORMATS["format_tcell_percent_center_bold"] = workbook.add_format( dict(border, num_format=pct_format, align="center", bold=True) ) - self.format_tcell_percent_right_bold = workbook.add_format( + FORMATS["format_tcell_percent_right_bold"] = workbook.add_format( dict(border, num_format=pct_format, align="right", bold=True) ) - self.format_tcell_percent_conditional_left_bold = workbook.add_format( + FORMATS["format_tcell_percent_conditional_left_bold"] = workbook.add_format( dict(border, num_format=pct_format_conditional, align="left", bold=True) ) - self.format_tcell_percent_conditional_center_bold = workbook.add_format( + FORMATS["format_tcell_percent_conditional_center_bold"] = workbook.add_format( dict(border, num_format=pct_format_conditional, align="center", bold=True) ) - self.format_tcell_percent_conditional_right_bold = workbook.add_format( + FORMATS["format_tcell_percent_conditional_right_bold"] = workbook.add_format( dict(border, num_format=pct_format_conditional, align="right", bold=True) ) - self.format_tcell_integer_left_bold = workbook.add_format( + FORMATS["format_tcell_integer_left_bold"] = workbook.add_format( dict(border, num_format=int_format, align="left", bold=True) ) - self.format_tcell_integer_center_bold = workbook.add_format( + FORMATS["format_tcell_integer_center_bold"] = workbook.add_format( dict(border, num_format=int_format, align="center", bold=True) ) - self.format_tcell_integer_right_bold = workbook.add_format( + FORMATS["format_tcell_integer_right_bold"] = workbook.add_format( dict(border, num_format=int_format, align="right", bold=True) ) - self.format_tcell_integer_conditional_left_bold = workbook.add_format( + FORMATS["format_tcell_integer_conditional_left_bold"] = workbook.add_format( dict(border, num_format=int_format_conditional, align="left", bold=True) ) - self.format_tcell_integer_conditional_center_bold = workbook.add_format( + FORMATS["format_tcell_integer_conditional_center_bold"] = workbook.add_format( dict(border, num_format=int_format_conditional, align="center", bold=True) ) - self.format_tcell_integer_conditional_right_bold = workbook.add_format( + FORMATS["format_tcell_integer_conditional_right_bold"] = workbook.add_format( dict(border, num_format=int_format_conditional, align="right", bold=True) ) - self.format_tcell_date_left_bold = workbook.add_format( + FORMATS["format_tcell_date_left_bold"] = workbook.add_format( dict(border, num_format=date_format, align="left", bold=True) ) - self.format_tcell_date_center_bold = workbook.add_format( + FORMATS["format_tcell_date_center_bold"] = workbook.add_format( dict(border, num_format=date_format, align="center", bold=True) ) - self.format_tcell_date_right_bold = workbook.add_format( + FORMATS["format_tcell_date_right_bold"] = workbook.add_format( dict(border, num_format=date_format, align="right", bold=True) ) @@ -557,10 +642,10 @@ class ReportXlsxAbstract(models.AbstractModel): wl = ws_params.get("wanted_list") if wl and len(wl) > 1: ws.merge_range( - row_pos, 0, row_pos, len(wl) - 1, title, self.format_ws_title + row_pos, 0, row_pos, len(wl) - 1, title, FORMATS["format_ws_title"] ) else: - ws.write_string(row_pos, 0, title, self.format_ws_title) + ws.write_string(row_pos, 0, title, FORMATS["format_ws_title"]) return row_pos + 2 def _write_line( diff --git a/report_xlsx_helper/report/report_xlsx_format.py b/report_xlsx_helper/report/report_xlsx_format.py new file mode 100644 index 00000000..9e60acab --- /dev/null +++ b/report_xlsx_helper/report/report_xlsx_format.py @@ -0,0 +1,164 @@ +# Global Formatting +XLS_HEADERS = {"xls_headers": "", "xls_footers": ""} +FORMATS = { + "format_ws_title": False, + "format_left": False, + "format_center": False, + "format_right": False, + "format_amount_left": False, + "format_amount_center": False, + "format_amount_right": False, + "format_amount_conditional_left": False, + "format_amount_conditional_center": False, + "format_amount_conditional_right": False, + "format_percent_left": False, + "format_percent_center": False, + "format_percent_right": False, + "format_percent_conditional_left": False, + "format_percent_conditional_center": False, + "format_percent_conditional_right": False, + "format_integer_left": False, + "format_integer_center": False, + "format_integer_right": False, + "format_integer_conditional_left": False, + "format_integer_conditional_center": False, + "format_integer_conditional_right": False, + "format_date_left": False, + "format_date_center": False, + "format_date_right": False, + "format_left_bold": False, + "format_center_bold": False, + "format_right_bold": False, + "format_amount_left_bold": False, + "format_amount_center_bold": False, + "format_amount_right_bold": False, + "format_amount_conditional_left_bold": False, + "format_amount_conditional_center_bold": False, + "format_amount_conditional_right_bold": False, + "format_percent_left_bold": False, + "format_percent_center_bold": False, + "format_percent_right_bold": False, + "format_percent_conditional_left_bold": False, + "format_percent_conditional_center_bold": False, + "format_percent_conditional_right_bold": False, + "format_integer_left_bold": False, + "format_integer_center_bold": False, + "format_integer_right_bold": False, + "format_integer_conditional_left_bold": False, + "format_integer_conditional_center_bold": False, + "format_integer_conditional_right_bold": False, + "format_date_left_bold": False, + "format_date_center_bold": False, + "format_date_right_bold": False, + "format_theader_grey_left": False, + "format_theader_grey_center": False, + "format_theader_grey_right": False, + "format_theader_grey_amount_left": False, + "format_theader_grey_amount_center": False, + "format_theader_grey_amount_right": False, + "format_theader_grey_amount_conditional_left": False, + "format_theader_grey_amount_conditional_center": False, + "format_theader_grey_amount_conditional_right": False, + "format_theader_grey_percent_left": False, + "format_theader_grey_percent_center": False, + "format_theader_grey_percent_right": False, + "format_theader_grey_percent_conditional_left": False, + "format_theader_grey_percent_conditional_center": False, + "format_theader_grey_percent_conditional_right": False, + "format_theader_grey_integer_left": False, + "format_theader_grey_integer_center": False, + "format_theader_grey_integer_right": False, + "format_theader_grey_integer_conditional_left": False, + "format_theader_grey_integer_conditional_center": False, + "format_theader_grey_integer_conditional_right": False, + "format_theader_yellow_left": False, + "format_theader_yellow_center": False, + "format_theader_yellow_right": False, + "format_theader_yellow_amount_left": False, + "format_theader_yellow_amount_center": False, + "format_theader_yellow_amount_right": False, + "format_theader_yellow_amount_conditional_left": False, + "format_theader_yellow_amount_conditional_center": False, + "format_theader_yellow_amount_conditional_right": False, + "format_theader_yellow_percent_left": False, + "format_theader_yellow_percent_center": False, + "format_theader_yellow_percent_right": False, + "format_theader_yellow_percent_conditional_left": False, + "format_theader_yellow_percent_conditional_center": False, + "format_theader_yellow_percent_conditional_right": False, + "format_theader_yellow_integer_left": False, + "format_theader_yellow_integer_center": False, + "format_theader_yellow_integer_right": False, + "format_theader_yellow_integer_conditional_left": False, + "format_theader_yellow_integer_conditional_center": False, + "format_theader_yellow_integer_conditional_right": False, + "format_theader_blue_left": False, + "format_theader_blue_center": False, + "format_theader_blue_right": False, + "format_theader_blue_amount_left": False, + "format_theader_blue_amount_center": False, + "format_theader_blue_amount_right": False, + "format_theader_blue_amount_conditional_left": False, + "format_theader_blue_amount_conditional_center": False, + "format_theader_blue_amount_conditional_right": False, + "format_theader_blue_percent_left": False, + "format_theader_blue_percent_center": False, + "format_theader_blue_percent_right": False, + "format_theader_blue_percent_conditional_left": False, + "format_theader_blue_percent_conditional_center": False, + "format_theader_blue_percent_conditional_right": False, + "format_theader_blue_integer_left": False, + "format_theader_blue_integer_center": False, + "format_theader_blue_integer_right": False, + "format_theader_blue_integer_conditional_left": False, + "format_theader_blue_integer_conditional_center": False, + "format_theader_blue_integer_conditional_right": False, + "format_tcell_left": False, + "format_tcell_center": False, + "format_tcell_right": False, + "format_tcell_amount_left": False, + "format_tcell_amount_center": False, + "format_tcell_amount_right": False, + "format_tcell_amount_conditional_left": False, + "format_tcell_amount_conditional_center": False, + "format_tcell_amount_conditional_right": False, + "format_tcell_percent_left": False, + "format_tcell_percent_center": False, + "format_tcell_percent_right": False, + "format_tcell_percent_conditional_left": False, + "format_tcell_percent_conditional_center": False, + "format_tcell_percent_conditional_right": False, + "format_tcell_integer_left": False, + "format_tcell_integer_center": False, + "format_tcell_integer_right": False, + "format_tcell_integer_conditional_left": False, + "format_tcell_integer_conditional_center": False, + "format_tcell_integer_conditional_right": False, + "format_tcell_date_left": False, + "format_tcell_date_center": False, + "format_tcell_date_right": False, + "format_tcell_left_bold": False, + "format_tcell_center_bold": False, + "format_tcell_right_bold": False, + "format_tcell_amount_left_bold": False, + "format_tcell_amount_center_bold": False, + "format_tcell_amount_right_bold": False, + "format_tcell_amount_conditional_left_bold": False, + "format_tcell_amount_conditional_center_bold": False, + "format_tcell_amount_conditional_right_bold": False, + "format_tcell_percent_left_bold": False, + "format_tcell_percent_center_bold": False, + "format_tcell_percent_right_bold": False, + "format_tcell_percent_conditional_left_bold": False, + "format_tcell_percent_conditional_center_bold": False, + "format_tcell_percent_conditional_right_bold": False, + "format_tcell_integer_left_bold": False, + "format_tcell_integer_center_bold": False, + "format_tcell_integer_right_bold": False, + "format_tcell_integer_conditional_left_bold": False, + "format_tcell_integer_conditional_center_bold": False, + "format_tcell_integer_conditional_right_bold": False, + "format_tcell_date_left_bold": False, + "format_tcell_date_center_bold": False, + "format_tcell_date_right_bold": False, +} diff --git a/report_xlsx_helper/report/test_partner_report_xlsx.py b/report_xlsx_helper/report/test_partner_report_xlsx.py index f175608d..481e5575 100644 --- a/report_xlsx_helper/report/test_partner_report_xlsx.py +++ b/report_xlsx_helper/report/test_partner_report_xlsx.py @@ -3,6 +3,8 @@ from odoo import models +from .report_xlsx_format import FORMATS, XLS_HEADERS + # TODO: # make PR to move this class as well as the report_xlsx test class @@ -47,9 +49,8 @@ class TestPartnerXlsx(models.AbstractModel): ws.set_portrait() ws.fit_to_pages(1, 0) - ws.set_header(self.xls_headers["standard"]) - ws.set_footer(self.xls_footers["standard"]) - + ws.set_header(XLS_HEADERS["xls_headers"]["standard"]) + ws.set_footer(XLS_HEADERS["xls_footers"]["standard"]) self._set_column_width(ws, ws_params) row_pos = 0 @@ -59,7 +60,7 @@ class TestPartnerXlsx(models.AbstractModel): row_pos, ws_params, col_specs_section="header", - default_format=self.format_theader_yellow_left, + default_format=FORMATS["format_theader_yellow_left"], ) ws.freeze_panes(row_pos, 0) @@ -70,5 +71,5 @@ class TestPartnerXlsx(models.AbstractModel): ws_params, col_specs_section="data", render_space={"partner": partner}, - default_format=self.format_tcell_left, + default_format=FORMATS["format_tcell_left"], ) diff --git a/report_xlsx_helper/static/description/index.html b/report_xlsx_helper/static/description/index.html index c96aa0eb..655de838 100644 --- a/report_xlsx_helper/static/description/index.html +++ b/report_xlsx_helper/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runbot

This module provides a set of tools to facilitate the creation of excel reports with format xlsx.

Table of contents

@@ -424,7 +424,7 @@ from http://apps.odoo.

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -450,7 +450,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/reporting-engine project on GitHub.

+

This module is part of the OCA/reporting-engine project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.