0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

帳票作成のテンプレートエンジン(いろいろ)

Posted at

テンプレートエンジン(いろいろ)

KOMAINU - FastAPI Repot Engine

image.png

odt系

py3o.template - odoo向けに開発

py3o.formatsのソースコードは、py3o.formats-0.3-py2-none-any.whl等から入手可能

py3o.formats
main.py
# -*- coding: utf-8 -*-

DEFAULT_MIMETYPE = "application/octet-stream"

FORMAT_WORD97 = "doc"
FORMAT_WORD2003 = "docx"
FORMAT_PDF = "pdf"
FORMAT_DOCBOOK = "docbook"
FORMAT_HTML = "html"
FORMAT_ODT = "odt"
FORMAT_ODS = "ods"
FORMAT_XLS = "xls"


class UnkownFormatException(Exception):
    pass


class Format(object):

    def __init__(self, name, odfname, mimetype=DEFAULT_MIMETYPE, native=False):
        self.name = name
        self.odfname = odfname
        self.mimetype = mimetype
        self.native = native


class Formats(object):

    def __init__(self):

        self._formats = {
            FORMAT_WORD97: Format(
                FORMAT_WORD97, "MS Word 97", "application/msword"
            ),
            FORMAT_WORD2003: Format(
                FORMAT_WORD2003, "MS Word 2003 XML",
                "application/vnd.openxmlformats-officedocument"
                ".wordprocessingml.document"
            ),
            FORMAT_PDF: Format(
                FORMAT_PDF, "writer_pdf_Export", "application/pdf"
            ),
            FORMAT_DOCBOOK: Format(
                FORMAT_DOCBOOK, "DocBook File", "application/xml"
            ),
            FORMAT_HTML: Format(FORMAT_HTML, "HTML", "text/html"),
            FORMAT_ODT: Format(
                FORMAT_ODT, "writer8",
                "application/vnd.oasis.opendocument.text",
                native=True,
            ),
            FORMAT_ODS: Format(
                FORMAT_ODS, "calc8",
                "application/vnd.oasis.opendocument.spreadsheet",
                native=True,
            ),
            FORMAT_XLS: Format(
                FORMAT_XLS, "MS Excel 97", "application/msexcel"
            ),
        }

    def get_format(self, name):
        f = self._formats.get(name)

        if not f:
            raise UnkownFormatException("Format {} is unkown".format(name))

        return f

    def get_known_format_names(self, nativeonly=False):
        """return the a list of names that can be used as format names in
        py3o.template.

        :param nativeonly: a boolean flag. If set to True will only return
        native formats.
        :type nativeonly: bool

        :return: list of chars
        :returntype: list

        :raises: nothing
        """
        if nativeonly:
            return [
                f for f in self._formats if self.get_format(f).native
            ]
        else:
            return [f for f in self._formats]

__init__.py
from py3o.formats.main import UnkownFormatException
from py3o.formats.main import Formats
from py3o.formats.main import Format
from py3o.formats.main import FORMAT_DOCBOOK
from py3o.formats.main import FORMAT_HTML
from py3o.formats.main import FORMAT_ODT
from py3o.formats.main import FORMAT_PDF
from py3o.formats.main import FORMAT_WORD2003
from py3o.formats.main import FORMAT_WORD97

secretary - odtを変換(jinja2)

python-odt-template - secretaryを元に開発

docx系

docxtpl

fastapi-report-engine

xlsx系

odoo

alnas-docx

py3o - server連携版

帳票サーバー

py3o - odoo向けのapiサーバー

javaベースの帳票生成API

odoo帳票のしくみ - report_xlsx

report_xlsx\__manifest__.py

分類 項目 内容 備考
外部依存 Python xlsxwriter external_dependencies に記述
xlrd
依存 (odoo) base
web
assets web.assets_backend action_manager_report.esm.js
code - __manifest__.py
report_xlsx/__manifest__.py
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
    "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",
    "category": "Reporting",
    "version": "18.0.1.0.0",
    "development_status": "Mature",
    "license": "AGPL-3",
    "external_dependencies": {"python": ["xlsxwriter", "xlrd"]},
    "depends": ["base", "web"],
    "demo": ["demo/report.xml"],
    "installable": True,
    "assets": {
        "web.assets_backend": [
            "report_xlsx/static/src/js/report/action_manager_report.esm.js",
        ],
    },
}

report_xlsx/__init__.py

分類 モジュール 説明 備考
controllers main.py ReportController 継承
models ir_report.py ReportActionモデル "ir.actions.report"の継承
report report_abstract_xlsx.py XLSX生成モジュール 各帳票で継承される
report_partner_xlsx.py Partner一覧作成 report.report_xlsx.abstract"の継承
__init__.py
report_xlsx/__init__.py
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import controllers
from . import models
from . import report

XLSX帳票生成のシーケンス図

odoo帳票エンジン - docxをまねしてodtへ

alnas-docx
docxtplとdocxcomposeとで、レポートを生成している。
HtmlToDocxは、docxファイル内にhtmlを埋め込むために使用している。

docxtplでレンダリングしているので、これをodtテンプレートエンジンに変更する。

テンプレートでは、"docs"でデータにできる。

pdf変換

unoserver - libreofficeのサービス化

pip install unoserver

LibreOffceのpython3環境で実行する必要がある

wget -O find_uno.py https://gist.githubusercontent.com/regebro/036da022dc7d5241a0ee97efdf1458eb/raw/find_uno.py
python find_uno.py

wget https://bootstrap.pypa.io/get-pip.py
/usr/bin/python3 get-pip.py
/usr/bin/python3 -m pip install unoserver -U

unoserverの起動

unoserver

pdf変換

unoconvert sampleja.odt sampleja.pdf

from unoserver import server

関連記事

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?