add profit/loss-values for selection of cashbooks by btype
This commit is contained in:
parent
d01bd0dc0a
commit
131b9f0c8d
7 changed files with 119 additions and 31 deletions
|
@ -10,7 +10,7 @@ from trytond.pool import Pool
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from .colors import sel_color as sel_bgcolor
|
from .colors import sel_color as sel_bgcolor
|
||||||
from .templates import template_view_graph, template_view_line, \
|
from .templates import template_view_graph, template_view_line, \
|
||||||
cashbook_types, category_types
|
cashbook_types, category_types, booktype_types
|
||||||
|
|
||||||
|
|
||||||
sel_chart = [
|
sel_chart = [
|
||||||
|
@ -65,7 +65,7 @@ class Evaluation(sequence_ordered(), ModelSQL, ModelView):
|
||||||
relation_name='cashbook_report.eval_line',
|
relation_name='cashbook_report.eval_line',
|
||||||
origin='evaluation', target='dtype',
|
origin='evaluation', target='dtype',
|
||||||
states={
|
states={
|
||||||
'invisible': Eval('dtype', '') != 'types',
|
'invisible': ~Eval('dtype', '').in_(booktype_types),
|
||||||
}, depends=['dtype'])
|
}, depends=['dtype'])
|
||||||
currencies = fields.Many2Many(string='Currencies',
|
currencies = fields.Many2Many(string='Currencies',
|
||||||
relation_name='cashbook_report.eval_line',
|
relation_name='cashbook_report.eval_line',
|
||||||
|
@ -316,4 +316,3 @@ class Evaluation(sequence_ordered(), ModelSQL, ModelView):
|
||||||
super(Evaluation, cls).delete(evaluations)
|
super(Evaluation, cls).delete(evaluations)
|
||||||
|
|
||||||
# end Evaluation
|
# end Evaluation
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ class InvestmentEvaluation(metaclass=PoolMeta):
|
||||||
('category_gldiff', gettext('cashbook_report.msg_dtype_category_gldiff')),
|
('category_gldiff', gettext('cashbook_report.msg_dtype_category_gldiff')),
|
||||||
('category_glvalue', gettext('cashbook_report.msg_dtype_category_glvalue')),
|
('category_glvalue', gettext('cashbook_report.msg_dtype_category_glvalue')),
|
||||||
('category_glperc', gettext('cashbook_report.msg_dtype_category_glperc')),
|
('category_glperc', gettext('cashbook_report.msg_dtype_category_glperc')),
|
||||||
|
('types_gldiff', gettext('cashbook_report.msg_dtype_types_gldiff')),
|
||||||
|
('types_glvalue', gettext('cashbook_report.msg_dtype_types_glvalue')),
|
||||||
|
('types_glperc', gettext('cashbook_report.msg_dtype_types_glperc')),
|
||||||
])
|
])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -32,19 +35,36 @@ class InvestmentEvaluation(metaclass=PoolMeta):
|
||||||
class InvestmentLine(metaclass=PoolMeta):
|
class InvestmentLine(metaclass=PoolMeta):
|
||||||
__name__ = 'cashbook_report.eval_line'
|
__name__ = 'cashbook_report.eval_line'
|
||||||
|
|
||||||
|
def get_value_types_glperc(self):
|
||||||
|
""" get percent of profit/loss by type
|
||||||
|
"""
|
||||||
|
if self.dtype is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.get_percent_by_query([
|
||||||
|
('btype.id', '=', self.dtype.id),
|
||||||
|
])
|
||||||
|
|
||||||
def get_value_category_glperc(self):
|
def get_value_category_glperc(self):
|
||||||
|
""" get percent of profit/loss by category
|
||||||
|
"""
|
||||||
|
if self.category is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.get_percent_by_query([
|
||||||
|
('categories.id', '=', self.category.id),
|
||||||
|
])
|
||||||
|
|
||||||
|
def get_percent_by_query(self, query):
|
||||||
""" get percentual difference of bookings in categories
|
""" get percentual difference of bookings in categories
|
||||||
converted to currency of evaluation
|
converted to currency of evaluation
|
||||||
"""
|
"""
|
||||||
Book = Pool().get('cashbook.book')
|
Book = Pool().get('cashbook.book')
|
||||||
|
|
||||||
if self.category is None:
|
query2 = [('state', '=', 'open')]
|
||||||
return None
|
query2.extend(query)
|
||||||
|
books = Book.search(query2)
|
||||||
|
|
||||||
books = Book.search([
|
|
||||||
('state', '=', 'open'),
|
|
||||||
('categories.id', '=', self.category.id),
|
|
||||||
])
|
|
||||||
value = Decimal('0.0')
|
value = Decimal('0.0')
|
||||||
amount = Decimal('0.0')
|
amount = Decimal('0.0')
|
||||||
|
|
||||||
|
@ -60,19 +80,36 @@ class InvestmentLine(metaclass=PoolMeta):
|
||||||
)
|
)
|
||||||
return Decimal('0.0')
|
return Decimal('0.0')
|
||||||
|
|
||||||
|
def get_value_types_glvalue(self):
|
||||||
|
""" get current value by type
|
||||||
|
"""
|
||||||
|
if self.dtype is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.get_currentvalue_by_query([
|
||||||
|
('btype.id', '=', self.dtype.id),
|
||||||
|
])
|
||||||
|
|
||||||
def get_value_category_glvalue(self):
|
def get_value_category_glvalue(self):
|
||||||
|
""" get current value by category
|
||||||
|
"""
|
||||||
|
if self.category is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.get_currentvalue_by_query([
|
||||||
|
('categories.id', '=', self.category.id),
|
||||||
|
])
|
||||||
|
|
||||||
|
def get_currentvalue_by_query(self, query):
|
||||||
""" get current value of bookings in categories
|
""" get current value of bookings in categories
|
||||||
converted to currency of evaluation
|
converted to currency of evaluation
|
||||||
"""
|
"""
|
||||||
Book = Pool().get('cashbook.book')
|
Book = Pool().get('cashbook.book')
|
||||||
|
|
||||||
if self.category is None:
|
query2 = [('state', '=', 'open')]
|
||||||
return None
|
query2.extend(query)
|
||||||
|
books = Book.search(query2)
|
||||||
|
|
||||||
books = Book.search([
|
|
||||||
('state', '=', 'open'),
|
|
||||||
('categories.id', '=', self.category.id),
|
|
||||||
])
|
|
||||||
result = Decimal('0.0')
|
result = Decimal('0.0')
|
||||||
if len(books) > 0:
|
if len(books) > 0:
|
||||||
for book in books:
|
for book in books:
|
||||||
|
@ -86,19 +123,36 @@ class InvestmentLine(metaclass=PoolMeta):
|
||||||
books[0].company.currency, result)
|
books[0].company.currency, result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_value_types_gldiff(self):
|
||||||
|
""" get difference amount by type
|
||||||
|
"""
|
||||||
|
if self.dtype is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.get_difference_by_query([
|
||||||
|
('btype.id', '=', self.dtype.id),
|
||||||
|
])
|
||||||
|
|
||||||
def get_value_category_gldiff(self):
|
def get_value_category_gldiff(self):
|
||||||
|
""" get difference amount by category
|
||||||
|
"""
|
||||||
|
if self.category is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.get_difference_by_query([
|
||||||
|
('categories.id', '=', self.category.id),
|
||||||
|
])
|
||||||
|
|
||||||
|
def get_difference_by_query(self, query):
|
||||||
""" get difference amount of bookings in categories
|
""" get difference amount of bookings in categories
|
||||||
converted to currency of evaluation
|
converted to currency of evaluation
|
||||||
"""
|
"""
|
||||||
Book = Pool().get('cashbook.book')
|
Book = Pool().get('cashbook.book')
|
||||||
|
|
||||||
if self.category is None:
|
query2 = [('state', '=', 'open')]
|
||||||
return None
|
query2.extend(query)
|
||||||
|
books = Book.search(query2)
|
||||||
|
|
||||||
books = Book.search([
|
|
||||||
('state', '=', 'open'),
|
|
||||||
('categories.id', '=', self.category.id),
|
|
||||||
])
|
|
||||||
result = Decimal('0.0')
|
result = Decimal('0.0')
|
||||||
if len(books) > 0:
|
if len(books) > 0:
|
||||||
result = sum([x.current_value_ref - x.balance_ref for x in books
|
result = sum([x.current_value_ref - x.balance_ref for x in books
|
||||||
|
|
11
line.py
11
line.py
|
@ -11,7 +11,7 @@ from trytond.transaction import Transaction
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from .templates import cashbook_types, category_types
|
from .templates import cashbook_types, category_types, booktype_types
|
||||||
|
|
||||||
|
|
||||||
class EvaluationLine(ModelSQL, ModelView):
|
class EvaluationLine(ModelSQL, ModelView):
|
||||||
|
@ -29,7 +29,7 @@ class EvaluationLine(ModelSQL, ModelView):
|
||||||
dtype = fields.Many2One(string='Type', select=True, ondelete='CASCADE',
|
dtype = fields.Many2One(string='Type', select=True, ondelete='CASCADE',
|
||||||
model_name='cashbook.type',
|
model_name='cashbook.type',
|
||||||
states={
|
states={
|
||||||
'required': Eval('eval_dtype', '') == 'types',
|
'required': Eval('eval_dtype', '').in_(booktype_types),
|
||||||
}, depends=['eval_dtype'])
|
}, depends=['eval_dtype'])
|
||||||
currency = fields.Many2One(string='Currency', select=True, ondelete='CASCADE',
|
currency = fields.Many2One(string='Currency', select=True, ondelete='CASCADE',
|
||||||
model_name='currency.currency',
|
model_name='currency.currency',
|
||||||
|
@ -96,7 +96,7 @@ class EvaluationLine(ModelSQL, ModelView):
|
||||||
|
|
||||||
@fields.depends('evaluation', '_parent_evaluation.dtype')
|
@fields.depends('evaluation', '_parent_evaluation.dtype')
|
||||||
def on_change_with_eval_dtype(self, name=None):
|
def on_change_with_eval_dtype(self, name=None):
|
||||||
""" get dtape from parent
|
""" get dtype from parent
|
||||||
"""
|
"""
|
||||||
if self.evaluation:
|
if self.evaluation:
|
||||||
return self.evaluation.dtype
|
return self.evaluation.dtype
|
||||||
|
@ -128,9 +128,10 @@ class EvaluationLine(ModelSQL, ModelView):
|
||||||
|
|
||||||
# otherwise use rec_name of linked record
|
# otherwise use rec_name of linked record
|
||||||
if self.eval_dtype:
|
if self.eval_dtype:
|
||||||
dtype_sel = {'types': 'dtype', 'currencies': 'currency'}
|
dtype_sel = {'currencies': 'currency'}
|
||||||
dtype_sel.update({x:'cashbook' for x in cashbook_types})
|
dtype_sel.update({x:'cashbook' for x in cashbook_types})
|
||||||
dtype_sel.update({x:'category' for x in category_types})
|
dtype_sel.update({x:'category' for x in category_types})
|
||||||
|
dtype_sel.update({x:'dtype' for x in booktype_types})
|
||||||
|
|
||||||
return getattr(
|
return getattr(
|
||||||
getattr(self, dtype_sel[self.eval_dtype], None),
|
getattr(self, dtype_sel[self.eval_dtype], None),
|
||||||
|
@ -160,7 +161,7 @@ class EvaluationLine(ModelSQL, ModelView):
|
||||||
'cashbook_report.msg_invalid_dtype',
|
'cashbook_report.msg_invalid_dtype',
|
||||||
typename = gettext('cashbook_report.msg_dtype_cashbook'),
|
typename = gettext('cashbook_report.msg_dtype_cashbook'),
|
||||||
))
|
))
|
||||||
if (record.evaluation.dtype != 'types') and \
|
if (record.evaluation.dtype not in booktype_types) and \
|
||||||
(record.dtype is not None):
|
(record.dtype is not None):
|
||||||
raise UserError(gettext(
|
raise UserError(gettext(
|
||||||
'cashbook_report.msg_invalid_dtype',
|
'cashbook_report.msg_invalid_dtype',
|
||||||
|
|
16
locale/de.po
16
locale/de.po
|
@ -27,8 +27,20 @@ msgid "Cashbooks [Current Value]"
|
||||||
msgstr "Kassenbücher [aktueller Wert]"
|
msgstr "Kassenbücher [aktueller Wert]"
|
||||||
|
|
||||||
msgctxt "model:ir.message,text:msg_dtype_type"
|
msgctxt "model:ir.message,text:msg_dtype_type"
|
||||||
msgid "Types of Cashbooks"
|
msgid "Types of Cashbooks [Amount]"
|
||||||
msgstr "Typen von Kassenbüchern"
|
msgstr "Typen von Kassenbüchern [Betrag]"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_dtype_types_gldiff"
|
||||||
|
msgid "Types of Cashbooks [Amount of Profit/Loss]"
|
||||||
|
msgstr "Typen von Kassenbüchern [Betrag Gewinn/Verlust]"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_dtype_types_glvalue"
|
||||||
|
msgid "Types of Cashbooks [Current Value]"
|
||||||
|
msgstr "Typen von Kassenbüchern [aktueller Wert]"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_dtype_types_glperc"
|
||||||
|
msgid "Types of Cashbooks [Percent of Profit/Loss]"
|
||||||
|
msgstr "Typen von Kassenbüchern [Prozent Gewinn/Verlust]"
|
||||||
|
|
||||||
msgctxt "model:ir.message,text:msg_dtype_currency"
|
msgctxt "model:ir.message,text:msg_dtype_currency"
|
||||||
msgid "Currencies"
|
msgid "Currencies"
|
||||||
|
|
16
locale/en.po
16
locale/en.po
|
@ -23,8 +23,20 @@ msgid "Cashbooks [Current Value]"
|
||||||
msgstr "Cashbooks [Current Value]"
|
msgstr "Cashbooks [Current Value]"
|
||||||
|
|
||||||
msgctxt "model:ir.message,text:msg_dtype_type"
|
msgctxt "model:ir.message,text:msg_dtype_type"
|
||||||
msgid "Types of Cashbooks"
|
msgid "Types of Cashbooks [Amount]"
|
||||||
msgstr "Types of Cashbooks"
|
msgstr "Types of Cashbooks [Amount]"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_dtype_types_gldiff"
|
||||||
|
msgid "Types of Cashbooks [Amount of Profit/Loss]"
|
||||||
|
msgstr "Types of Cashbooks [Amount of Profit/Loss]"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_dtype_types_glvalue"
|
||||||
|
msgid "Types of Cashbooks [Current Value]"
|
||||||
|
msgstr "Types of Cashbooks [Current Value]"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_dtype_types_glperc"
|
||||||
|
msgid "Types of Cashbooks [Percent of Profit/Loss]"
|
||||||
|
msgstr "Types of Cashbooks [Percent of Profit/Loss]"
|
||||||
|
|
||||||
msgctxt "model:ir.message,text:msg_dtype_currency"
|
msgctxt "model:ir.message,text:msg_dtype_currency"
|
||||||
msgid "Currencies"
|
msgid "Currencies"
|
||||||
|
|
11
message.xml
11
message.xml
|
@ -21,7 +21,16 @@ full copyright notices and license terms. -->
|
||||||
<field name="text">Cashbooks [Current Value]</field>
|
<field name="text">Cashbooks [Current Value]</field>
|
||||||
</record>
|
</record>
|
||||||
<record model="ir.message" id="msg_dtype_type">
|
<record model="ir.message" id="msg_dtype_type">
|
||||||
<field name="text">Types of Cashbooks</field>
|
<field name="text">Types of Cashbooks [Amount]</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.message" id="msg_dtype_types_gldiff">
|
||||||
|
<field name="text">Types of Cashbooks [Amount of Profit/Loss]</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.message" id="msg_dtype_types_glvalue">
|
||||||
|
<field name="text">ypes of Cashbooks [Current Value]</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.message" id="msg_dtype_types_glperc">
|
||||||
|
<field name="text">Types of Cashbooks [Percent of Profit/Loss]</field>
|
||||||
</record>
|
</record>
|
||||||
<record model="ir.message" id="msg_dtype_currency">
|
<record model="ir.message" id="msg_dtype_currency">
|
||||||
<field name="text">Currencies</field>
|
<field name="text">Currencies</field>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
cashbook_types = ['cashbooks', 'cashbooks_gldiff', 'cashbooks_glperc', 'cashbooks_glvalue']
|
cashbook_types = ['cashbooks', 'cashbooks_gldiff', 'cashbooks_glperc', 'cashbooks_glvalue']
|
||||||
category_types = ['categories', 'category_gldiff', 'category_glvalue', 'category_glperc']
|
category_types = ['categories', 'category_gldiff', 'category_glvalue', 'category_glperc']
|
||||||
|
booktype_types = ['types', 'types_gldiff', 'types_glvalue', 'types_glperc']
|
||||||
|
|
||||||
template_view_line = '<field name="balance" fill="%(fill)s" empty="0" string="%(string)s"/>'
|
template_view_line = '<field name="balance" fill="%(fill)s" empty="0" string="%(string)s"/>'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue