asset: Felder wkn, isin, symobl + suche + test
This commit is contained in:
parent
13007f30c8
commit
353df93a9e
8 changed files with 267 additions and 3 deletions
93
asset.py
93
asset.py
|
@ -4,8 +4,6 @@
|
|||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, Bool
|
||||
|
@ -46,6 +44,16 @@ class Asset(ModelSQL, ModelView):
|
|||
currency_digits = fields.Integer(string='Currency Digits',
|
||||
required=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,
|
||||
help='International Securities Identification Number'),
|
||||
'get_identifiers', searcher='search_identifier')
|
||||
secsymb = fields.Function(fields.Char(string='Symbol', readonly=True,
|
||||
help='Stock market symbol'),
|
||||
'get_identifiers', searcher='search_identifier')
|
||||
|
||||
@classmethod
|
||||
def default_currency(cls):
|
||||
""" currency of company
|
||||
|
@ -84,6 +92,87 @@ class Asset(ModelSQL, ModelView):
|
|||
if self.currency:
|
||||
self.currency_digits = self.currency.digits
|
||||
|
||||
@classmethod
|
||||
def get_identifier_sql(cls, tab_asset):
|
||||
""" sql-query for identifiers
|
||||
"""
|
||||
pool = Pool()
|
||||
Product = pool.get('product.product')
|
||||
Identifier = pool.get('product.identifier')
|
||||
tab_prod = Product.__table__()
|
||||
tab_wkn = Identifier.__table__()
|
||||
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',
|
||||
).select(
|
||||
tab_asset.id,
|
||||
tab_wkn.code.as_('wkn'),
|
||||
tab_secsymb.code.as_('secsymb'),
|
||||
tab_isin.code.as_('isin'),
|
||||
)
|
||||
return query
|
||||
|
||||
@classmethod
|
||||
def search_identifier(cls, names, clause):
|
||||
""" search in identifier
|
||||
"""
|
||||
pool = Pool()
|
||||
Asset = pool.get('investment.asset')
|
||||
tab_asset = Asset.__table__()
|
||||
Operator = fields.SQL_OPERATORS[clause[1]]
|
||||
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,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
where=Operator(field_qu, clause[2]) & \
|
||||
(field_qu != None),
|
||||
)
|
||||
|
||||
return [('id', 'in', query)]
|
||||
|
||||
@classmethod
|
||||
def get_identifiers(cls, assets, names):
|
||||
""" get identifiers of assets
|
||||
"""
|
||||
pool = Pool()
|
||||
Asset = pool.get('investment.asset')
|
||||
tab_asset = Asset.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
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])
|
||||
|
||||
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]
|
||||
|
||||
return result
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_with_product_uom(self, name=None):
|
||||
""" get category of product-uom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue