kategorie: domain-views, importer ergänzt

This commit is contained in:
Frederik Jaeckel 2022-08-27 09:32:17 +02:00
parent d383b8f9c1
commit 532d9cc7c8
3 changed files with 106 additions and 9 deletions

View file

@ -3,13 +3,15 @@
# 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'
file_category_income = 'category_income.qif'
file_category_expense = 'category_expense.qif'
company_name = 'm-ds'
from quiffen import Qif
from proteus import config, Model
from datetime import date
import json
cfg1 = config.set_trytond(
'postgresql://postgres:test1@localhost:5432/tr44/',
@ -28,12 +30,16 @@ if not len(mod_lst) == len(need_modules):
raise ValueError('einige module sind nicht aktiviert!')
def add_category(category, parent, company):
def add_category(category, parent, company, cattype):
""" check or add category
"""
Category = Model.get('cashbook.category')
query = [('name', '=', category.name)]
query = [
('name', '=', category.name),
('cattype', '=', cattype),
]
if parent is None:
query.append(('parent', '=', None))
else :
@ -47,7 +53,7 @@ def add_category(category, parent, company):
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',
'cattype': cattype,
'parent': getattr(parent, 'id', None),
}], context={'company': company.id})
cashbook_category = Category(cashbook_category)
@ -56,17 +62,43 @@ def add_category(category, parent, company):
raise ValueError('invalid num of category')
for subcat in category.children:
add_category(subcat, cashbook_category, company)
add_category(subcat, cashbook_category, company, cattype)
# end add_category
qif = Qif.parse(file_name, day_first=True)
def get_category_tree(categories):
""" convert categories in dict-tree
"""
result = []
for category in categories:
cat1 = {
'name': category.name,
'type': 'in' if category.income == True else 'out' if category.expense == True else 'ups',
}
cat1['childs'] = get_category_tree(category.children)
result.append(cat1)
return result
# end get_category_tree
Company = Model.get('company.company')
company1, = Company.find([('rec_name', '=', company_name)])
# import categories
# income-category
qif = Qif.parse(file_category_income, day_first=True)
cat_tree = []
for catname in qif.categories.keys():
category = qif.categories[catname]
add_category(category, None, company1)
#cat_tree.extend(get_category_tree([category]))
add_category(category, None, company1, 'in')
# expense-category
qif = Qif.parse(file_category_expense, day_first=True)
cat_tree = []
for catname in qif.categories.keys():
category = qif.categories[catname]
#cat_tree.extend(get_category_tree([category]))
add_category(category, None, company1, 'out')