Compare commits

..

13 commits
main ... 6.8

Author SHA1 Message Date
Frederik Jaeckel
5a320e57da Etikett ver 6.8.26 zum Änderungssatz c44e42da0955 hinzugefügt 2023-12-06 22:38:54 +01:00
Frederik Jaeckel
c84c2d2907 Version 6.8.26 2023-12-06 22:37:56 +01:00
Frederik Jaeckel
e63023170f asset: columns optional 2023-12-03 18:20:22 +01:00
Frederik Jaeckel
4656a4c65c Etikett ver 6.8.25 zum Änderungssatz 7e16130066c0 hinzugefügt 2023-12-01 13:40:37 +01:00
Frederik Jaeckel
214edfd070 Version 6.8.25 2023-12-01 13:40:14 +01:00
Frederik Jaeckel
530d382905 formatting 2023-12-01 13:29:46 +01:00
Frederik Jaeckel
6d72822526 asset-list: remove percent-symbol to speed up list view 2023-06-23 21:40:55 +02:00
Frederik Jaeckel
41a86155a1 diagram: simplify queries 2023-06-23 16:41:39 +02:00
Frederik Jaeckel
0b774fc6e2 asset: avoid exceptions in get_identifiers() 2023-06-23 16:29:10 +02:00
Frederik Jaeckel
c06c2b8260 asset/rate: speed up percent-queries 2023-06-23 16:02:31 +02:00
Frederik Jaeckel
8eaddc9b28 asset: fixed possible exceptions 2023-06-22 17:28:58 +02:00
Frederik Jaeckel
4f9fdb6fe7 Etikett ver 6.8.24 zum Änderungssatz 81540c6c6c42 hinzugefügt 2023-06-07 21:58:47 +02:00
Frederik Jaeckel
922c650a71 Version 6.8.24 2023-06-07 21:58:32 +02:00
13 changed files with 125 additions and 166 deletions

View file

@ -9,7 +9,7 @@ pip install mds-investment
Requires Requires
======== ========
- Tryton 7.0 - Tryton 6.8
How to How to
====== ======
@ -22,6 +22,14 @@ You can define the course sources yourself.
Changes Changes
======= =======
*7.0.0 - 01.12.2023* *6.8.26 - 06.12.2023*
- compatibility to Tryton 7.0 - add: columns optional
*6.8.25 - 01.12.2023*
- code/speed optimized
*6.8.24 - 07.06.2023*
- portet to Tryton 6.8

View file

@ -32,7 +32,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
name = fields.Function(fields.Char( name = fields.Function(fields.Char(
string='Name', readonly=True), string='Name', readonly=True),
'get_name_symbol', searcher='search_rec_name') 'get_name_symbol', searcher='search_rec_name')
company = fields.Many2One( company = fields.Many2One(
string='Company', model_name='company.company', string='Company', model_name='company.company',
required=True, ondelete="RESTRICT") required=True, ondelete="RESTRICT")
@ -46,9 +46,12 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
uom = fields.Many2One( uom = fields.Many2One(
string='UOM', required=True, model_name='product.uom', string='UOM', required=True, model_name='product.uom',
ondelete='RESTRICT', ondelete='RESTRICT',
states={'readonly': ~Bool(Eval('product'))}, states={
domain=[('category', '=', Eval('product_uom'))], 'readonly': ~Bool(Eval('product')),
depends=['product_uom', 'product']) },
domain=[
('category', '=', Eval('product_uom')),
], depends=['product_uom', 'product'])
symbol = fields.Function(fields.Char( symbol = fields.Function(fields.Char(
string='UOM', readonly=True), 'get_name_symbol', string='UOM', readonly=True), 'get_name_symbol',
searcher='search_uom_symbol') searcher='search_uom_symbol')
@ -71,7 +74,9 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
model_name='currency.currency', ondelete='RESTRICT') model_name='currency.currency', ondelete='RESTRICT')
currency_digits = fields.Integer( currency_digits = fields.Integer(
string='Digits', required=True, string='Digits', required=True,
domain=[('currency_digits', '>=', 0), ('currency_digits', '<=', 6)]) domain=[
('currency_digits', '>=', 0),
('currency_digits', '<=', 6)])
wkn = fields.Function(fields.Char( wkn = fields.Function(fields.Char(
string='NSIN', readonly=True, string='NSIN', readonly=True,
@ -107,8 +112,9 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
string='Select days', required=True, selection=sel_updtdays) string='Select days', required=True, selection=sel_updtdays)
updttime = fields.Time( updttime = fields.Time(
string='Time', string='Time',
states={'readonly': ~Bool(Eval('updtsources'))}, states={
depends=['updtsources']) 'readonly': ~Bool(Eval('updtsources')),
}, depends=['updtsources'])
nextupdate = fields.Function(fields.DateTime( nextupdate = fields.Function(fields.DateTime(
string='Next Update', readonly=True), string='Next Update', readonly=True),
'get_nextupdates', searcher='search_nextupdate') 'get_nextupdates', searcher='search_nextupdate')
@ -195,7 +201,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
'source': x[1], 'source': x[1],
} for x in records] } for x in records]
if to_create: if len(to_create) > 0:
AssetSourceRel.create(to_create) AssetSourceRel.create(to_create)
asset_table.drop_column('updtsource') asset_table.drop_column('updtsource')
@ -256,7 +262,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
def on_change_updtsources(self): def on_change_updtsources(self):
""" clear time-fields """ clear time-fields
""" """
if not self.updtsources: if len(self.updtsources) == 0:
self.updttime = None self.updttime = None
else: else:
self.updttime = time(11, 30) self.updttime = time(11, 30)
@ -417,7 +423,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_query.select( query = tab_query.select(
tab_query.id, tab_query.id,
where=Operator(tab_query.date, clause[2])) where=Operator(tab_query.date, clause[2]),
)
return [('id', 'in', query)] return [('id', 'in', query)]
@classmethod @classmethod
@ -429,7 +436,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_query.select( query = tab_query.select(
tab_query.id, tab_query.id,
where=Operator(tab_query.rate, clause[2])) where=Operator(tab_query.rate, clause[2]),
)
return [('id', 'in', query)] return [('id', 'in', query)]
@staticmethod @staticmethod
@ -441,7 +449,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_query.select( query = tab_query.select(
tab_query.date, tab_query.date,
where=tab_query.id == table.id) where=tab_query.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -453,7 +462,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_query.select( query = tab_query.select(
tab_query.rate, tab_query.rate,
where=tab_query.id == table.id) where=tab_query.id == table.id,
)
return [query] return [query]
@classmethod @classmethod
@ -479,7 +489,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
tab_rate1.rate, tab_rate1.rate,
distinct_on=[tab_rate1.asset], distinct_on=[tab_rate1.asset],
order_by=[tab_rate1.asset, tab_rate1.date.desc], order_by=[tab_rate1.asset, tab_rate1.date.desc],
where=where_asset) where=where_asset,
)
days_diff = days + 5 days_diff = days + 5
query = tab_today.join( query = tab_today.join(
@ -495,7 +506,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
(tab_today.rate * 100.0 / NullIf(tab_rate2.rate, 0.00) - (tab_today.rate * 100.0 / NullIf(tab_rate2.rate, 0.00) -
100.0).as_('percent'), 100.0).as_('percent'),
distinct_on=[tab_today.id], distinct_on=[tab_today.id],
order_by=[tab_today.id, tab_rate2.date.desc]) order_by=[tab_today.id, tab_rate2.date.desc]
)
return query return query
@staticmethod @staticmethod
@ -508,7 +520,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_asset.select( query = tab_asset.select(
tab_asset.percent, tab_asset.percent,
where=tab_asset.id == table.id) where=tab_asset.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -521,7 +534,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_asset.select( query = tab_asset.select(
tab_asset.percent, tab_asset.percent,
where=tab_asset.id == table.id) where=tab_asset.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -534,7 +548,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_asset.select( query = tab_asset.select(
tab_asset.percent, tab_asset.percent,
where=tab_asset.id == table.id) where=tab_asset.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -547,7 +562,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_asset.select( query = tab_asset.select(
tab_asset.percent, tab_asset.percent,
where=tab_asset.id == table.id) where=tab_asset.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -560,7 +576,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_asset.select( query = tab_asset.select(
tab_asset.percent, tab_asset.percent,
where=tab_asset.id == table.id) where=tab_asset.id == table.id,
)
return [query] return [query]
@classmethod @classmethod
@ -602,13 +619,14 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
'change_month6': 180, 'change_month6': 180,
'change_month12': 365, 'change_month12': 365,
}[x], }[x],
asset_ids=asset_id_lst) asset_ids=asset_id_lst,
)
cursor.execute(*tab_percent) cursor.execute(*tab_percent)
records = cursor.fetchall() records = cursor.fetchall()
for record in records: for record in records:
result[x][record[0]] = record[3].quantize(exp) \ result[x][record[0]] = record[3].quantize(exp) \
if record[3] is not None else None if record[3] is not None else None
return result return result
@classmethod @classmethod
@ -642,7 +660,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
tab_asset.updtdays, tab_asset.updtdays,
tab_asset.updttime, tab_asset.updttime,
distinct_on=[tab_asset.id], distinct_on=[tab_asset.id],
order_by=[tab_asset.id, tab_rate.date.desc]) order_by=[tab_asset.id, tab_rate.date.desc],
)
query = tab_date.select( query = tab_date.select(
tab_date.id, tab_date.id,
@ -654,7 +673,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
(Extract('dow', tab_date.date) == 6), (Extract('dow', tab_date.date) == 6),
tab_date.date + Literal(2)), tab_date.date + Literal(2)),
else_=tab_date.date, else_=tab_date.date,
) + tab_date.updttime).as_('updttime')) ) + tab_date.updttime).as_('updttime'),
)
return query return query
@classmethod @classmethod
@ -668,7 +688,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_updt.select( query = tab_updt.select(
tab_updt.id, tab_updt.id,
tab_updt.updttime, tab_updt.updttime,
where=tab_updt.id.in_([x.id for x in assets])) where=tab_updt.id.in_([x.id for x in assets]),
)
cursor.execute(*query) cursor.execute(*query)
records = cursor.fetchall() records = cursor.fetchall()
@ -692,7 +713,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_updt.select( query = tab_updt.select(
tab_updt.id, tab_updt.id,
where=Operator(tab_updt.updttime, clause[2])) where=Operator(tab_updt.updttime, clause[2]),
)
return [('id', 'in', query)] return [('id', 'in', query)]
@classmethod @classmethod
@ -729,7 +751,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
tab_asset.id, tab_asset.id,
tab_wkn.code.as_('wkn'), tab_wkn.code.as_('wkn'),
tab_secsymb.code.as_('secsymb'), tab_secsymb.code.as_('secsymb'),
tab_isin.code.as_('isin')) tab_isin.code.as_('isin'),
)
return query return query
@staticmethod @staticmethod
@ -753,7 +776,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
condition=tab_templ.id == tab_prod.template condition=tab_templ.id == tab_prod.template
).select( ).select(
tab_templ.name, tab_templ.name,
where=tab_asset.id == table.id) where=tab_asset.id == table.id
)
return [query] return [query]
@staticmethod @staticmethod
@ -766,7 +790,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_ids.select( query = tab_ids.select(
getattr(tab_ids, 'wkn'), getattr(tab_ids, 'wkn'),
where=tab_ids.id == table.id) where=tab_ids.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -779,7 +804,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_ids.select( query = tab_ids.select(
getattr(tab_ids, 'isin'), getattr(tab_ids, 'isin'),
where=tab_ids.id == table.id) where=tab_ids.id == table.id,
)
return [query] return [query]
@staticmethod @staticmethod
@ -792,7 +818,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
query = tab_ids.select( query = tab_ids.select(
getattr(tab_ids, 'secsymb'), getattr(tab_ids, 'secsymb'),
where=tab_ids.id == table.id) where=tab_ids.id == table.id,
)
return [query] return [query]
@classmethod @classmethod
@ -812,7 +839,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
).select( ).select(
tab_asset.id, tab_asset.id,
where=Operator(field_qu, clause[2]) & where=Operator(field_qu, clause[2]) &
(field_qu != DEF_NONE)) (field_qu != DEF_NONE),
)
return [('id', 'in', query)] return [('id', 'in', query)]
@ -885,7 +913,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
if OnlineSource.update_rate(asset): if OnlineSource.update_rate(asset):
to_run_activities.append(asset) to_run_activities.append(asset)
if to_run_activities: if len(to_run_activities) > 0:
cls.after_update_actions(to_run_activities) cls.after_update_actions(to_run_activities)
# end Asset # end Asset

View file

@ -95,7 +95,7 @@ class ChartPoint(metaclass=PoolMeta):
""" """
Rate = Pool().get('investment.rate') Rate = Pool().get('investment.rate')
if not keyname: if keyname is None:
return None return None
# check if query is for us # check if query is for us

View file

@ -84,14 +84,14 @@ class ImportWizard(Wizard):
pool = Pool() pool = Pool()
ImportWiz = pool.get('investment.imp_wiz', type='wizard') ImportWiz = pool.get('investment.imp_wiz', type='wizard')
if self.start.file_: if self.start.file_ is not None:
(lines, max_date, min_date) = ImportWiz.read_csv_file( (lines, max_date, min_date) = ImportWiz.read_csv_file(
self.start.file_.decode('utf8'), self.start.file_.decode('utf8'),
dec_divider=self.start.dec_divider, dec_divider=self.start.dec_divider,
date_fmt=self.start.date_fmt, date_fmt=self.start.date_fmt,
delimiter=self.start.field_delimiter) delimiter=self.start.field_delimiter)
if lines: if len(lines) > 0:
ImportWiz.upload_rates( ImportWiz.upload_rates(
self.start.asset, self.start.asset,
lines, min_date, max_date) lines, min_date, max_date)

View file

@ -50,10 +50,6 @@ msgctxt "model:ir.message,text:msg_missing_url"
msgid "URL for the online source '%(oname)s' is missing." msgid "URL for the online source '%(oname)s' is missing."
msgstr "URL für die Onlinequelle '%(oname)s' fehlt." msgstr "URL für die Onlinequelle '%(oname)s' fehlt."
msgctxt "model:ir.message,text:msg_bug_in_regexquery"
msgid "Error in regex code of field '%(fname)s': %(errmsg)s [%(code)s]"
msgstr "Fehler in Regex-Code des Feldes '%(fname)s': %(errmsg)s [%(code)s]"
############## ##############
# ir.ui.menu # # ir.ui.menu #

View file

@ -38,10 +38,6 @@ msgctxt "model:ir.message,text:msg_missing_url"
msgid "URL for the online source '%(oname)s' is missing." msgid "URL for the online source '%(oname)s' is missing."
msgstr "URL for the online source '%(oname)s' is missing." msgstr "URL for the online source '%(oname)s' is missing."
msgctxt "model:ir.message,text:msg_bug_in_regexquery"
msgid "Error in regex code of field '%(fname)s': %(errmsg)s [%(code)s]"
msgstr "Error in regex code of field '%(fname)s': %(errmsg)s [%(code)s]"
msgctxt "model:ir.ui.menu,name:menu_investment" msgctxt "model:ir.ui.menu,name:menu_investment"
msgid "Investment" msgid "Investment"
msgstr "Investment" msgstr "Investment"
@ -298,18 +294,6 @@ msgctxt "selection:investment.asset,updtdays:"
msgid "Mon - Sun" msgid "Mon - Sun"
msgstr "Mon - Sun" msgstr "Mon - Sun"
msgctxt "field:investment.asset,updturl:"
msgid "URL"
msgstr "URL"
msgctxt "help:investment.asset,updturl:"
msgid "URL for data retrieval."
msgstr "URL for data retrieval."
msgctxt "field:investment.asset,updturl_enable:"
msgid "URL required"
msgstr "URL required"
msgctxt "model:investment.asset_source_rel,name:" msgctxt "model:investment.asset_source_rel,name:"
msgid "Asset Source Relation" msgid "Asset Source Relation"
msgstr "Asset Source Relation" msgstr "Asset Source Relation"

View file

@ -23,9 +23,6 @@ full copyright notices and license terms. -->
<record model="ir.message" id="msg_missing_url"> <record model="ir.message" id="msg_missing_url">
<field name="text">URL for the online source '%(oname)s' is missing.</field> <field name="text">URL for the online source '%(oname)s' is missing.</field>
</record> </record>
<record model="ir.message" id="msg_bug_in_regexquery">
<field name="text">Error in regex code of field '%(fname)s': %(errmsg)s [%(code)s]</field>
</record>
</data> </data>
</tryton> </tryton>

View file

@ -63,14 +63,16 @@ class OnlineSource(ModelSQL, ModelView):
url = fields.Char(string='URL', states=STATES_WEB, depends=DEPENDS_WEB) url = fields.Char(string='URL', states=STATES_WEB, depends=DEPENDS_WEB)
fixed_url = fields.Boolean( fixed_url = fields.Boolean(
string='Fixed URL', string='Fixed URL',
states={'invisible': Eval('query_method', '') != 'web'}, states={
depends=DEPENDS_WEB, 'invisible': Eval('query_method', '') != 'web',
}, depends=DEPENDS_WEB,
help='URL must be defined at investment record.') help='URL must be defined at investment record.')
nohtml = fields.Boolean( nohtml = fields.Boolean(
string='Remove HTML', string='Remove HTML',
help='Removes HTML tags before the text is interpreted.', help='Removes HTML tags before the text is interpreted.',
states={'invisible': STATES_WEB['invisible']}, states={
depends=DEPENDS_WEB) 'invisible': STATES_WEB['invisible'],
}, depends=DEPENDS_WEB)
rgxdate = fields.Char( rgxdate = fields.Char(
string='Date', string='Date',
help='Regex code to find the date in the downloaded HTML file.', help='Regex code to find the date in the downloaded HTML file.',
@ -90,8 +92,9 @@ class OnlineSource(ModelSQL, ModelView):
rgxident = fields.Char( rgxident = fields.Char(
string='Identifier', string='Identifier',
help='Regex code to find the identifier in the downloaded HTML file.', help='Regex code to find the identifier in the downloaded HTML file.',
states={'invisible': STATES_WEB['invisible']}, states={
depends=DEPENDS_WEB) 'invisible': STATES_WEB['invisible'],
}, depends=DEPENDS_WEB)
rgxidtype = fields.Selection( rgxidtype = fields.Selection(
string='ID-Type', selection=sel_rgxidtype, string='ID-Type', selection=sel_rgxidtype,
help='Type of identifier used to validate the result.', help='Type of identifier used to validate the result.',
@ -240,13 +243,16 @@ class OnlineSource(ModelSQL, ModelView):
isin=self.isin, isin=self.isin,
nsin=self.nsin, nsin=self.nsin,
symbol=self.symbol, symbol=self.symbol,
url=self.url) url=self.url,
)
@classmethod @classmethod
def get_query_methods(cls): def get_query_methods(cls):
""" get list of query-methods """ get list of query-methods
""" """
return [('web', gettext('investment.msg_querytype_web'))] return [
('web', gettext('investment.msg_querytype_web')),
]
@classmethod @classmethod
def set_test_value(cls, record, name, value): def set_test_value(cls, record, name, value):
@ -254,15 +260,6 @@ class OnlineSource(ModelSQL, ModelView):
""" """
pass pass
@classmethod
def validate(cls, records):
""" check regex-code
"""
for record in records:
for x in ['rgxdate', 'rgxrate', 'rgxident']:
if x:
record.get_regex_result('', x)
@classmethod @classmethod
def run_query_method(cls, osource, isin, nsin, symbol, url, debug=False): def run_query_method(cls, osource, isin, nsin, symbol, url, debug=False):
""" run selected query to retrive data """ run selected query to retrive data
@ -283,7 +280,8 @@ class OnlineSource(ModelSQL, ModelView):
nsin=nsin, nsin=nsin,
symbol=symbol, symbol=symbol,
debug=debug, debug=debug,
url=url) url=url,
)
def call_online_source(self): def call_online_source(self):
""" use updated values to call online-source, """ use updated values to call online-source,
@ -294,7 +292,7 @@ class OnlineSource(ModelSQL, ModelView):
result = OSourc.run_query_method( result = OSourc.run_query_method(
self, self.isin, self.nsin, self.url, self, self.isin, self.nsin, self.url,
self.symbol, debug=True) self.symbol, debug=True)
if result: if result is not None:
self.text = result.get('text', None) self.text = result.get('text', None)
self.http_state = result.get('http_state', None) self.http_state = result.get('http_state', None)
self.fnddate = result.get('date', None) self.fnddate = result.get('date', None)
@ -306,17 +304,19 @@ class OnlineSource(ModelSQL, ModelView):
""" generate url """ generate url
""" """
if self.fixed_url is True: if self.fixed_url is True:
if not url: if url is None:
raise UserError(gettext( raise UserError(gettext(
'investment.msg_missing_url', 'investment.msg_missing_url',
oname=self.rec_name)) oname=self.rec_name,
))
return url return url
else:
if self.url: if self.url:
return Template(self.url).substitute({ return Template(self.url).substitute({
'isin': isin if isin is not None else '', 'isin': isin if isin is not None else '',
'nsin': nsin if nsin is not None else '', 'nsin': nsin if nsin is not None else '',
'symbol': symbol if symbol is not None else ''}) 'symbol': symbol if symbol is not None else '',
})
@classmethod @classmethod
def update_rate(cls, asset): def update_rate(cls, asset):
@ -335,7 +335,8 @@ class OnlineSource(ModelSQL, ModelView):
isin=asset.isin, isin=asset.isin,
nsin=asset.wkn, nsin=asset.wkn,
symbol=asset.secsymb, symbol=asset.secsymb,
url=asset.updturl) url=asset.updturl,
)
if len(updtsource.rgxident or '') > 0: if len(updtsource.rgxident or '') > 0:
# check result - same code? # check result - same code?
@ -352,13 +353,15 @@ class OnlineSource(ModelSQL, ModelView):
'update_rate: got wrong code ' + 'update_rate: got wrong code ' +
'"%(wrong)s" - expected "%(exp)s"' % { '"%(wrong)s" - expected "%(exp)s"' % {
'exp': asset_code, 'exp': asset_code,
'wrong': code}) 'wrong': code,
})
continue continue
to_create = { to_create = {
'date': rate_data.get('date', None), 'date': rate_data.get('date', None),
'rate': rate_data.get('rate', None), 'rate': rate_data.get('rate', None),
'asset': asset.id} 'asset': asset.id,
}
if (to_create['date'] is not None) and \ if (to_create['date'] is not None) and \
(to_create['rate'] is not None): (to_create['rate'] is not None):
# check if exists # check if exists
@ -377,22 +380,13 @@ class OnlineSource(ModelSQL, ModelView):
def get_regex_result(self, html_text, field_name): def get_regex_result(self, html_text, field_name):
""" run regex on html-text, convert result """ run regex on html-text, convert result
""" """
OSource = Pool().get('investment.source')
rgxcode = getattr(self, field_name) or '' rgxcode = getattr(self, field_name) or ''
if len(rgxcode) == 0: if len(rgxcode) == 0:
return None return None
try: search_result = re.compile(rgxcode).search(html_text)
search_result = re.compile(rgxcode).search(html_text) if search_result is None:
if search_result is None: return None
return None
except Exception as e1:
raise UserError(gettext(
'investment.msg_bug_in_regexquery',
errmsg=str(e1),
fname=getattr(OSource, field_name).string,
code=rgxcode))
try: try:
result = search_result.group(1) result = search_result.group(1)
@ -433,7 +427,8 @@ class OnlineSource(ModelSQL, ModelView):
isin=isin, isin=isin,
nsin=nsin, nsin=nsin,
symbol=symbol, symbol=symbol,
url=url), url=url,
),
allow_redirects=True, allow_redirects=True,
timeout=5.0) timeout=5.0)
@ -442,7 +437,7 @@ class OnlineSource(ModelSQL, ModelView):
'msg': res1.reason, 'msg': res1.reason,
} }
if res1.status_code in [200, 204, 410]: if res1.status_code in [200, 204]:
html = res1.text html = res1.text
# remove html-tags # remove html-tags

View file

@ -39,8 +39,8 @@ with open(path.join(here, 'versiondep.txt'), encoding='utf-8') as f:
modversion[l2[0]] = {'min': l2[1], 'max': l2[2], 'prefix': l2[3]} modversion[l2[0]] = {'min': l2[1], 'max': l2[2], 'prefix': l2[3]}
# tryton-version # tryton-version
major_version = 7 major_version = 6
minor_version = 0 minor_version = 8
requires = ['requests>=2.26', 'html2text'] requires = ['requests>=2.26', 'html2text']
for dep in info.get('depends', []): for dep in info.get('depends', []):

View file

@ -71,9 +71,9 @@ full copyright notices and license terms. -->
<field name="name">www.sbroker.de</field> <field name="name">www.sbroker.de</field>
<field name="url">https://www.sbroker.de/sbl/mdaten_analyse/dksuche_a?SEARCH_VALUE=${isin}</field> <field name="url">https://www.sbroker.de/sbl/mdaten_analyse/dksuche_a?SEARCH_VALUE=${isin}</field>
<field name="nohtml" eval="True"/> <field name="nohtml" eval="True"/>
<field name="rgxdate">\nDatum\s*(?:\/ Uhrzeit)*: (\d+\.\d+\.\d+)\s*(?:\/ \d+:\d+)*\s*\n</field> <field name="rgxdate">\nDatum / Uhrzeit: (\d+\.\d+\.\d+) / \d+:\d+\s+\n</field>
<field name="rgxdatefmt">%d.%m.%y</field> <field name="rgxdatefmt">%d.%m.%y</field>
<field name="rgxrate">(?:Kurs aktuell|Rucknahmepreis)\s+[()\w\./\[\]!]+\s+(\d+,\d+)\s+(EUR|€)</field> <field name="rgxrate">Kurs aktuell .* (\d+,\d+)\s+EUR.*\n</field>
<field name="rgxdecimal">,</field> <field name="rgxdecimal">,</field>
<field name="rgxident">\nWKN / ISIN: [A-Z,0-9]+ / ([A-Z,0-9]+)\s+\n</field> <field name="rgxident">\nWKN / ISIN: [A-Z,0-9]+ / ([A-Z,0-9]+)\s+\n</field>
<field name="rgxidtype">isin</field> <field name="rgxidtype">isin</field>

View file

@ -6,7 +6,6 @@
from trytond.tests.test_tryton import with_transaction from trytond.tests.test_tryton import with_transaction
from trytond.pool import Pool from trytond.pool import Pool
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.exceptions import UserError
from decimal import Decimal from decimal import Decimal
from datetime import time, date, datetime from datetime import time, date, datetime
from unittest.mock import MagicMock from unittest.mock import MagicMock
@ -132,54 +131,5 @@ High 34,87 EUR
'rgxdate' 'rgxdate'
), date(2022, 3, 14)) ), date(2022, 3, 14))
@with_transaction()
def test_waitlist_source_check_regex_validate(self):
""" create source, check validation of regex-code
"""
pool = Pool()
OSource = pool.get('investment.source')
self.assertRaisesRegex(
UserError,
r"Error in regex code of field 'Date': nothing to repeat " +
r"at position 0 \[\*+ multiple repeat\]",
OSource.create,
[{
'name': 'Check date',
'rgxdate': '** multiple repeat',
'rgxrate': 'rate -- multiple repeat',
'rgxident': 'identifiert ** multiple repeat',
}])
self.assertRaisesRegex(
UserError,
r"Error in regex code of field 'Rate': multiple repeat " +
r"at position 6 \[rate \*+ multiple repeat\]",
OSource.create,
[{
'name': 'Check rate',
'rgxdate': '-- multiple repeat',
'rgxrate': 'rate ** multiple repeat',
'rgxident': 'identifiert -- multiple repeat',
}])
self.assertRaisesRegex(
UserError,
r"Error in regex code of field 'Identifier': multiple " +
r"repeat at position 13 \[identifiert \*+ multiple repeat\]",
OSource.create,
[{
'name': 'Check rgxident',
'rgxdate': '-- multiple repeat',
'rgxrate': 'rate -- multiple repeat',
'rgxident': 'identifiert ** multiple repeat',
}])
OSource.create([{
'name': 'Check rgxident',
'rgxdate': '-- multiple repeat',
'rgxrate': 'rate -- multiple repeat',
'rgxident': 'identifiert -- multiple repeat',
}])
# end SourceTestCase # end SourceTestCase

View file

@ -1,5 +1,5 @@
[tryton] [tryton]
version=7.0.0 version=6.8.26
depends: depends:
ir ir
res res
@ -21,3 +21,4 @@ xml:
import_wiz.xml import_wiz.xml
menu.xml menu.xml
cron.xml cron.xml

View file

@ -29,7 +29,7 @@ class UpdateSoureWizard(Wizard):
if OnlineSource.update_rate(asset): if OnlineSource.update_rate(asset):
to_run_activities.append(asset) to_run_activities.append(asset)
if to_run_activities: if len(to_run_activities) > 0:
Asset.after_update_actions(to_run_activities) Asset.after_update_actions(to_run_activities)
return 'end' return 'end'