formatting
This commit is contained in:
parent
82f9d3a792
commit
8f12741d76
14 changed files with 411 additions and 344 deletions
332
asset.py
332
asset.py
|
@ -8,7 +8,6 @@ from trytond.transaction import Transaction
|
|||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, Bool, If, Date
|
||||
from trytond.report import Report
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
from decimal import Decimal
|
||||
from datetime import time
|
||||
|
@ -30,59 +29,71 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
'Asset'
|
||||
__name__ = 'investment.asset'
|
||||
|
||||
name = fields.Function(fields.Char(string='Name', readonly=True),
|
||||
'get_name_symbol', searcher='search_rec_name')
|
||||
company = fields.Many2One(string='Company', model_name='company.company',
|
||||
name = fields.Function(fields.Char(
|
||||
string='Name', readonly=True),
|
||||
'get_name_symbol', searcher='search_rec_name')
|
||||
company = fields.Many2One(
|
||||
string='Company', model_name='company.company',
|
||||
required=True, ondelete="RESTRICT")
|
||||
product = fields.Many2One(string='Product', required=True,
|
||||
model_name='product.product', ondelete='RESTRICT',
|
||||
domain=[('type', '=', 'assets')])
|
||||
product_uom = fields.Function(fields.Many2One(string='UOM Category',
|
||||
readonly=True, model_name='product.uom.category',
|
||||
product = fields.Many2One(
|
||||
string='Product', required=True, model_name='product.product',
|
||||
ondelete='RESTRICT', domain=[('type', '=', 'assets')])
|
||||
product_uom = fields.Function(fields.Many2One(
|
||||
string='UOM Category', readonly=True,
|
||||
model_name='product.uom.category',
|
||||
help='Category of unit on the product.'), 'get_name_symbol')
|
||||
uom = fields.Many2One(string='UOM', required=True,
|
||||
model_name='product.uom', ondelete='RESTRICT',
|
||||
uom = fields.Many2One(
|
||||
string='UOM', required=True, model_name='product.uom',
|
||||
ondelete='RESTRICT',
|
||||
states={
|
||||
'readonly': ~Bool(Eval('product')),
|
||||
},
|
||||
domain=[
|
||||
('category', '=', Eval('product_uom')),
|
||||
], depends=['product_uom', 'product'])
|
||||
symbol = fields.Function(fields.Char(string='UOM', readonly=True),
|
||||
'get_name_symbol', searcher='search_uom_symbol')
|
||||
asset_symbol = fields.Function(fields.Many2One(string='Symbol',
|
||||
readonly=True, model_name='investment.asset'),
|
||||
symbol = fields.Function(fields.Char(
|
||||
string='UOM', readonly=True), 'get_name_symbol',
|
||||
searcher='search_uom_symbol')
|
||||
asset_symbol = fields.Function(fields.Many2One(
|
||||
string='Symbol', readonly=True, model_name='investment.asset'),
|
||||
'get_name_symbol')
|
||||
|
||||
rates = fields.One2Many(string='Rates', field='asset',
|
||||
model_name='investment.rate')
|
||||
rate = fields.Function(fields.Numeric(string='Current Rate',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 4)),
|
||||
depends=['currency_digits']),
|
||||
rates = fields.One2Many(
|
||||
string='Rates', field='asset', model_name='investment.rate')
|
||||
rate = fields.Function(fields.Numeric(
|
||||
string='Current Rate', readonly=True,
|
||||
digits=(16, Eval('currency_digits', 4)), depends=['currency_digits']),
|
||||
'get_rate_data', searcher='search_rate')
|
||||
date = fields.Function(fields.Date(string='Date', readonly=True,
|
||||
help='Date of current rate'),
|
||||
date = fields.Function(fields.Date(
|
||||
string='Date', readonly=True, help='Date of current rate'),
|
||||
'get_rate_data', searcher='search_date')
|
||||
|
||||
currency = fields.Many2One(string='Currency', select=True,
|
||||
required=True, model_name='currency.currency', ondelete='RESTRICT')
|
||||
currency_digits = fields.Integer(string='Digits', required=True,
|
||||
currency = fields.Many2One(
|
||||
string='Currency', select=True, required=True,
|
||||
model_name='currency.currency', ondelete='RESTRICT')
|
||||
currency_digits = fields.Integer(
|
||||
string='Digits', required=True,
|
||||
domain=[
|
||||
('currency_digits', '>=', 0),
|
||||
('currency_digits', '<=', 6)])
|
||||
|
||||
wkn = fields.Function(fields.Char(string='NSIN', readonly=True,
|
||||
wkn = fields.Function(fields.Char(
|
||||
string='NSIN', readonly=True,
|
||||
help='National Securities Identifying Number'),
|
||||
'get_identifiers', searcher='search_identifier')
|
||||
isin = fields.Function(fields.Char(string='ISIN', readonly=True,
|
||||
isin = fields.Function(fields.Char(
|
||||
string='ISIN', readonly=True,
|
||||
help='International Securities Identification Number'),
|
||||
'get_identifiers', searcher='search_identifier')
|
||||
secsymb = fields.Function(fields.Char(string='Symbol', readonly=True,
|
||||
secsymb = fields.Function(fields.Char(
|
||||
string='Symbol', readonly=True,
|
||||
help='Stock market symbol'),
|
||||
'get_identifiers', searcher='search_identifier')
|
||||
|
||||
updtsources = fields.Many2Many(string='Update Sources',
|
||||
help='Select sources for the course update. The course sources are tried until a valid value has been read.',
|
||||
updtsources = fields.Many2Many(
|
||||
string='Update Sources',
|
||||
help='Select sources for the course update. The course sources ' +
|
||||
'are tried until a valid value has been read.',
|
||||
relation_name='investment.asset_source_rel',
|
||||
origin='asset', target='source')
|
||||
updturl = fields.Char(
|
||||
|
@ -98,37 +109,42 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
'on_change_with_updturl_enable')
|
||||
updtdays = fields.Selection(
|
||||
string='Select days', required=True, selection=sel_updtdays)
|
||||
updttime = fields.Time(string='Time',
|
||||
updttime = fields.Time(
|
||||
string='Time',
|
||||
states={
|
||||
'readonly': ~Bool(Eval('updtsources')),
|
||||
}, depends=['updtsources'])
|
||||
nextupdate = fields.Function(fields.DateTime(string='Next Update',
|
||||
readonly=True),
|
||||
nextupdate = fields.Function(fields.DateTime(
|
||||
string='Next Update', readonly=True),
|
||||
'get_nextupdates', searcher='search_nextupdate')
|
||||
|
||||
# percentage change
|
||||
change_day1 = fields.Function(fields.Numeric(string='Previous Day',
|
||||
help='percentage change in value compared to the previous day',
|
||||
readonly=True, digits=(16,digits_percent)),
|
||||
change_day1 = fields.Function(fields.Numeric(
|
||||
string='Previous Day', readonly=True,
|
||||
digits=(16, digits_percent)),
|
||||
'get_percentage_change', searcher='search_percentage')
|
||||
change_month1 = fields.Function(fields.Numeric(string='1 Month',
|
||||
change_month1 = fields.Function(fields.Numeric(
|
||||
string='1 Month', readonly=True,
|
||||
help='percentage change in value compared to last month',
|
||||
readonly=True, digits=(16,digits_percent)),
|
||||
digits=(16, digits_percent)),
|
||||
'get_percentage_change', searcher='search_percentage')
|
||||
change_month3 = fields.Function(fields.Numeric(string='3 Months',
|
||||
change_month3 = fields.Function(fields.Numeric(
|
||||
string='3 Months',
|
||||
help='percentage change in value during 3 months',
|
||||
readonly=True, digits=(16,digits_percent)),
|
||||
digits=(16, digits_percent)),
|
||||
'get_percentage_change', searcher='search_percentage')
|
||||
change_month6 = fields.Function(fields.Numeric(string='6 Months',
|
||||
change_month6 = fields.Function(fields.Numeric(
|
||||
string='6 Months', readonly=True,
|
||||
help='percentage change in value during 6 months',
|
||||
readonly=True, digits=(16,digits_percent)),
|
||||
digits=(16, digits_percent)),
|
||||
'get_percentage_change', searcher='search_percentage')
|
||||
change_month12 = fields.Function(fields.Numeric(string='1 Year',
|
||||
change_month12 = fields.Function(fields.Numeric(
|
||||
string='1 Year', readonly=True,
|
||||
help='percentage change in value during 1 year',
|
||||
readonly=True, digits=(16,digits_percent)),
|
||||
digits=(16, digits_percent)),
|
||||
'get_percentage_change', searcher='search_percentage')
|
||||
change_symbol = fields.Function(fields.Many2One(string='Symbol',
|
||||
readonly=True, model_name='investment.rate'),
|
||||
change_symbol = fields.Function(fields.Many2One(
|
||||
string='Symbol', readonly=True, model_name='investment.rate'),
|
||||
'get_rate_data')
|
||||
|
||||
@classmethod
|
||||
|
@ -160,7 +176,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 != None,
|
||||
)
|
||||
cursor.execute(*query)
|
||||
records = cursor.fetchall()
|
||||
|
@ -179,9 +195,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
('/tree', 'visual',
|
||||
If(Eval('date', Date()) < Date(delta_days=-5), 'muted',
|
||||
If(Eval('change_day1', 0) < 0, 'danger',
|
||||
If(Eval('change_day1', 0) > 0, 'success', '')
|
||||
))
|
||||
),
|
||||
If(Eval('change_day1', 0) > 0, 'success', '')))),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
@ -224,7 +238,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
"""
|
||||
if self.updtsources:
|
||||
for usource in self.updtsources:
|
||||
if usource.fixed_url == True:
|
||||
if usource.fixed_url is True:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -234,7 +248,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
"""
|
||||
if len(self.updtsources) == 0:
|
||||
self.updttime = None
|
||||
else :
|
||||
else:
|
||||
self.updttime = time(11, 30)
|
||||
|
||||
@fields.depends('product', 'uom')
|
||||
|
@ -272,16 +286,21 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
(tab1, join1, col1) = Uom.symbol._get_translation_column(Uom, 'symbol')
|
||||
tab_symb = join1.select(tab1.id, col1.as_('symbol'))
|
||||
|
||||
query = tab_asset.join(tab_prod,
|
||||
condition=tab_asset.product==tab_prod.id,
|
||||
).join(tab_templ,
|
||||
condition=tab_templ.id==tab_prod.template,
|
||||
).join(tab_uom,
|
||||
condition=tab_templ.default_uom==tab_uom.id,
|
||||
).join(tab_cur,
|
||||
condition=tab_asset.currency==tab_cur.id,
|
||||
).join(tab_symb,
|
||||
condition=tab_asset.uom==tab_symb.id,
|
||||
query = tab_asset.join(
|
||||
tab_prod,
|
||||
condition=tab_asset.product == tab_prod.id,
|
||||
).join(
|
||||
tab_templ,
|
||||
condition=tab_templ.id == tab_prod.template,
|
||||
).join(
|
||||
tab_uom,
|
||||
condition=tab_templ.default_uom == tab_uom.id,
|
||||
).join(
|
||||
tab_cur,
|
||||
condition=tab_asset.currency == tab_cur.id,
|
||||
).join(
|
||||
tab_symb,
|
||||
condition=tab_asset.uom == tab_symb.id,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
tab_templ.name,
|
||||
|
@ -297,11 +316,11 @@ 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])
|
||||
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}
|
||||
result = {x: {y.id: None for y in assets} for x in names}
|
||||
|
||||
for record in records:
|
||||
values = {
|
||||
|
@ -321,8 +340,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
"""
|
||||
return ['OR',
|
||||
(('uom.rec_name',) + tuple(clause[1:])),
|
||||
(('currency.rec_name',) + tuple(clause[1:])),
|
||||
]
|
||||
(('currency.rec_name',) + tuple(clause[1:]))]
|
||||
|
||||
@classmethod
|
||||
def get_rate_data_sql(cls):
|
||||
|
@ -334,8 +352,9 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_asset = Asset.__table__()
|
||||
tab_rate = Rate.__table__()
|
||||
|
||||
query = tab_asset.join(tab_rate,
|
||||
condition=tab_asset.id==tab_rate.asset
|
||||
query = tab_asset.join(
|
||||
tab_rate,
|
||||
condition=tab_asset.id == tab_rate.asset
|
||||
).select(
|
||||
tab_asset.id,
|
||||
Round(tab_rate.rate, tab_asset.currency_digits).as_('rate'),
|
||||
|
@ -354,12 +373,12 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
|
||||
cursor = Transaction().connection.cursor()
|
||||
(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])
|
||||
|
||||
cursor.execute(*query)
|
||||
records = cursor.fetchall()
|
||||
|
||||
result = {x:{y.id: None for y in assets} for x in names}
|
||||
result = {x: {y.id: None for y in assets} for x in names}
|
||||
|
||||
for record in records:
|
||||
(id1, rate1, date1, id_rate) = record
|
||||
|
@ -413,7 +432,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
|
||||
query = tab_query.select(
|
||||
tab_query.date,
|
||||
where=tab_query.id==table.id,
|
||||
where=tab_query.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -426,7 +445,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
|
||||
query = tab_query.select(
|
||||
tab_query.rate,
|
||||
where=tab_query.id==table.id,
|
||||
where=tab_query.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -449,8 +468,9 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
if isinstance(asset_ids, list):
|
||||
where_asset &= tab_asset.id.in_(asset_ids)
|
||||
|
||||
tab_today = tab_asset.join(tab_rate1,
|
||||
condition=tab_asset.id==tab_rate1.asset,
|
||||
tab_today = tab_asset.join(
|
||||
tab_rate1,
|
||||
condition=tab_asset.id == tab_rate1.asset,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
tab_rate1.date,
|
||||
|
@ -461,16 +481,18 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
)
|
||||
|
||||
days_diff = days + 5
|
||||
query = tab_today.join(tab_rate2,
|
||||
condition=(tab_today.id==tab_rate2.asset) & \
|
||||
(tab_today.date > (tab_rate2.date + days)) & \
|
||||
(tab_today.date <= (tab_rate2.date + days_diff)),
|
||||
type_ = 'LEFT OUTER',
|
||||
query = tab_today.join(
|
||||
tab_rate2,
|
||||
condition=(tab_today.id == tab_rate2.asset) &
|
||||
(tab_today.date > (tab_rate2.date + days)) &
|
||||
(tab_today.date <= (tab_rate2.date + days_diff)),
|
||||
type_='LEFT OUTER',
|
||||
).select(
|
||||
tab_today.id,
|
||||
tab_today.date,
|
||||
tab_today.rate,
|
||||
(tab_today.rate * 100.0 / NullIf(tab_rate2.rate, 0.00) - 100.0).as_('percent'),
|
||||
(tab_today.rate * 100.0 / NullIf(tab_rate2.rate, 0.00) -
|
||||
100.0).as_('percent'),
|
||||
distinct_on=[tab_today.id],
|
||||
order_by=[tab_today.id, tab_rate2.date.desc]
|
||||
)
|
||||
|
@ -480,13 +502,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
def order_change_day1(tables):
|
||||
""" order day1
|
||||
"""
|
||||
Assert = Pool().get('investment.asset')
|
||||
tab_asset = Asset.get_percentage_sql(days=0)
|
||||
Asset2 = Pool().get('investment.asset')
|
||||
tab_asset = Asset2.get_percentage_sql(days=0)
|
||||
table, _ = tables[None]
|
||||
|
||||
query = tab_asset.select(
|
||||
tab_asset.percent,
|
||||
where=tab_asset.id==table.id,
|
||||
where=tab_asset.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -494,13 +516,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
def order_change_month1(tables):
|
||||
""" order month1
|
||||
"""
|
||||
Assert = Pool().get('investment.asset')
|
||||
tab_asset = Asset.get_percentage_sql(days=30)
|
||||
Asset2 = Pool().get('investment.asset')
|
||||
tab_asset = Asset2.get_percentage_sql(days=30)
|
||||
table, _ = tables[None]
|
||||
|
||||
query = tab_asset.select(
|
||||
tab_asset.percent,
|
||||
where=tab_asset.id==table.id,
|
||||
where=tab_asset.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -508,13 +530,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
def order_change_month3(tables):
|
||||
""" order month1
|
||||
"""
|
||||
Assert = Pool().get('investment.asset')
|
||||
tab_asset = Asset.get_percentage_sql(days=90)
|
||||
Asset2 = Pool().get('investment.asset')
|
||||
tab_asset = Asset2.get_percentage_sql(days=90)
|
||||
table, _ = tables[None]
|
||||
|
||||
query = tab_asset.select(
|
||||
tab_asset.percent,
|
||||
where=tab_asset.id==table.id,
|
||||
where=tab_asset.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -522,13 +544,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
def order_change_month6(tables):
|
||||
""" order month1
|
||||
"""
|
||||
Assert = Pool().get('investment.asset')
|
||||
tab_asset = Asset.get_percentage_sql(days=180)
|
||||
Asset2 = Pool().get('investment.asset')
|
||||
tab_asset = Asset2.get_percentage_sql(days=180)
|
||||
table, _ = tables[None]
|
||||
|
||||
query = tab_asset.select(
|
||||
tab_asset.percent,
|
||||
where=tab_asset.id==table.id,
|
||||
where=tab_asset.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -536,13 +558,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
def order_change_month12(tables):
|
||||
""" order month1
|
||||
"""
|
||||
Assert = Pool().get('investment.asset')
|
||||
tab_asset = Asset.get_percentage_sql(days=365)
|
||||
Asset2 = Pool().get('investment.asset')
|
||||
tab_asset = Asset2.get_percentage_sql(days=365)
|
||||
table, _ = tables[None]
|
||||
|
||||
query = tab_asset.select(
|
||||
tab_asset.percent,
|
||||
where=tab_asset.id==table.id,
|
||||
where=tab_asset.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -560,9 +582,9 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
'month12': 365,
|
||||
}[field_name])
|
||||
|
||||
query = tab_percent.select(tab_percent.id,
|
||||
where=Operator(Round(tab_percent.percent, 2),
|
||||
clause[2]))
|
||||
query = tab_percent.select(
|
||||
tab_percent.id,
|
||||
where=Operator(Round(tab_percent.percent, 2), clause[2]))
|
||||
return [('id', 'in', query)]
|
||||
|
||||
@classmethod
|
||||
|
@ -571,7 +593,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
"""
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
result = {x:{y.id: None for y in assets} for x in names}
|
||||
result = {x: {y.id: None for y in assets} for x in names}
|
||||
exp = Decimal(Decimal(1) / 10 ** digits_percent)
|
||||
asset_id_lst = [x.id for x in assets]
|
||||
|
||||
|
@ -610,30 +632,34 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
query_date = context.get('qdate', CurrentDate() - Literal(1))
|
||||
|
||||
# get last date of rate
|
||||
tab_date = tab_asset.join(tab_rel,
|
||||
tab_date = tab_asset.join(
|
||||
tab_rel,
|
||||
# link to asset-source-relation to check if
|
||||
# there are online-sources set
|
||||
condition=tab_rel.asset == tab_asset.id,
|
||||
).join(tab_rate,
|
||||
).join(
|
||||
tab_rate,
|
||||
condition=tab_asset.id == tab_rate.asset,
|
||||
type_ = 'LEFT OUTER',
|
||||
type_='LEFT OUTER',
|
||||
).select(
|
||||
tab_asset.id,
|
||||
(Coalesce(tab_rate.date, query_date) + Literal(1)).as_('date'),
|
||||
tab_asset.updtdays,
|
||||
tab_asset.updttime,
|
||||
distinct_on = [tab_asset.id],
|
||||
order_by = [tab_asset.id, tab_rate.date.desc],
|
||||
distinct_on=[tab_asset.id],
|
||||
order_by=[tab_asset.id, tab_rate.date.desc],
|
||||
)
|
||||
|
||||
query = tab_date.select(
|
||||
tab_date.id,
|
||||
(Case(
|
||||
((tab_date.updtdays == 'work') & \
|
||||
(Extract('dow', tab_date.date) == 0), tab_date.date + Literal(1)),
|
||||
((tab_date.updtdays == 'work') & \
|
||||
(Extract('dow', tab_date.date) == 6), tab_date.date + Literal(2)),
|
||||
else_ = tab_date.date,
|
||||
((tab_date.updtdays == 'work') &
|
||||
(Extract('dow', tab_date.date) == 0),
|
||||
tab_date.date + Literal(1)),
|
||||
((tab_date.updtdays == 'work') &
|
||||
(Extract('dow', tab_date.date) == 6),
|
||||
tab_date.date + Literal(2)),
|
||||
else_=tab_date.date,
|
||||
) + tab_date.updttime).as_('updttime'),
|
||||
)
|
||||
return query
|
||||
|
@ -654,7 +680,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
cursor.execute(*query)
|
||||
records = cursor.fetchall()
|
||||
|
||||
result = {x:{y.id: None for y in assets} for x in names}
|
||||
result = {x: {y.id: None for y in assets} for x in names}
|
||||
|
||||
for record in records:
|
||||
(id1, updt) = record
|
||||
|
@ -690,20 +716,24 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_secsymb = Identifier.__table__()
|
||||
tab_isin = Identifier.__table__()
|
||||
|
||||
query = tab_asset.join(tab_prod,
|
||||
condition=tab_asset.product==tab_prod.id,
|
||||
).join(tab_wkn,
|
||||
condition=(tab_prod.id==tab_wkn.product) & \
|
||||
(tab_wkn.type == 'wkn'),
|
||||
type_ = 'LEFT OUTER',
|
||||
).join(tab_secsymb,
|
||||
condition=(tab_prod.id==tab_secsymb.product) & \
|
||||
(tab_secsymb.type == 'secsymb'),
|
||||
type_ = 'LEFT OUTER',
|
||||
).join(tab_isin,
|
||||
condition=(tab_prod.id==tab_isin.product) & \
|
||||
(tab_isin.type == 'isin'),
|
||||
type_ = 'LEFT OUTER',
|
||||
query = tab_asset.join(
|
||||
tab_prod,
|
||||
condition=tab_asset.product == tab_prod.id,
|
||||
).join(
|
||||
tab_wkn,
|
||||
condition=(tab_prod.id == tab_wkn.product) &
|
||||
(tab_wkn.type == 'wkn'),
|
||||
type_='LEFT OUTER',
|
||||
).join(
|
||||
tab_secsymb,
|
||||
condition=(tab_prod.id == tab_secsymb.product) &
|
||||
(tab_secsymb.type == 'secsymb'),
|
||||
type_='LEFT OUTER',
|
||||
).join(
|
||||
tab_isin,
|
||||
condition=(tab_prod.id == tab_isin.product) &
|
||||
(tab_isin.type == 'isin'),
|
||||
type_='LEFT OUTER',
|
||||
).select(
|
||||
tab_asset.id,
|
||||
tab_wkn.code.as_('wkn'),
|
||||
|
@ -725,12 +755,15 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_prod = Product.__table__()
|
||||
tab_templ = Templ.__table__()
|
||||
|
||||
query = tab_asset.join(tab_prod,
|
||||
condition=tab_asset.product==tab_prod.id
|
||||
).join(tab_templ,
|
||||
condition=tab_templ.id==tab_prod.template
|
||||
).select(tab_templ.name,
|
||||
where=tab_asset.id==table.id
|
||||
query = tab_asset.join(
|
||||
tab_prod,
|
||||
condition=tab_asset.product == tab_prod.id
|
||||
).join(
|
||||
tab_templ,
|
||||
condition=tab_templ.id == tab_prod.template
|
||||
).select(
|
||||
tab_templ.name,
|
||||
where=tab_asset.id == table.id
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -744,7 +777,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
|
||||
query = tab_ids.select(
|
||||
getattr(tab_ids, 'wkn'),
|
||||
where=tab_ids.id==table.id,
|
||||
where=tab_ids.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -758,7 +791,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
|
||||
query = tab_ids.select(
|
||||
getattr(tab_ids, 'isin'),
|
||||
where=tab_ids.id==table.id,
|
||||
where=tab_ids.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -772,7 +805,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
|
||||
query = tab_ids.select(
|
||||
getattr(tab_ids, 'secsymb'),
|
||||
where=tab_ids.id==table.id,
|
||||
where=tab_ids.id == table.id,
|
||||
)
|
||||
return [query]
|
||||
|
||||
|
@ -787,12 +820,13 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_ids = cls.get_identifier_sql(tab_asset)
|
||||
|
||||
field_qu = getattr(tab_ids, names)
|
||||
query = tab_ids.join(tab_asset,
|
||||
condition=tab_ids.id==tab_asset.id,
|
||||
query = tab_ids.join(
|
||||
tab_asset,
|
||||
condition=tab_ids.id == tab_asset.id,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
where=Operator(field_qu, clause[2]) & \
|
||||
(field_qu != None),
|
||||
where=Operator(field_qu, clause[2]) &
|
||||
(field_qu != None),
|
||||
)
|
||||
|
||||
return [('id', 'in', query)]
|
||||
|
@ -806,7 +840,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_asset = Asset.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
result = {x:{y.id: None for y in assets} for x in names}
|
||||
result = {x: {y.id: None for y in assets} for x in names}
|
||||
|
||||
query = cls.get_identifier_sql(tab_asset)
|
||||
query.where = tab_asset.id.in_([x.id for x in assets])
|
||||
|
@ -829,17 +863,18 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
return '%(prod)s | %(rate)s %(unit)s | %(date)s' % {
|
||||
'prod': getattr(self.product, 'rec_name', '-'),
|
||||
'unit': self.symbol,
|
||||
'rate': Report.format_number(self.rate, lang=None,
|
||||
digits=self.currency_digits or 4) \
|
||||
if self.rate is not None else '-',
|
||||
'date': Report.format_date(self.date) if self.date is not None else '-',
|
||||
}
|
||||
'rate': Report.format_number(
|
||||
self.rate, lang=None, digits=self.currency_digits or 4)
|
||||
if self.rate is not None else '-',
|
||||
'date': Report.format_date(self.date)
|
||||
if self.date is not None else '-'}
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
""" search in rec_name
|
||||
"""
|
||||
return ['OR',
|
||||
return [
|
||||
'OR',
|
||||
('product.rec_name',) + tuple(clause[1:]),
|
||||
('product.identifiers.code',) + tuple(clause[1:]),
|
||||
]
|
||||
|
@ -862,8 +897,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
query_time = context.get('qdatetime', CurrentTimestamp())
|
||||
to_run_activities = []
|
||||
for asset in Asset2.search([
|
||||
('nextupdate', '<=', query_time),
|
||||
]):
|
||||
('nextupdate', '<=', query_time)]):
|
||||
if OnlineSource.update_rate(asset):
|
||||
to_run_activities.append(asset)
|
||||
|
||||
|
@ -877,10 +911,12 @@ class AssetSourceRel(ModelSQL):
|
|||
'Asset Source Relation'
|
||||
__name__ = 'investment.asset_source_rel'
|
||||
|
||||
source = fields.Many2One(string='Online Source', select=True,
|
||||
source = fields.Many2One(
|
||||
string='Online Source', select=True,
|
||||
required=True, model_name='investment.source',
|
||||
ondelete='CASCADE')
|
||||
asset = fields.Many2One(string='Asset', select=True,
|
||||
asset = fields.Many2One(
|
||||
string='Asset', select=True,
|
||||
required=True, model_name='investment.asset',
|
||||
ondelete='CASCADE')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue