kategorie, verknüpfung zu kassenbuch, forms

This commit is contained in:
Frederik Jaeckel 2022-11-07 23:11:41 +01:00
parent 5bb6421692
commit c69b9c86d8
16 changed files with 561 additions and 0 deletions

View file

@ -2,3 +2,5 @@ syntax: glob
build/* build/*
mds_cashbook_bookcategory.egg-info/* mds_cashbook_bookcategory.egg-info/*
dist/* dist/*
__pycache__/*
locale/convert_de2en.py

View file

@ -4,7 +4,12 @@
# full copyright notices and license terms. # full copyright notices and license terms.
from trytond.pool import Pool from trytond.pool import Pool
from .category import Category
from .book import CategoryCashbookRel, Cashbook
def register(): def register():
Pool.register( Pool.register(
Category,
Cashbook,
CategoryCashbookRel,
module='cashbook_bookcategory', type_='model') module='cashbook_bookcategory', type_='model')

29
book.py Normal file
View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelSQL, fields
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
class Cashbook(metaclass=PoolMeta):
__name__ = 'cashbook.book'
categories = fields.Many2Many(string='Categories',
relation_name='cashbook.bookcategory-rel',
origin='cashbook', target='category')
# end Cashbook
class CategoryCashbookRel(ModelSQL):
'Category Cashbook Relation'
__name__ = 'cashbook.bookcategory-rel'
category = fields.Many2One(string='Category', required=True, select=True,
model_name='cashbook.bookcategory', ondelete='CASCADE')
cashbook = fields.Many2One(string='Cashbook', required=True, select=True,
model_name='cashbook.book', ondelete='CASCADE')
# end CategoryCashbookRel

15
book.xml Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!-- 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. -->
<tryton>
<data>
<record model="ir.ui.view" id="book_view_form">
<field name="model">cashbook.book</field>
<field name="inherit" ref="cashbook.book_view_form"/>
<field name="name">book_form</field>
</record>
</data>
</tryton>

50
category.py Normal file
View file

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields, tree
from trytond.modules.cashbook.model import order_name_hierarchical
from trytond.transaction import Transaction
class Category(tree(separator=' / '), ModelSQL, ModelView):
"Cashbook Category"
__name__ = "cashbook.bookcategory"
company = fields.Many2One(string='Company', model_name='company.company',
required=True, ondelete="RESTRICT")
name = fields.Char(string='Name', required=True, translate=True)
parent = fields.Many2One(string='Parent', select=True,
model_name='cashbook.bookcategory', ondelete='CASCADE',
left='left', right='right')
childs = fields.One2Many(string='Children', field='parent',
model_name='cashbook.bookcategory')
left = fields.Integer(string='Left', required=True, select=True)
right = fields.Integer(string='Right', required=True, select=True)
@classmethod
def __setup__(cls):
super(Category, cls).__setup__()
cls._order.insert(0, ('rec_name', 'ASC'))
@staticmethod
def default_left():
return 0
@staticmethod
def default_right():
return 0
@staticmethod
def default_company():
return Transaction().context.get('company') or None
@staticmethod
def order_rec_name(tables):
""" order by pos
a recursive sorting
"""
return order_name_hierarchical('cashbook.bookcategory', tables)
# ende Category

143
category.xml Normal file
View file

@ -0,0 +1,143 @@
<?xml version="1.0"?>
<tryton>
<data>
<record model="ir.ui.view" id="category_view_list">
<field name="model">cashbook.bookcategory</field>
<field name="type">tree</field>
<field name="priority" eval="10"/>
<field name="name">category_list</field>
</record>
<record model="ir.ui.view" id="category_view_tree">
<field name="model">cashbook.bookcategory</field>
<field name="type">tree</field>
<field name="priority" eval="20"/>
<field name="field_childs">childs</field>
<field name="name">category_tree</field>
</record>
<record model="ir.ui.view" id="category_view_form">
<field name="model">cashbook.bookcategory</field>
<field name="type">form</field>
<field name="name">category_form</field>
</record>
<!-- tree view -->
<record model="ir.action.act_window" id="tree_category_view">
<field name="name">Cashbook Category</field>
<field name="res_model">cashbook.bookcategory</field>
<field name="domain" eval="[('parent', '=', None)]" pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="tree_category_view-1">
<field name="sequence" eval="10"/>
<field name="view" ref="category_view_tree"/>
<field name="act_window" ref="tree_category_view"/>
</record>
<record model="ir.action.act_window.view" id="tree_category_view-2">
<field name="sequence" eval="20"/>
<field name="view" ref="category_view_form"/>
<field name="act_window" ref="tree_category_view"/>
</record>
<!-- list view -->
<record model="ir.action.act_window" id="list_category_view">
<field name="name">Cashbook Category (List)</field>
<field name="res_model">cashbook.bookcategory</field>
</record>
<record model="ir.action.act_window.view" id="list_category_view-1">
<field name="sequence" eval="10"/>
<field name="view" ref="category_view_list"/>
<field name="act_window" ref="list_category_view"/>
</record>
<record model="ir.action.act_window.view" id="list_category_view-2">
<field name="sequence" eval="20"/>
<field name="view" ref="category_view_form"/>
<field name="act_window" ref="list_category_view"/>
</record>
<!-- permissions -->
<record model="ir.model.access" id="access_category-anon">
<field name="model" search="[('model', '=', 'cashbook.bookcategory')]"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<!-- group_cashbook_admin: read/write -->
<record model="ir.model.access" id="access_category-group_cashbook_admin">
<field name="model" search="[('model', '=', 'cashbook.bookcategory')]"/>
<field name="group" ref="cashbook.group_cashbook_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<!-- cashbook: read/write -->
<record model="ir.model.access" id="access_category-group_cashbook">
<field name="model" search="[('model', '=', 'cashbook.bookcategory')]"/>
<field name="group" ref="cashbook.group_cashbook"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<!-- permission by rule - admin -->
<record model="ir.rule.group" id="rg_category_write_adm">
<field name="model" search="[('model', '=', 'cashbook.bookcategory')]"/>
<field name="name">Administrators: Category read/write</field>
<field name="global_p" eval="False"/>
<field name="default_p" eval="False"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.rule" id="rg_category_write_adm-1">
<field name="domain" eval="[]" pyson="1"/>
<field name="rule_group" ref="rg_category_write_adm"/>
</record>
<record model="ir.rule.group-res.group" id="rg_category_write_adm-group_cashbook_admin">
<field name="rule_group" ref="rg_category_write_adm"/>
<field name="group" ref="cashbook.group_cashbook_admin"/>
</record>
<!-- permission by rule - read/write: owner -->
<record model="ir.rule.group" id="rg_category_rw_owner">
<field name="model" search="[('model', '=', 'cashbook.bookcategory')]"/>
<field name="name">Owners: Category read/write</field>
<field name="global_p" eval="False"/>
<field name="default_p" eval="False"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.rule" id="rg_category_rw_owner-1">
<field name="domain" eval="[
('create_uid.id', '=', Eval('user', {}).get('id', -1)),
]" pyson="1"/>
<field name="rule_group" ref="rg_category_rw_owner"/>
</record>
<record model="ir.rule.group-res.group"
id="rg_category_rw_owner-group_cashbook">
<field name="rule_group" ref="rg_category_rw_owner"/>
<field name="group" ref="cashbook.group_cashbook"/>
</record>
<!-- company user -->
<record model="ir.rule.group" id="rg_category_companies">
<field name="name">User in companies</field>
<field name="model"
search="[('model', '=', 'cashbook.bookcategory')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="r_category_companies">
<field name="domain"
eval="[('company', 'in', Eval('companies', []))]"
pyson="1"/>
<field name="rule_group" ref="rg_category_companies"/>
</record>
</data>
</tryton>

107
locale/de.po Normal file
View file

@ -0,0 +1,107 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
#################
# ir.rule.group #
#################
msgctxt "model:ir.rule.group,name:rg_category_write_adm"
msgid "Administrators: Category read/write"
msgstr "Administrators: Kategorie schreiben"
msgctxt "model:ir.rule.group,name:rg_category_rw_owner"
msgid "Owners: Category read/write"
msgstr "Eigentümer: Kategorie schreiben"
msgctxt "model:ir.rule.group,name:rg_category_companies"
msgid "User in companies"
msgstr "Benutzer im Unternehmen"
##############
# ir.ui.menu #
##############
msgctxt "model:ir.ui.menu,name:menu_category_tree"
msgid "Cashbook Category"
msgstr "Kassenbuchkategorie"
msgctxt "model:ir.ui.menu,name:menu_category_list"
msgid "Cashbook Category (List)"
msgstr "Kassenbuchkategorie (Liste)"
#############
# ir.action #
#############
msgctxt "model:ir.action,name:tree_category_view"
msgid "Cashbook Category"
msgstr "Kassenbuchkategorie"
msgctxt "model:ir.action,name:list_category_view"
msgid "Cashbook Category (List)"
msgstr "Kassenbuchkategorie (Liste)"
#########################
# cashbook.bookcategory #
#########################
msgctxt "model:cashbook.bookcategory,name:"
msgid "Cashbook Category"
msgstr "Kassenbuchkategorie"
msgctxt "view:cashbook.bookcategory:"
msgid "General Information"
msgstr "Allgemein"
msgctxt "field:cashbook.bookcategory,name:"
msgid "Name"
msgstr "Name"
msgctxt "field:cashbook.bookcategory,company:"
msgid "Company"
msgstr "Unternehmen"
msgctxt "field:cashbook.bookcategory,parent:"
msgid "Parent"
msgstr "Übergeordnet"
msgctxt "field:cashbook.bookcategory,childs:"
msgid "Children"
msgstr "Untergeordnet"
msgctxt "field:cashbook.bookcategory,left:"
msgid "Left"
msgstr "Links"
msgctxt "field:cashbook.bookcategory,right:"
msgid "Right"
msgstr "Rechts"
#################
# cashbook.book #
#################
msgctxt "view:cashbook.book:"
msgid "Categories"
msgstr "Kategorien"
msgctxt "field:cashbook.book,categories:"
msgid "Categories"
msgstr "Kategorien"
#############################
# cashbook.bookcategory-rel #
#############################
msgctxt "model:cashbook.bookcategory-rel,name:"
msgid "Category Cashbook Relation"
msgstr "Kategorie Kassenbuch Verknüpfung"
msgctxt "field:cashbook.bookcategory-rel,category:"
msgid "Category"
msgstr "Kategorie"
msgctxt "field:cashbook.bookcategory-rel,cashbook:"
msgid "Cashbook"
msgstr "Kassenbuch"

80
locale/en.po Normal file
View file

@ -0,0 +1,80 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "model:ir.rule.group,name:rg_category_write_adm"
msgid "Administrators: Category read/write"
msgstr "Administrators: Category read/write"
msgctxt "model:ir.rule.group,name:rg_category_rw_owner"
msgid "Owners: Category read/write"
msgstr "Owners: Category read/write"
msgctxt "model:ir.rule.group,name:rg_category_companies"
msgid "User in companies"
msgstr "User in companies"
msgctxt "model:ir.ui.menu,name:menu_category_tree"
msgid "Cashbook Category"
msgstr "Cashbook Category"
msgctxt "model:ir.ui.menu,name:menu_category_list"
msgid "Cashbook Category (List)"
msgstr "Cashbook Category (List)"
msgctxt "model:ir.action,name:tree_category_view"
msgid "Cashbook Category"
msgstr "Cashbook Category"
msgctxt "model:ir.action,name:list_category_view"
msgid "Cashbook Category (List)"
msgstr "Cashbook Category (List)"
msgctxt "model:cashbook.bookcategory,name:"
msgid "Cashbook Category"
msgstr "Cashbook Category"
msgctxt "view:cashbook.bookcategory:"
msgid "General Information"
msgstr "General Information"
msgctxt "field:cashbook.bookcategory,name:"
msgid "Name"
msgstr "Name"
msgctxt "field:cashbook.bookcategory,company:"
msgid "Company"
msgstr "Company"
msgctxt "field:cashbook.bookcategory,parent:"
msgid "Parent"
msgstr "Parent"
msgctxt "field:cashbook.bookcategory,childs:"
msgid "Children"
msgstr "Children"
msgctxt "field:cashbook.bookcategory,left:"
msgid "Left"
msgstr "Left"
msgctxt "field:cashbook.bookcategory,right:"
msgid "Right"
msgstr "Right"
msgctxt "view:cashbook.book:"
msgid "Categories"
msgstr "Categories"
msgctxt "field:cashbook.book,categories:"
msgid "Categories"
msgstr "Categories"
msgctxt "model:cashbook.bookcategory-rel,name:"
msgid "Category Cashbook Relation"
msgstr "Category Cashbook Relation"
msgctxt "field:cashbook.bookcategory-rel,category:"
msgid "Category"
msgstr "Category"

39
menu.xml Normal file
View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!-- 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. -->
<tryton>
<data>
<!-- menu: /Cashbook/Cashbook/Category -->
<menuitem id="menu_category_tree" action="tree_category_view"
icon="tryton-tree"
parent="cashbook.menu_booktree" sequence="20"/>
<record model="ir.ui.menu-res.group"
id="menu_category_tree-group_cashbook">
<field name="menu" ref="menu_category_tree"/>
<field name="group" ref="cashbook.group_cashbook"/>
</record>
<record model="ir.ui.menu-res.group"
id="menu_category_tree-group_cashbook_admin">
<field name="menu" ref="menu_category_tree"/>
<field name="group" ref="cashbook.group_cashbook_admin"/>
</record>
<!-- menu: /Cashbook/Cashbook/Category/Category (List) -->
<menuitem id="menu_category_list" action="list_category_view"
icon="tryton-list"
parent="menu_category_tree" sequence="10"/>
<record model="ir.ui.menu-res.group"
id="menu_category_list-group_cashbook">
<field name="menu" ref="menu_category_list"/>
<field name="group" ref="cashbook.group_cashbook"/>
</record>
<record model="ir.ui.menu-res.group"
id="menu_category_list-group_cashbook_admin">
<field name="menu" ref="menu_category_list"/>
<field name="group" ref="cashbook.group_cashbook_admin"/>
</record>
</data>
</tryton>

24
tests/__init__.py Normal file
View file

@ -0,0 +1,24 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import trytond.tests.test_tryton
import unittest
from trytond.modules.cashbook_bookcategory.tests.test_category import CategoryTestCase
__all__ = ['suite']
class CashbookCategoryTestCase(\
CategoryTestCase,\
):
'Test cashbook module'
module = 'cashbook_bookcategory'
# end CashbookCategoryTestCase
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookCategoryTestCase))
return suite

17
tests/test_category.py Normal file
View file

@ -0,0 +1,17 @@
# -*- 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.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.exceptions import UserError
from trytond.modules.cashbook.tests import CashbookTestCase
class CategoryTestCase(CashbookTestCase):
'Test cashbook category module'
module = 'cashbook_bookcategory'
# end CategoryTestCase

View file

@ -3,3 +3,6 @@ version=6.0.0
depends: depends:
cashbook cashbook
xml: xml:
category.xml
book.xml
menu.xml

13
view/book_form.xml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- 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. -->
<data>
<xpath expr="/form/notebook/page[@id='pggeneral']" position="after">
<page id="pgcategory" string="Categories" col="1">
<field name="categories"/>
</page>
</xpath>
</data>

18
view/category_form.xml Normal file
View file

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!-- 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. -->
<form col="2">
<label name="name"/>
<field name="name"/>
<notebook colspan="2">
<page string="General Information" id="general" col="4">
<label name="parent"/>
<field name="parent"/>
<field name="childs" colspan="4"/>
</page>
</notebook>
<field name="company" invisible="1"/>
</form>

7
view/category_list.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!-- 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. -->
<tree>
<field name="rec_name"/>
</tree>

9
view/category_tree.xml Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- 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. -->
<tree tree_state="1">
<field name="name"/>
<field name="parent" tree_invisible="1"/>
<field name="childs" tree_invisible="1"/>
</tree>