importer begonnen
This commit is contained in:
parent
dadcfb618f
commit
0aa9df2f1d
1 changed files with 72 additions and 0 deletions
72
importer/import_qif.py
Normal file
72
importer/import_qif.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
# -*- 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 quiffen import Qif
|
||||||
|
|
||||||
|
file_name = 'bargeld.qif'
|
||||||
|
company_name = 'm-ds'
|
||||||
|
|
||||||
|
from proteus import config, Model
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
cfg1 = config.set_trytond(
|
||||||
|
'postgresql://postgres:test1@localhost:5432/tr44/',
|
||||||
|
user='admin',
|
||||||
|
config_file='/home/trytproj/projekt/py3tr60/etc/trytond.conf')
|
||||||
|
|
||||||
|
# check active modules
|
||||||
|
need_modules = ['cashbook', 'party', 'company']
|
||||||
|
|
||||||
|
IrModule = Model.get('ir.module')
|
||||||
|
mod_lst = IrModule.find([
|
||||||
|
('state', '=', 'activated'),
|
||||||
|
('name', 'in', need_modules),
|
||||||
|
])
|
||||||
|
if not len(mod_lst) == len(need_modules):
|
||||||
|
raise ValueError('einige module sind nicht aktiviert!')
|
||||||
|
|
||||||
|
|
||||||
|
def add_category(category, parent, company):
|
||||||
|
""" check or add category
|
||||||
|
"""
|
||||||
|
Category = Model.get('cashbook.category')
|
||||||
|
|
||||||
|
query = [('name', '=', category.name)]
|
||||||
|
if parent is None:
|
||||||
|
query.append(('parent', '=', None))
|
||||||
|
else :
|
||||||
|
query.append(('parent.id', '=', parent.id))
|
||||||
|
|
||||||
|
cat1 = Category.find(query)
|
||||||
|
if len(cat1) == 1:
|
||||||
|
cashbook_category = cat1[0]
|
||||||
|
print('- found:', cashbook_category.rec_name)
|
||||||
|
elif len(cat1) == 0:
|
||||||
|
print('- new-go:', getattr(parent, 'rec_name', '-'), category.name, category.income, category.expense)
|
||||||
|
cashbook_category, = Category.create([{
|
||||||
|
'name': category.name,
|
||||||
|
'cattype': 'in' if category.income == True else 'out',
|
||||||
|
'parent': getattr(parent, 'id', None),
|
||||||
|
}], context={'company': company.id})
|
||||||
|
cashbook_category = Category(cashbook_category)
|
||||||
|
print('- new-ok:', cashbook_category.rec_name)
|
||||||
|
else :
|
||||||
|
raise ValueError('invalid num of category')
|
||||||
|
|
||||||
|
for subcat in category.children:
|
||||||
|
add_category(subcat, cashbook_category, company)
|
||||||
|
|
||||||
|
# end add_category
|
||||||
|
|
||||||
|
|
||||||
|
qif = Qif.parse(file_name, day_first=True)
|
||||||
|
|
||||||
|
Company = Model.get('company.company')
|
||||||
|
company1, = Company.find([('rec_name', '=', company_name)])
|
||||||
|
|
||||||
|
# import categories
|
||||||
|
for catname in qif.categories.keys():
|
||||||
|
category = qif.categories[catname]
|
||||||
|
add_category(category, None, company1)
|
Loading…
Reference in a new issue