From 922c650a7193d8d0ed7ce2e35dc1202938187cf6 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Wed, 7 Jun 2023 21:58:32 +0200 Subject: [PATCH 01/13] Version 6.8.24 --- tryton.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/tryton.cfg b/tryton.cfg index 4ba63f6..4650f07 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -21,3 +21,4 @@ xml: import_wiz.xml menu.xml cron.xml + From 8eaddc9b28560dfcc49b6c3bdc813653777f50c7 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Thu, 22 Jun 2023 17:28:58 +0200 Subject: [PATCH 03/13] asset: fixed possible exceptions --- asset.py | 65 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/asset.py b/asset.py index d599d7b..06bade6 100644 --- a/asset.py +++ b/asset.py @@ -330,23 +330,24 @@ class Asset(SymbolMixin, ModelSQL, ModelView): """ cursor = Transaction().connection.cursor() - (query, tab_asset) = cls.get_name_symbol_sql() - query.where = tab_asset.id.in_([x.id for x in assets]) - - cursor.execute(*query) - records = cursor.fetchall() result = {x: {y.id: None for y in assets} for x in names} - for record in records: - values = { - 'name': record[1], - 'product_uom': record[2], - 'symbol': record[3], - 'asset_symbol': record[0], - } + (query, tab_asset) = cls.get_name_symbol_sql() + if assets: + query.where = tab_asset.id.in_([x.id for x in assets]) + cursor.execute(*query) + records = cursor.fetchall() - for name in names: - result[name][record[0]] = values[name] + for record in records: + values = { + 'name': record[1], + 'product_uom': record[2], + 'symbol': record[3], + 'asset_symbol': record[0], + } + + for name in names: + result[name][record[0]] = values[name] return result @classmethod @@ -384,32 +385,32 @@ class Asset(SymbolMixin, ModelSQL, ModelView): def get_rate_data(cls, assets, names): """ get date and rate of asset """ - Asset2 = Pool().get('investment.asset') - cursor = Transaction().connection.cursor() - (query, tab_asset) = cls.get_rate_data_sql() - query.where = tab_asset.id.in_([x.id for x in assets]) - - cursor.execute(*query) - records = cursor.fetchall() result = {x: {y.id: None for y in assets} for x in names} - for record in records: - (id1, rate1, date1, id_rate) = record + if assets: + (query, tab_asset) = cls.get_rate_data_sql() + query.where = tab_asset.id.in_([x.id for x in assets]) + curr_digits = {x.id: x.currency_digits for x in assets} - asset = Asset2(id1) - exp = Decimal(Decimal(1) / 10 ** (asset.currency_digits or 4)) + cursor.execute(*query) + records = cursor.fetchall() - values = { - 'rate': record[1].quantize(exp), - 'date': record[2], - 'change_symbol': id_rate, - } + for record in records: + (id1, rate1, date1, id_rate) = record - for name in names: - result[name][record[0]] = values[name] + curr_dig = curr_digits.get(id1, 4) + exp = Decimal(Decimal(1) / 10 ** curr_dig) + values = { + 'rate': record[1].quantize(exp), + 'date': record[2], + 'change_symbol': id_rate, + } + + for name in names: + result[name][record[0]] = values[name] return result @classmethod From c06c2b8260e6ad230ba66985b8e5b469853a22f5 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 23 Jun 2023 16:02:31 +0200 Subject: [PATCH 04/13] asset/rate: speed up percent-queries --- asset.py | 48 ++++++++++++++++++++++-------------------------- rate.py | 7 +++++++ 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/asset.py b/asset.py index 06bade6..9d4ca63 100644 --- a/asset.py +++ b/asset.py @@ -473,8 +473,6 @@ class Asset(SymbolMixin, ModelSQL, ModelView): """ pool = Pool() Rate = pool.get('investment.rate') - Asset2 = pool.get('investment.asset') - tab_asset = Asset2.__table__() tab_rate1 = Rate.__table__() tab_rate2 = Rate.__table__() context = Transaction().context @@ -482,17 +480,14 @@ class Asset(SymbolMixin, ModelSQL, ModelView): query_date = context.get('qdate', CurrentDate()) where_asset = tab_rate1.date <= query_date if isinstance(asset_ids, list): - where_asset &= tab_asset.id.in_(asset_ids) + where_asset &= tab_rate1.asset.in_(asset_ids) - tab_today = tab_asset.join( - tab_rate1, - condition=tab_asset.id == tab_rate1.asset, - ).select( - tab_asset.id, + tab_today = tab_rate1.select( + tab_rate1.asset.as_('id'), tab_rate1.date, tab_rate1.rate, - distinct_on=[tab_asset.id], - order_by=[tab_asset.id, tab_rate1.date.desc], + distinct_on=[tab_rate1.asset], + order_by=[tab_rate1.asset, tab_rate1.date.desc], where=where_asset, ) @@ -613,23 +608,24 @@ class Asset(SymbolMixin, ModelSQL, ModelView): exp = Decimal(Decimal(1) / 10 ** digits_percent) asset_id_lst = [x.id for x in assets] - for x in names: - tab_percent = cls.get_percentage_sql( - days={ - 'change_day1': 0, - 'change_month1': 30, - 'change_month3': 90, - 'change_month6': 180, - 'change_month12': 365, - }[x], - asset_ids=asset_id_lst, - ) - cursor.execute(*tab_percent) - records = cursor.fetchall() + if asset_id_lst and names: + for x in names: + tab_percent = cls.get_percentage_sql( + days={ + 'change_day1': 0, + 'change_month1': 30, + 'change_month3': 90, + 'change_month6': 180, + 'change_month12': 365, + }[x], + asset_ids=asset_id_lst, + ) + cursor.execute(*tab_percent) + records = cursor.fetchall() - for record in records: - result[x][record[0]] = record[3].quantize(exp) \ - if record[3] is not None else None + for record in records: + result[x][record[0]] = record[3].quantize(exp) \ + if record[3] is not None else None return result @classmethod diff --git a/rate.py b/rate.py index eef697c..6379e6b 100644 --- a/rate.py +++ b/rate.py @@ -53,6 +53,13 @@ class Rate(SymbolMixin, ModelSQL, ModelView): Index( t, (t.rate, Index.Range())), + Index( + t, + (t.asset, Index.Equality())), + Index( + t, + (t.asset, Index.Equality()), + (t.date, Index.Range(order='DESC'))), }) @classmethod From 0b774fc6e2bf42a14c4086a9f3878c276c4a5558 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 23 Jun 2023 16:29:10 +0200 Subject: [PATCH 05/13] asset: avoid exceptions in get_identifiers() --- asset.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/asset.py b/asset.py index 9d4ca63..98286af 100644 --- a/asset.py +++ b/asset.py @@ -853,20 +853,19 @@ class Asset(SymbolMixin, ModelSQL, ModelView): cursor = Transaction().connection.cursor() result = {x: {y.id: None for y in assets} for x in names} + if assets: + query = cls.get_identifier_sql(tab_asset) + query.where = tab_asset.id.in_([x.id for x in assets]) - query = cls.get_identifier_sql(tab_asset) - query.where = tab_asset.id.in_([x.id for x in assets]) + cursor.execute(*query) + l1 = cursor.fetchall() - cursor.execute(*query) - l1 = cursor.fetchall() - - for x in l1: - (id1, wkn, secsymb, isin) = x - r1 = {'wkn': wkn, 'secsymb': secsymb, 'isin': isin} - - for n in names: - result[n][id1] = r1[n] + for x in l1: + (id1, wkn, secsymb, isin) = x + r1 = {'wkn': wkn, 'secsymb': secsymb, 'isin': isin} + for n in names: + result[n][id1] = r1[n] return result def get_rec_name(self, name): From 41a86155a1c845bdbae3019567c2bcb93ccc8880 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 23 Jun 2023 16:41:39 +0200 Subject: [PATCH 06/13] diagram: simplify queries --- diagram.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/diagram.py b/diagram.py index 514a2ad..08c7cab 100644 --- a/diagram.py +++ b/diagram.py @@ -60,16 +60,16 @@ class GraphDef(metaclass=PoolMeta): return None if self.scaling == 'alldata': - query = [('asset.id', '=', self.asset.id)] + query = [('asset', '=', self.asset.id)] elif self.scaling == 'view': query = [ - ('asset.id', '=', self.asset.id), + ('asset', '=', self.asset.id), ('date', '>=', self.chart.used_start_date()), ('date', '<=', self.chart.used_end_date()), ] elif self.scaling == 'six': query = [ - ('asset.id', '=', self.asset.id), + ('asset', '=', self.asset.id), ('date', '>=', self.chart.used_start_date() - timedelta(days=180)), ('date', '<=', self.chart.used_end_date()), @@ -104,12 +104,12 @@ class ChartPoint(metaclass=PoolMeta): before = Rate.search([ ('date', '<', query_date), - ('asset.id', '=', asset_id), + ('asset', '=', asset_id), ], limit=1, order=[('date', 'DESC')]) after = Rate.search([ ('date', '>', query_date), - ('asset.id', '=', asset_id), + ('asset', '=', asset_id), ], limit=1, order=[('date', 'ASC')]) if (len(before) == 1) and (len(after) == 1): From 6d72822526d682af9ba2370c3061499d897ddaab Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 23 Jun 2023 21:40:55 +0200 Subject: [PATCH 07/13] asset-list: remove percent-symbol to speed up list view --- view/asset_list.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/view/asset_list.xml b/view/asset_list.xml index daee4c5..e5c15bc 100644 --- a/view/asset_list.xml +++ b/view/asset_list.xml @@ -4,10 +4,10 @@ The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. --> - - - - + + + + From 530d382905d42cc8505580b48aaa5956e62fda32 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 1 Dec 2023 13:29:46 +0100 Subject: [PATCH 08/13] formatting --- asset.py | 9 +++++---- const.py | 8 ++++++++ import_wiz.py | 3 ++- onlinesource.py | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 const.py diff --git a/asset.py b/asset.py index 98286af..dd62caa 100644 --- a/asset.py +++ b/asset.py @@ -15,6 +15,7 @@ from sql.functions import CurrentDate, CurrentTimestamp, Round, Extract from sql.conditionals import Case, Coalesce, NullIf from sql import Literal from .diagram import Concat2 +from .const import DEF_NONE digits_percent = 2 @@ -100,8 +101,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView): string='URL', help='URL for data retrieval.', states={ - 'invisible': Eval('updturl_enable', False) == False, - 'required': Eval('updturl_enable', False) == True, + 'invisible': ~Eval('updturl_enable', False), + 'required': Eval('updturl_enable', False), }, depends=['updturl_enable']) updturl_enable = fields.Function(fields.Boolean( string='URL required', readonly=True, @@ -191,7 +192,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView): query = tab_asset.select( tab_asset.id, tab_asset.updtsource, - where=tab_asset.updtsource != None, + where=tab_asset.updtsource != DEF_NONE, ) cursor.execute(*query) records = cursor.fetchall() @@ -838,7 +839,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView): ).select( tab_asset.id, where=Operator(field_qu, clause[2]) & - (field_qu != None), + (field_qu != DEF_NONE), ) return [('id', 'in', query)] diff --git a/const.py b/const.py new file mode 100644 index 0000000..a01e781 --- /dev/null +++ b/const.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# This file is part of the cashbook-module from m-ds.de for Tryton. +# The COPYRIGHT file at the top level of this repository contains the +# full copyright notices and license terms. + + +DEF_TRUE = True +DEF_NONE = None diff --git a/import_wiz.py b/import_wiz.py index 72e7d4e..4722557 100644 --- a/import_wiz.py +++ b/import_wiz.py @@ -173,7 +173,8 @@ class ImportWizard(Wizard): datefmt='dd%sdd' % dec_divider, colnr='2')) - if isinstance(date_val, date) and isinstance(rate_val, Decimal): + if isinstance(date_val, date) and isinstance( + rate_val, Decimal): result.append({'date': date_val, 'rate': rate_val}) # date range diff --git a/onlinesource.py b/onlinesource.py index c881aa5..a74696a 100644 --- a/onlinesource.py +++ b/onlinesource.py @@ -86,7 +86,8 @@ class OnlineSource(ModelSQL, ModelView): states=STATES_WEB, depends=DEPENDS_WEB) rgxdecimal = fields.Selection( string='Decimal Separator', - help='Decimal separator for converting the market value into a number.', + help='Decimal separator for converting the market ' + + 'value into a number.', selection=sel_rgxdecimal, states=STATES_WEB, depends=DEPENDS_WEB) rgxident = fields.Char( string='Identifier', From 214edfd0704ce4c7e74b63f14efcf1e4b877d5f3 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 1 Dec 2023 13:40:14 +0100 Subject: [PATCH 09/13] Version 6.8.25 --- README.rst | 4 ++++ tryton.cfg | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 1f48f27..17e1669 100644 --- a/README.rst +++ b/README.rst @@ -22,6 +22,10 @@ You can define the course sources yourself. Changes ======= +*6.8.25 - 01.12.2023* + +- code/speed optimized + *6.8.24 - 07.06.2023* - portet to Tryton 6.8 diff --git a/tryton.cfg b/tryton.cfg index 4650f07..745c960 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=6.8.24 +version=6.8.25 depends: ir res From e63023170f84ed90be30fa83e2f8b78e7f94a08c Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Sun, 3 Dec 2023 18:20:22 +0100 Subject: [PATCH 11/13] asset: columns optional --- view/asset_list.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/view/asset_list.xml b/view/asset_list.xml index e5c15bc..7837d85 100644 --- a/view/asset_list.xml +++ b/view/asset_list.xml @@ -4,12 +4,12 @@ The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. --> - - - - - - - - + + + + + + + + From c84c2d290710a3bd20facf16ec23a765eebd0fb6 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Wed, 6 Dec 2023 22:37:56 +0100 Subject: [PATCH 12/13] Version 6.8.26 --- README.rst | 4 ++++ tryton.cfg | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 17e1669..f6ecf30 100644 --- a/README.rst +++ b/README.rst @@ -22,6 +22,10 @@ You can define the course sources yourself. Changes ======= +*6.8.26 - 06.12.2023* + +- add: columns optional + *6.8.25 - 01.12.2023* - code/speed optimized diff --git a/tryton.cfg b/tryton.cfg index 745c960..b7b3c7d 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=6.8.25 +version=6.8.26 depends: ir res