From b50927753bb884dfcfc9b661d3d57c3dd77c2fc8 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Wed, 31 Aug 2022 17:32:01 +0200 Subject: [PATCH] kategorie: export als qif --- __init__.py | 4 + category.py | 15 +++ locale/de.po | 4 + qif_export.py | 27 +++++ qif_export.xml | 23 ++++ qiftool.py | 12 +++ report/exort.fods | 240 +++++++++++++++++++++++++++++++++++++++++ setup.py | 3 +- tests/test_category.py | 48 +++++++++ tryton.cfg | 1 + 10 files changed, 376 insertions(+), 1 deletion(-) create mode 100644 qif_export.py create mode 100644 qif_export.xml create mode 100644 report/exort.fods diff --git a/__init__.py b/__init__.py index 780ef43..d703d42 100644 --- a/__init__.py +++ b/__init__.py @@ -7,6 +7,7 @@ from trytond.pool import Pool from .category import Category from .qiftool import QifTool from .qif_import_wiz import ImportQifWizard, ImportQifWizardStart, ImportQifWizardInfo +from .qif_export import QifCategoryExport def register(): Pool.register( @@ -15,6 +16,9 @@ def register(): ImportQifWizardStart, ImportQifWizardInfo, module='cashbook_dataexchange', type_='model') + Pool.register( + QifCategoryExport, + module='cashbook_dataexchange', type_='report') Pool.register( ImportQifWizard, module='cashbook_dataexchange', type_='wizard') diff --git a/category.py b/category.py index 05f31de..d347f34 100644 --- a/category.py +++ b/category.py @@ -10,6 +10,21 @@ from trytond.pool import Pool, PoolMeta class Category(metaclass=PoolMeta): __name__ = 'cashbook.category' + @classmethod + def export_as_qif(cls): + """ export all accessible categories as QIF + """ + pool = Pool() + Category2 = pool.get('cashbook.category') + QifTool = pool.get('cashbook_dataexchange.qiftool') + + categories = Category2.search([], + order=[('cattype', 'ASC'), ('rec_name', 'ASC')]) + + export = ['!Type:Cat'] + export.extend([QifTool.qif_export_category(x) for x in categories]) + return '\n'.join(export) + @classmethod def create_from_qif(cls, qifdata): """ add categories from QIF-File-content diff --git a/locale/de.po b/locale/de.po index 09c0727..730f94e 100644 --- a/locale/de.po +++ b/locale/de.po @@ -18,6 +18,10 @@ msgctxt "model:ir.action,name:act_import_qif_wizard" msgid "Import QIF-File" msgstr "QIF-Datei importieren" +msgctxt "model:ir.action,name:qif_category_report" +msgid "Export QIF-File" +msgstr "QIF-Datei exportieren" + msgctxt "model:ir.action,name:msg_wiz_no_categories" msgid "No categories were found in the file." msgstr "In der Datei wurden keine Kategorien gefunden." diff --git a/qif_export.py b/qif_export.py new file mode 100644 index 0000000..d54d9c4 --- /dev/null +++ b/qif_export.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# This file is part of the cashbook-module from m-ds for Tryton. +# The COPYRIGHT file at the top level of this repository contains the +# full copyright notices and license terms. + +from trytond.report import Report +from trytond.pool import Pool + + +class QifCategoryExport(Report): + __name__ = 'cashbook_dataexchange.rep_category' + + @classmethod + def execute(cls, ids, data): + """ filename for export + """ + pool = Pool() + IrDate = pool.get('ir.date') + Category = pool.get('cashbook.category') + + return ( + 'qif', + Category.export_as_qif(), + False, + '%s-categories' % IrDate.today().isoformat().replace('-', '')) + +# end QifCategoryExport diff --git a/qif_export.xml b/qif_export.xml new file mode 100644 index 0000000..26507a9 --- /dev/null +++ b/qif_export.xml @@ -0,0 +1,23 @@ + + + + + + + Export QIF-File + cashbook.category + cashbook_dataexchange.rep_category + cashbook_dataexchange/report/export.fods + ods + + + + form_action + cashbook.category,-1 + + + + + diff --git a/qiftool.py b/qiftool.py index 0743f3b..c00bdd2 100644 --- a/qiftool.py +++ b/qiftool.py @@ -78,4 +78,16 @@ class QifTool(Model): categories[cattype] = add_category(categories[cattype], catname, cattype) return categories + @classmethod + def qif_export_category(cls, record): + """ export single category as qif + """ + return '\n'.join([ + 'N%(cname)s' % { + 'cname': record.rec_name.replace('/', ':'), + }, + 'E' if record.cattype == 'out' else 'I', + '^', + ]) + # end QifTool diff --git a/report/exort.fods b/report/exort.fods new file mode 100644 index 0000000..86a7924 --- /dev/null +++ b/report/exort.fods @@ -0,0 +1,240 @@ + + + + 2017-10-20T23:41:04.964000000LibreOffice/6.0.7.3$Linux_X86_64 LibreOffice_project/00m0$Build-3 + + + 0 + 0 + 2257 + 451 + + + view1 + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 100 + 60 + true + false + + + Sheet1 + 1828 + 0 + 100 + 60 + false + true + true + true + 12632256 + true + true + true + true + false + false + false + 1270 + 1270 + 1 + 1 + true + false + + + + + 7 + true + false + false + 0 + true + owH+/0hQX0xhc2VySmV0X01GUF9NNDI2ZmRuX0IyNUM3Ml8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ1VQUzpIUF9MYXNlckpldF9NRlBfTTQyNmZkbl9CMgAWAAMAxAAAAAAAAAAEAAhSAAAEdAAASm9iRGF0YSAxCnByaW50ZXI9SFBfTGFzZXJKZXRfTUZQX000MjZmZG5fQjI1QzcyXwpvcmllbnRhdGlvbj1Qb3J0cmFpdApjb3BpZXM9MQpjb2xsYXRlPWZhbHNlCm1hcmdpbmRhanVzdG1lbnQ9MCwwLDAsMApjb2xvcmRlcHRoPTI0CnBzbGV2ZWw9MApwZGZkZXZpY2U9MQpjb2xvcmRldmljZT0wClBQRENvbnRleERhdGEKUGFnZVNpemU6QTQAABIAQ09NUEFUX0RVUExFWF9NT0RFDwBEdXBsZXhNb2RlOjpPZmY= + HP_LaserJet_MFP_M426fdn_B25C72_ + true + 3 + true + false + true + true + 12632256 + true + true + true + false + true + false + true + 1 + false + 1270 + 1270 + false + 1 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ??? + + + + Page 1 + + + + + + + ???(???) + + + 00.00.0000, 00:00:00 + + + + + Page 1/ 99 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/setup.py b/setup.py index 1eff6ad..61227b6 100644 --- a/setup.py +++ b/setup.py @@ -97,7 +97,8 @@ setup(name='%s_%s' % (PREFIX, MODULE), package_data={ 'trytond.modules.%s' % MODULE: (info.get('xml', []) + ['tryton.cfg', 'locale/*.po', 'tests/*.py', - 'view/*.xml', 'versiondep.txt', 'README.rst']), + 'report/*.fods', 'view/*.xml', + 'versiondep.txt', 'README.rst']), }, install_requires=requires, diff --git a/tests/test_category.py b/tests/test_category.py index 753aab5..1487cc9 100644 --- a/tests/test_category.py +++ b/tests/test_category.py @@ -123,6 +123,54 @@ Lebensmittel (out)""") self.assertEqual(records[13].rec_name, 'Telekommunikation/Telefon') self.assertEqual(records[14].rec_name, 'Telekommunikation/Telefon/Test1') + result = Category.export_as_qif() + self.assertEqual(result, """!Type:Cat +NFernsehen +E +^ +NFernsehen:GEZ +E +^ +NFernsehen:TV-Company +E +^ +NLebensmittel +E +^ +NTelefon +E +^ +NTelefon:Telco1-Tablett +E +^ +NTelefon:Telco2-Handy +E +^ +NTelefon:Telco3 +E +^ +NTelekommunikation +E +^ +NTelekommunikation:Fernsehen +E +^ +NTelekommunikation:Online-Dienste +E +^ +NTelekommunikation:Telefon +E +^ +NTelekommunikation:Telefon:Test1 +E +^ +NGehalt +I +^ +NGehalt:Zulagen +I +^""") + @with_transaction() def test_category_create_by_qif_existing_categories(self): """ create categories by import a qif-file, diff --git a/tryton.cfg b/tryton.cfg index df0875c..914e6da 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,3 +5,4 @@ depends: xml: message.xml qif_import_wiz.xml + qif_export.xml