From e2025a1711d4e42628b74a47afdfe1265c7eb8a1 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Mon, 29 Aug 2022 11:05:59 +0200 Subject: [PATCH] importiert kategorien --- __init__.py | 3 +- locale/de.po | 40 ++++++++++++++ message.xml | 17 ++++++ qif_import_wiz.py | 92 ++++++++++++++++++++++++++++++++ qif_import_wiz.xml | 5 ++ tryton.cfg | 1 + view/wiz_qifimport_info_form.xml | 13 +++++ 7 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 message.xml create mode 100644 view/wiz_qifimport_info_form.xml diff --git a/__init__.py b/__init__.py index d01f22e..780ef43 100644 --- a/__init__.py +++ b/__init__.py @@ -6,13 +6,14 @@ from trytond.pool import Pool from .category import Category from .qiftool import QifTool -from .qif_import_wiz import ImportQifWizard, ImportQifWizardStart +from .qif_import_wiz import ImportQifWizard, ImportQifWizardStart, ImportQifWizardInfo def register(): Pool.register( QifTool, Category, ImportQifWizardStart, + ImportQifWizardInfo, module='cashbook_dataexchange', type_='model') Pool.register( ImportQifWizard, diff --git a/locale/de.po b/locale/de.po index 2245828..09c0727 100644 --- a/locale/de.po +++ b/locale/de.po @@ -3,6 +3,14 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" +############## +# ir.message # +############## +msgctxt "model:ir.message,text:msg_wiz_categories_found" +msgid "The following categories are now imported:\n%(categories)s" +msgstr "Die folgenden Kategorien werden nun importiert:\n%(categories)s" + + ############# # ir.action # ############# @@ -10,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:msg_wiz_no_categories" +msgid "No categories were found in the file." +msgstr "In der Datei wurden keine Kategorien gefunden." + ##################################### # cashbook_dataexchange.qif_imp_wiz # @@ -26,6 +38,14 @@ msgctxt "wizard_button:cashbook_dataexchange.qif_imp_wiz,start,readf:" msgid "Read File" msgstr "Datei lesen" +msgctxt "wizard_button:cashbook_dataexchange.qif_imp_wiz,showinfo,end:" +msgid "Cancel" +msgstr "Abbruch" + +msgctxt "wizard_button:cashbook_dataexchange.qif_imp_wiz,showinfo,importf:" +msgid "Import Categories" +msgstr "Kategorien importieren" + ########################################### # cashbook_dataexchange.qif_imp_wiz.start # @@ -45,3 +65,23 @@ msgstr "QIF-Datei" msgctxt "help:cashbook_dataexchange.qif_imp_wiz.start,file_:" msgid "Quicken Interchange Format" msgstr "Quicken Interchange Format" + + +########################################## +# cashbook_dataexchange.qif_imp_wiz.info # +########################################## +msgctxt "model:cashbook_dataexchange.qif_imp_wiz.info,name:" +msgid "Import QIF-File" +msgstr "QIF-Datei importieren" + +msgctxt "view:cashbook_dataexchange.qif_imp_wiz.info:" +msgid "Information" +msgstr "Information" + +msgctxt "field:cashbook_dataexchange.qif_imp_wiz.start,company:" +msgid "Company" +msgstr "Unternehmen" + +msgctxt "field:cashbook_dataexchange.qif_imp_wiz.start,info:" +msgid "Information" +msgstr "Information" diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..fe4a54e --- /dev/null +++ b/message.xml @@ -0,0 +1,17 @@ + + + + + + + The following categories are now imported:\n%(categories)s + + + + No categories were found in the file. + + + + diff --git a/qif_import_wiz.py b/qif_import_wiz.py index e2578df..419e746 100644 --- a/qif_import_wiz.py +++ b/qif_import_wiz.py @@ -8,6 +8,7 @@ from trytond.pool import Pool from trytond.model import ModelView, fields from trytond.wizard import Wizard, StateTransition, StateView, Button from trytond.transaction import Transaction +from trytond.i18n import gettext class ImportQifWizardStart(ModelView): @@ -27,6 +28,18 @@ class ImportQifWizardStart(ModelView): # end ImportQifWizardStart +class ImportQifWizardInfo(ModelView): + 'Import QIF-File' + __name__ = 'cashbook_dataexchange.qif_imp_wiz.info' + + company = fields.Many2One(model_name='company.company', + string="Company", required=True, + states={'invisible': True}) + info = fields.Text(string='Information', readonly=True) + +# end ImportQifWizardInfo + + class ImportQifWizard(Wizard): 'Import QIF-File' __name__ = 'cashbook_dataexchange.qif_imp_wiz' @@ -38,6 +51,85 @@ class ImportQifWizard(Wizard): Button(string='Cancel', state='end', icon='tryton-cancel'), Button(string='Read File', state='readf', icon='tryton-forward', default=True), ]) + showinfo = StateView(model_name='cashbook_dataexchange.qif_imp_wiz.info', \ + view='cashbook_dataexchange.qif_imp_wiz_info_form', \ + buttons=[ + Button(string='Cancel', state='end', icon='tryton-cancel'), + Button(string='Import Categories', state='importf', icon='tryton-import', default=True), + ]) + + readf = StateTransition() + importf = StateTransition() + + def default_showinfo(self, fields): + """ show import-info + """ + values = { + 'company': self.start.company.id, + 'info': getattr(self.showinfo, 'info', None), + } + return values + + def transition_readf(self): + """ read file, show number of objects + """ + pool = Pool() + QitTool = pool.get('cashbook_dataexchange.qiftool') + + model = Transaction().context.get('active_model', '') + file_content = None + if isinstance(self.start.file_, bytes): + file_content = self.start.file_.decode('utf8') + + if model == 'cashbook.category': + def get_catlist(catlist, parent_name=None): + """ generate list of categories + """ + names = [] + for name1 in catlist.keys(): + name_lst = [] + if parent_name: + name_lst.append(parent_name) + name_lst.append(name1) + current_name = '/'.join(name_lst) + names.append(current_name) + names.extend(get_catlist(catlist[name1]['childs'], current_name)) + return names + + # read file content, extract categories + qif_content = QitTool.split_by_type(file_content) + if 'Cat' in qif_content.keys(): + categories = QitTool.qif_read_categories(qif_content['Cat']) + self.showinfo.info = gettext( + 'cashbook_dataexchange.msg_wiz_categories_found', + categories = '\n'.join( + [' '] + + ['%s (in)' % x for x in get_catlist(categories['in'], None)]+ + [' '] + + ['%s (out)' % x for x in get_catlist(categories['out'], None)] + ) + ) + else : + self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_categories') + + return 'showinfo' + + def transition_importf(self): + """ read file, show number of objects + """ + pool = Pool() + Category = pool.get('cashbook.category') + + model = Transaction().context.get('active_model', '') + file_content = None + if isinstance(self.start.file_, bytes): + file_content = self.start.file_.decode('utf8') + + if model == 'cashbook.category': + if file_content: + records = Category.create_from_qif(file_content) + + return 'end' # end ImportQifWizard diff --git a/qif_import_wiz.xml b/qif_import_wiz.xml index 022f445..f354c18 100644 --- a/qif_import_wiz.xml +++ b/qif_import_wiz.xml @@ -10,6 +10,11 @@ full copyright notices and license terms. --> form wiz_qifimport_start_form + + cashbook_dataexchange.qif_imp_wiz.info + form + wiz_qifimport_info_form + diff --git a/tryton.cfg b/tryton.cfg index a10f4f1..df0875c 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -3,4 +3,5 @@ version=6.0.1 depends: cashbook xml: + message.xml qif_import_wiz.xml diff --git a/view/wiz_qifimport_info_form.xml b/view/wiz_qifimport_info_form.xml new file mode 100644 index 0000000..caff918 --- /dev/null +++ b/view/wiz_qifimport_info_form.xml @@ -0,0 +1,13 @@ + + +
+