cashbook_dataexchange/book.py

47 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-09-01 12:48:04 +00:00
# -*- 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.pool import Pool, PoolMeta
class Book(metaclass=PoolMeta):
__name__ = 'cashbook.book'
2022-09-05 08:13:20 +00:00
@classmethod
def export_as_qif(cls, book):
""" export all transactions as QIF
"""
pool = Pool()
QifTool = pool.get('cashbook_dataexchange.qiftool')
return QifTool.qif_export_book(book)
2022-09-01 12:48:04 +00:00
@classmethod
def create_from_qif(cls, book, qifdata):
""" add transactions from QIF-File-content
"""
pool = Pool()
QifTool = pool.get('cashbook_dataexchange.qiftool')
Book2 = pool.get('cashbook.book')
qif_content = QifTool.split_by_type(qifdata)
2023-06-06 13:22:57 +00:00
if 'Bank' not in qif_content.keys():
2022-09-01 12:48:04 +00:00
return None
2023-06-06 13:22:57 +00:00
(to_create, msg_list, fail_cnt) = \
QifTool.convert_transactions_to_create(
book,
2023-06-06 13:22:57 +00:00
QifTool.qif_read_transactions(qif_content['Bank']))
if fail_cnt == 0:
2022-09-01 12:48:04 +00:00
Book2.write(*[
[book],
{
'lines': [('create', to_create)],
}])
return [book]
return None
# end Category