asset: fixed possible exceptions
This commit is contained in:
parent
ddffa302c4
commit
3b9de6c0bb
1 changed files with 33 additions and 32 deletions
21
asset.py
21
asset.py
|
@ -330,12 +330,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
cursor = Transaction().connection.cursor()
|
cursor = Transaction().connection.cursor()
|
||||||
|
|
||||||
(query, tab_asset) = cls.get_name_symbol_sql()
|
result = {x: {y.id: None for y in assets} for x in names}
|
||||||
query.where = tab_asset.id.in_([x.id for x in assets])
|
|
||||||
|
|
||||||
|
(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)
|
cursor.execute(*query)
|
||||||
records = cursor.fetchall()
|
records = cursor.fetchall()
|
||||||
result = {x: {y.id: None for y in assets} for x in names}
|
|
||||||
|
|
||||||
for record in records:
|
for record in records:
|
||||||
values = {
|
values = {
|
||||||
|
@ -384,22 +385,23 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
def get_rate_data(cls, assets, names):
|
def get_rate_data(cls, assets, names):
|
||||||
""" get date and rate of asset
|
""" get date and rate of asset
|
||||||
"""
|
"""
|
||||||
Asset2 = Pool().get('investment.asset')
|
|
||||||
|
|
||||||
cursor = Transaction().connection.cursor()
|
cursor = Transaction().connection.cursor()
|
||||||
|
|
||||||
|
result = {x: {y.id: None for y in assets} for x in names}
|
||||||
|
|
||||||
|
if assets:
|
||||||
(query, tab_asset) = cls.get_rate_data_sql()
|
(query, tab_asset) = cls.get_rate_data_sql()
|
||||||
query.where = tab_asset.id.in_([x.id for x in assets])
|
query.where = tab_asset.id.in_([x.id for x in assets])
|
||||||
|
curr_digits = {x.id: x.currency_digits for x in assets}
|
||||||
|
|
||||||
cursor.execute(*query)
|
cursor.execute(*query)
|
||||||
records = cursor.fetchall()
|
records = cursor.fetchall()
|
||||||
|
|
||||||
result = {x: {y.id: None for y in assets} for x in names}
|
|
||||||
|
|
||||||
for record in records:
|
for record in records:
|
||||||
(id1, rate1, date1, id_rate) = record
|
(id1, rate1, date1, id_rate) = record
|
||||||
|
|
||||||
asset = Asset2(id1)
|
curr_dig = curr_digits.get(id1, 4)
|
||||||
exp = Decimal(Decimal(1) / 10 ** (asset.currency_digits or 4))
|
exp = Decimal(Decimal(1) / 10 ** curr_dig)
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
'rate': record[1].quantize(exp),
|
'rate': record[1].quantize(exp),
|
||||||
|
@ -409,7 +411,6 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
result[name][record[0]] = values[name]
|
result[name][record[0]] = values[name]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in a new issue