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

@ -42,6 +42,26 @@ full copyright notices and license terms. -->
<field name="act_window" ref="act_category_list"/>
</record>
<!-- domain view - list -->
<record model="ir.action.act_window.domain" id="act_category_list_domain_in">
<field name="name">Revenue</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('cattype', '=', 'in')]" pyson="1"/>
<field name="act_window" ref="act_category_list"/>
</record>
<record model="ir.action.act_window.domain" id="act_category_list_domain_out">
<field name="name">Expense</field>
<field name="sequence" eval="20"/>
<field name="domain" eval="[('cattype', '=', 'out')]" pyson="1"/>
<field name="act_window" ref="act_category_list"/>
</record>
<record model="ir.action.act_window.domain" id="act_category_list_domain_all">
<field name="name">All</field>
<field name="sequence" eval="999"/>
<field name="domain"/>
<field name="act_window" ref="act_category_list"/>
</record>
<!-- action view - tree -->
<record model="ir.action.act_window" id="act_category_tree">
<field name="name">Category</field>
@ -59,6 +79,27 @@ full copyright notices and license terms. -->
<field name="act_window" ref="act_category_tree"/>
</record>
<!-- domain view - tree -->
<record model="ir.action.act_window.domain" id="act_category_tree_domain_in">
<field name="name">Revenue</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('cattype', '=', 'in')]" pyson="1"/>
<field name="act_window" ref="act_category_tree"/>
</record>
<record model="ir.action.act_window.domain" id="act_category_tree_domain_out">
<field name="name">Expense</field>
<field name="sequence" eval="20"/>
<field name="domain" eval="[('cattype', '=', 'out')]" pyson="1"/>
<field name="act_window" ref="act_category_tree"/>
</record>
<record model="ir.action.act_window.domain" id="act_category_tree_domain_all">
<field name="name">All</field>
<field name="sequence" eval="999"/>
<field name="domain"/>
<field name="act_window" ref="act_category_tree"/>
</record>
<!-- permission -->
<!-- anon: deny all -->
<record model="ir.model.access" id="access_category-anon">

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')

View file

@ -318,6 +318,30 @@ msgctxt "model:ir.action.act_window.domain,name:act_line_domain_all"
msgid "All"
msgstr "Alle"
msgctxt "model:ir.action.act_window.domain,name:act_category_tree_domain_in"
msgid "Revenue"
msgstr "Einnahmen"
msgctxt "model:ir.action.act_window.domain,name:act_category_tree_domain_out"
msgid "Expense"
msgstr "Ausgaben"
msgctxt "model:ir.action.act_window.domain,name:act_category_tree_domain_all"
msgid "All"
msgstr "Alle"
msgctxt "model:ir.action.act_window.domain,name:act_category_list_domain_in"
msgid "Revenue"
msgstr "Einnahmen"
msgctxt "model:ir.action.act_window.domain,name:act_category_list_domain_out"
msgid "Expense"
msgstr "Ausgaben"
msgctxt "model:ir.action.act_window.domain,name:act_category_list_domain_all"
msgid "All"
msgstr "Alle"
###################
# ir.model.button #