diff --git a/evaluation.py b/evaluation.py index e7a78ab..a8b6f2d 100644 --- a/evaluation.py +++ b/evaluation.py @@ -10,7 +10,7 @@ from trytond.pool import Pool from trytond.i18n import gettext from .colors import sel_color as sel_bgcolor from .templates import template_view_graph, template_view_line, \ - cashbook_types, category_types + cashbook_types, category_types, booktype_types sel_chart = [ @@ -65,7 +65,7 @@ class Evaluation(sequence_ordered(), ModelSQL, ModelView): relation_name='cashbook_report.eval_line', origin='evaluation', target='dtype', states={ - 'invisible': Eval('dtype', '') != 'types', + 'invisible': ~Eval('dtype', '').in_(booktype_types), }, depends=['dtype']) currencies = fields.Many2Many(string='Currencies', relation_name='cashbook_report.eval_line', @@ -316,4 +316,3 @@ class Evaluation(sequence_ordered(), ModelSQL, ModelView): super(Evaluation, cls).delete(evaluations) # end Evaluation - diff --git a/investment.py b/investment.py index 2bfb384..3b339be 100644 --- a/investment.py +++ b/investment.py @@ -23,6 +23,9 @@ class InvestmentEvaluation(metaclass=PoolMeta): ('category_gldiff', gettext('cashbook_report.msg_dtype_category_gldiff')), ('category_glvalue', gettext('cashbook_report.msg_dtype_category_glvalue')), ('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 @@ -32,19 +35,36 @@ class InvestmentEvaluation(metaclass=PoolMeta): class InvestmentLine(metaclass=PoolMeta): __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): + """ 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 converted to currency of evaluation """ Book = Pool().get('cashbook.book') - if self.category is None: - return None + query2 = [('state', '=', 'open')] + query2.extend(query) + books = Book.search(query2) - books = Book.search([ - ('state', '=', 'open'), - ('categories.id', '=', self.category.id), - ]) value = Decimal('0.0') amount = Decimal('0.0') @@ -60,19 +80,36 @@ class InvestmentLine(metaclass=PoolMeta): ) 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): + """ 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 converted to currency of evaluation """ Book = Pool().get('cashbook.book') - if self.category is None: - return None + query2 = [('state', '=', 'open')] + query2.extend(query) + books = Book.search(query2) - books = Book.search([ - ('state', '=', 'open'), - ('categories.id', '=', self.category.id), - ]) result = Decimal('0.0') if len(books) > 0: for book in books: @@ -86,19 +123,36 @@ class InvestmentLine(metaclass=PoolMeta): books[0].company.currency, 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): + """ 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 converted to currency of evaluation """ Book = Pool().get('cashbook.book') - if self.category is None: - return None + query2 = [('state', '=', 'open')] + query2.extend(query) + books = Book.search(query2) - books = Book.search([ - ('state', '=', 'open'), - ('categories.id', '=', self.category.id), - ]) result = Decimal('0.0') if len(books) > 0: result = sum([x.current_value_ref - x.balance_ref for x in books diff --git a/line.py b/line.py index eb9a517..78f342c 100644 --- a/line.py +++ b/line.py @@ -11,7 +11,7 @@ from trytond.transaction import Transaction from trytond.i18n import gettext from trytond.exceptions import UserError 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): @@ -29,7 +29,7 @@ class EvaluationLine(ModelSQL, ModelView): dtype = fields.Many2One(string='Type', select=True, ondelete='CASCADE', model_name='cashbook.type', states={ - 'required': Eval('eval_dtype', '') == 'types', + 'required': Eval('eval_dtype', '').in_(booktype_types), }, depends=['eval_dtype']) currency = fields.Many2One(string='Currency', select=True, ondelete='CASCADE', model_name='currency.currency', @@ -96,7 +96,7 @@ class EvaluationLine(ModelSQL, ModelView): @fields.depends('evaluation', '_parent_evaluation.dtype') def on_change_with_eval_dtype(self, name=None): - """ get dtape from parent + """ get dtype from parent """ if self.evaluation: return self.evaluation.dtype @@ -128,9 +128,10 @@ class EvaluationLine(ModelSQL, ModelView): # otherwise use rec_name of linked record 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:'category' for x in category_types}) + dtype_sel.update({x:'dtype' for x in booktype_types}) return getattr( getattr(self, dtype_sel[self.eval_dtype], None), @@ -160,7 +161,7 @@ class EvaluationLine(ModelSQL, ModelView): 'cashbook_report.msg_invalid_dtype', 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): raise UserError(gettext( 'cashbook_report.msg_invalid_dtype', diff --git a/locale/de.po b/locale/de.po index ba30cac..1a4cfa0 100644 --- a/locale/de.po +++ b/locale/de.po @@ -27,8 +27,20 @@ msgid "Cashbooks [Current Value]" msgstr "Kassenbücher [aktueller Wert]" msgctxt "model:ir.message,text:msg_dtype_type" -msgid "Types of Cashbooks" -msgstr "Typen von Kassenbüchern" +msgid "Types of Cashbooks [Amount]" +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" msgid "Currencies" diff --git a/locale/en.po b/locale/en.po index cd993f7..3f49cf3 100644 --- a/locale/en.po +++ b/locale/en.po @@ -23,8 +23,20 @@ msgid "Cashbooks [Current Value]" msgstr "Cashbooks [Current Value]" msgctxt "model:ir.message,text:msg_dtype_type" -msgid "Types of Cashbooks" -msgstr "Types of Cashbooks" +msgid "Types of Cashbooks [Amount]" +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" msgid "Currencies" diff --git a/message.xml b/message.xml index 82d0674..fb578d8 100644 --- a/message.xml +++ b/message.xml @@ -21,7 +21,16 @@ full copyright notices and license terms. --> Cashbooks [Current Value] - Types of Cashbooks + Types of Cashbooks [Amount] + + + Types of Cashbooks [Amount of Profit/Loss] + + + ypes of Cashbooks [Current Value] + + + Types of Cashbooks [Percent of Profit/Loss] Currencies diff --git a/templates.py b/templates.py index 9c9e9af..753e2ef 100644 --- a/templates.py +++ b/templates.py @@ -5,6 +5,7 @@ cashbook_types = ['cashbooks', 'cashbooks_gldiff', 'cashbooks_glperc', 'cashbooks_glvalue'] category_types = ['categories', 'category_gldiff', 'category_glvalue', 'category_glperc'] +booktype_types = ['types', 'types_gldiff', 'types_glvalue', 'types_glperc'] template_view_line = ''