formatting
This commit is contained in:
parent
82f9d3a792
commit
8f12741d76
14 changed files with 411 additions and 344 deletions
|
@ -32,4 +32,3 @@ def register():
|
|||
UpdateSoureWizard,
|
||||
ImportWizard,
|
||||
module='investment', type_='wizard')
|
||||
|
||||
|
|
240
asset.py
240
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),
|
||||
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',
|
||||
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
|
||||
|
@ -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
|
||||
|
||||
|
@ -272,15 +286,20 @@ 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,
|
||||
query = tab_asset.join(
|
||||
tab_prod,
|
||||
condition=tab_asset.product == tab_prod.id,
|
||||
).join(tab_templ,
|
||||
).join(
|
||||
tab_templ,
|
||||
condition=tab_templ.id == tab_prod.template,
|
||||
).join(tab_uom,
|
||||
).join(
|
||||
tab_uom,
|
||||
condition=tab_templ.default_uom == tab_uom.id,
|
||||
).join(tab_cur,
|
||||
).join(
|
||||
tab_cur,
|
||||
condition=tab_asset.currency == tab_cur.id,
|
||||
).join(tab_symb,
|
||||
).join(
|
||||
tab_symb,
|
||||
condition=tab_asset.uom == tab_symb.id,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
|
@ -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,7 +352,8 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_asset = Asset.__table__()
|
||||
tab_rate = Rate.__table__()
|
||||
|
||||
query = tab_asset.join(tab_rate,
|
||||
query = tab_asset.join(
|
||||
tab_rate,
|
||||
condition=tab_asset.id == tab_rate.asset
|
||||
).select(
|
||||
tab_asset.id,
|
||||
|
@ -449,7 +468,8 @@ 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,
|
||||
tab_today = tab_asset.join(
|
||||
tab_rate1,
|
||||
condition=tab_asset.id == tab_rate1.asset,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
|
@ -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)) & \
|
||||
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,8 +502,8 @@ 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(
|
||||
|
@ -494,8 +516,8 @@ 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(
|
||||
|
@ -508,8 +530,8 @@ 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(
|
||||
|
@ -522,8 +544,8 @@ 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(
|
||||
|
@ -536,8 +558,8 @@ 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(
|
||||
|
@ -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
|
||||
|
@ -610,11 +632,13 @@ 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',
|
||||
).select(
|
||||
|
@ -629,10 +653,12 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
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)),
|
||||
((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'),
|
||||
)
|
||||
|
@ -690,18 +716,22 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_secsymb = Identifier.__table__()
|
||||
tab_isin = Identifier.__table__()
|
||||
|
||||
query = tab_asset.join(tab_prod,
|
||||
query = tab_asset.join(
|
||||
tab_prod,
|
||||
condition=tab_asset.product == tab_prod.id,
|
||||
).join(tab_wkn,
|
||||
condition=(tab_prod.id==tab_wkn.product) & \
|
||||
).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) & \
|
||||
).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) & \
|
||||
).join(
|
||||
tab_isin,
|
||||
condition=(tab_prod.id == tab_isin.product) &
|
||||
(tab_isin.type == 'isin'),
|
||||
type_='LEFT OUTER',
|
||||
).select(
|
||||
|
@ -725,11 +755,14 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_prod = Product.__table__()
|
||||
tab_templ = Templ.__table__()
|
||||
|
||||
query = tab_asset.join(tab_prod,
|
||||
query = tab_asset.join(
|
||||
tab_prod,
|
||||
condition=tab_asset.product == tab_prod.id
|
||||
).join(tab_templ,
|
||||
).join(
|
||||
tab_templ,
|
||||
condition=tab_templ.id == tab_prod.template
|
||||
).select(tab_templ.name,
|
||||
).select(
|
||||
tab_templ.name,
|
||||
where=tab_asset.id == table.id
|
||||
)
|
||||
return [query]
|
||||
|
@ -787,11 +820,12 @@ 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,
|
||||
query = tab_ids.join(
|
||||
tab_asset,
|
||||
condition=tab_ids.id == tab_asset.id,
|
||||
).select(
|
||||
tab_asset.id,
|
||||
where=Operator(field_qu, clause[2]) & \
|
||||
where=Operator(field_qu, clause[2]) &
|
||||
(field_qu != None),
|
||||
)
|
||||
|
||||
|
@ -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) \
|
||||
'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 '-',
|
||||
}
|
||||
'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')
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ class Concat2(Function):
|
|||
class GraphDef(metaclass=PoolMeta):
|
||||
__name__ = 'diagram.graphdef'
|
||||
|
||||
asset = fields.Many2One(string='Asset',
|
||||
model_name='investment.asset',
|
||||
asset = fields.Many2One(
|
||||
string='Asset', model_name='investment.asset',
|
||||
states={
|
||||
'invisible': Eval('dtype', '') != 'investment.asset',
|
||||
'required': Eval('dtype', '') == 'investment.asset',
|
||||
|
@ -70,7 +70,8 @@ class GraphDef(metaclass=PoolMeta):
|
|||
elif self.scaling == 'six':
|
||||
query = [
|
||||
('asset.id', '=', self.asset.id),
|
||||
('date', '>=', self.chart.used_start_date() - timedelta(days=180)),
|
||||
('date', '>=', self.chart.used_start_date() -
|
||||
timedelta(days=180)),
|
||||
('date', '<=', self.chart.used_end_date()),
|
||||
]
|
||||
|
||||
|
|
|
@ -36,15 +36,15 @@ class ImportWizardStart(ModelView):
|
|||
'Import CSV-File'
|
||||
__name__ = 'investment.imp_wiz.start'
|
||||
|
||||
asset = fields.Many2One(string='Asset', readonly=True,
|
||||
model_name='investment.asset')
|
||||
asset = fields.Many2One(
|
||||
string='Asset', readonly=True, model_name='investment.asset')
|
||||
file_ = fields.Binary(string="CSV-File", required=True)
|
||||
dec_divider = fields.Selection(string='Decimal divider',
|
||||
required=True, selection=sel_dec_divider)
|
||||
date_fmt = fields.Selection(string='Date format',
|
||||
required=True, selection=sel_date_fmt)
|
||||
field_delimiter = fields.Selection(string='Field delimiter',
|
||||
required=True, selection=sel_field_delimiter)
|
||||
dec_divider = fields.Selection(
|
||||
string='Decimal divider', required=True, selection=sel_dec_divider)
|
||||
date_fmt = fields.Selection(
|
||||
string='Date format', required=True, selection=sel_date_fmt)
|
||||
field_delimiter = fields.Selection(
|
||||
string='Field delimiter', required=True, selection=sel_field_delimiter)
|
||||
|
||||
# end ImportWizardStart
|
||||
|
||||
|
@ -54,11 +54,14 @@ class ImportWizard(Wizard):
|
|||
__name__ = 'investment.imp_wiz'
|
||||
|
||||
start_state = 'start'
|
||||
start = StateView(model_name='investment.imp_wiz.start', \
|
||||
view='investment.imp_wiz_start_form', \
|
||||
start = StateView(
|
||||
model_name='investment.imp_wiz.start',
|
||||
view='investment.imp_wiz_start_form',
|
||||
buttons=[
|
||||
Button(string='Cancel', state='end', icon='tryton-cancel'),
|
||||
Button(string='Import File', state='importf', icon='tryton-import', default=True),
|
||||
Button(
|
||||
string='Import File', state='importf',
|
||||
icon='tryton-import', default=True),
|
||||
])
|
||||
importf = StateTransition()
|
||||
|
||||
|
@ -140,7 +143,8 @@ class ImportWizard(Wizard):
|
|||
max_rate = None
|
||||
|
||||
with StringIO(file_content) as fhdl:
|
||||
csv_lines = csv.DictReader(fhdl,
|
||||
csv_lines = csv.DictReader(
|
||||
fhdl,
|
||||
fieldnames=['date', 'rate'],
|
||||
dialect='excel',
|
||||
delimiter=delimiter)
|
||||
|
@ -151,22 +155,23 @@ class ImportWizard(Wizard):
|
|||
continue
|
||||
|
||||
try:
|
||||
date_val = datetime.strptime(line.get('date', None).strip(), date_fmt).date()
|
||||
except :
|
||||
date_val = datetime.strptime(
|
||||
line.get('date', None).strip(), date_fmt).date()
|
||||
except Exception:
|
||||
raise UserError(gettext(
|
||||
'investment.msg_import_err_date',
|
||||
datefmt=date_fmt,
|
||||
colnr='1',
|
||||
))
|
||||
try:
|
||||
rate_val = line.get('rate', None).replace(del_chars[0], '').strip()
|
||||
rate_val = line.get('rate', None).replace(
|
||||
del_chars[0], '').strip()
|
||||
rate_val = Decimal(rate_val.replace(dec_divider, '.'))
|
||||
except :
|
||||
except Exception:
|
||||
raise UserError(gettext(
|
||||
'investment.msg_import_err_date',
|
||||
datefmt='dd%sdd' % dec_divider,
|
||||
colnr = '2',
|
||||
))
|
||||
colnr='2'))
|
||||
|
||||
if isinstance(date_val, date) and isinstance(rate_val, Decimal):
|
||||
result.append({'date': date_val, 'rate': rate_val})
|
||||
|
@ -199,9 +204,7 @@ class ImportWizard(Wizard):
|
|||
else:
|
||||
raise UserError(gettext(
|
||||
'investment.msg_err_unknown_content',
|
||||
linetxt = line,
|
||||
))
|
||||
linetxt=line))
|
||||
return (result, max_date, min_date)
|
||||
|
||||
# end ImportWizard
|
||||
|
||||
|
|
35
rate.py
35
rate.py
|
@ -3,33 +3,35 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.model import ModelView, ModelSQL, fields, Unique, Check, SymbolMixin
|
||||
from trytond.model import (
|
||||
ModelView, ModelSQL, fields, Unique, Check, SymbolMixin)
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.pyson import Eval
|
||||
|
||||
|
||||
class Rate(SymbolMixin, ModelSQL, ModelView):
|
||||
'Rate'
|
||||
__name__ = 'investment.rate'
|
||||
|
||||
asset = fields.Many2One(string='Asset', required=True,
|
||||
select=True, ondelete='CASCADE',
|
||||
asset = fields.Many2One(
|
||||
string='Asset', required=True, select=True, ondelete='CASCADE',
|
||||
model_name='investment.asset')
|
||||
date = fields.Date(string='Date', required=True, select=True)
|
||||
rate = fields.Numeric(string='Rate', required=True, select=True,
|
||||
digits=(16, Eval('asset_digits', 4)),
|
||||
depends=['asset_digits'])
|
||||
rate = fields.Numeric(
|
||||
string='Rate', required=True, select=True,
|
||||
digits=(16, Eval('asset_digits', 4)), depends=['asset_digits'])
|
||||
|
||||
asset_digits = fields.Function(fields.Integer(string='Digits',
|
||||
readonly=True), 'get_rate_data')
|
||||
currency = fields.Function(fields.Many2One(string='Currency',
|
||||
readonly=True, model_name='currency.currency'),
|
||||
asset_digits = fields.Function(fields.Integer(
|
||||
string='Digits', readonly=True), 'get_rate_data')
|
||||
currency = fields.Function(fields.Many2One(
|
||||
string='Currency', readonly=True, model_name='currency.currency'),
|
||||
'get_rate_data')
|
||||
uom = fields.Function(fields.Many2One(string='Uom',
|
||||
readonly=True, model_name='product.uom'), 'get_rate_data')
|
||||
symbol = fields.Function(fields.Char(string='Symbol',
|
||||
readonly=True), 'get_rate_data')
|
||||
uom = fields.Function(fields.Many2One(
|
||||
string='Uom', readonly=True, model_name='product.uom'),
|
||||
'get_rate_data')
|
||||
symbol = fields.Function(fields.Char(
|
||||
string='Symbol', readonly=True), 'get_rate_data')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -62,7 +64,8 @@ class Rate(SymbolMixin, ModelSQL, ModelView):
|
|||
tab_rate = cls.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
query = tab_asset.join(tab_rate,
|
||||
query = tab_asset.join(
|
||||
tab_rate,
|
||||
condition=tab_asset.id == tab_rate.asset,
|
||||
).select(
|
||||
tab_rate.id,
|
||||
|
|
26
setup.py
26
setup.py
|
@ -2,7 +2,7 @@
|
|||
"""
|
||||
|
||||
# Always prefer setuptools over distutils
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools import setup
|
||||
# To use a consistent encoding
|
||||
from codecs import open
|
||||
from os import path
|
||||
|
@ -51,19 +51,21 @@ for dep in info.get('depends', []):
|
|||
prefix = modversion[dep]['prefix']
|
||||
|
||||
if len(modversion[dep]['max']) > 0:
|
||||
requires.append('%s_%s >= %s, <= %s' %
|
||||
(prefix, dep, modversion[dep]['min'], modversion[dep]['max']))
|
||||
requires.append('%s_%s >= %s, <= %s' % (
|
||||
prefix, dep, modversion[dep]['min'],
|
||||
modversion[dep]['max']))
|
||||
else:
|
||||
requires.append('%s_%s >= %s' %
|
||||
(prefix, dep, modversion[dep]['min']))
|
||||
requires.append('%s_%s >= %s' % (
|
||||
prefix, dep, modversion[dep]['min']))
|
||||
else:
|
||||
requires.append('%s_%s >= %s.%s, < %s.%s' %
|
||||
('trytond', dep, major_version, minor_version,
|
||||
requires.append('%s_%s >= %s.%s, < %s.%s' % (
|
||||
'trytond', dep, major_version, minor_version,
|
||||
major_version, minor_version + 1))
|
||||
requires.append('trytond >= %s.%s, < %s.%s' %
|
||||
(major_version, minor_version, major_version, minor_version + 1))
|
||||
requires.append('trytond >= %s.%s, < %s.%s' % (
|
||||
major_version, minor_version, major_version, minor_version + 1))
|
||||
|
||||
setup(name='%s_%s' % (PREFIX, MODULE),
|
||||
setup(
|
||||
name='%s_%s' % (PREFIX, MODULE),
|
||||
version=info.get('version', '0.0.1'),
|
||||
description='Tryton module to add investment items.',
|
||||
long_description=long_description,
|
||||
|
@ -97,8 +99,8 @@ setup(name='%s_%s' % (PREFIX, MODULE),
|
|||
'trytond.modules.%s' % MODULE,
|
||||
],
|
||||
package_data={
|
||||
'trytond.modules.%s' % MODULE: (info.get('xml', [])
|
||||
+ ['tryton.cfg', 'locale/*.po', 'tests/*.py',
|
||||
'trytond.modules.%s' % MODULE: (info.get('xml', []) + [
|
||||
'tryton.cfg', 'locale/*.po', 'tests/*.py',
|
||||
'view/*.xml', 'icon/*.svg', 'scripts/*.py',
|
||||
'versiondep.txt', 'README.rst']),
|
||||
},
|
||||
|
|
|
@ -4,27 +4,14 @@
|
|||
import trytond.tests.test_tryton
|
||||
import unittest
|
||||
|
||||
from trytond.modules.investment.tests.test_asset import AssetTestCase
|
||||
from trytond.modules.investment.tests.test_rate import RateTestCase
|
||||
from trytond.modules.investment.tests.test_source import SourceTestCase
|
||||
from trytond.modules.investment.tests.test_wizard import WizardTestCase
|
||||
from .test_module import InvestmentTestCase
|
||||
|
||||
|
||||
__all__ = ['suite']
|
||||
|
||||
|
||||
class InvestmentTestCase(\
|
||||
WizardTestCase, \
|
||||
SourceTestCase, \
|
||||
RateTestCase,\
|
||||
AssetTestCase,\
|
||||
):
|
||||
'Test investment module'
|
||||
module = 'investment'
|
||||
|
||||
# end InvestmentTestCase
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(InvestmentTestCase))
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
InvestmentTestCase))
|
||||
return suite
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.modules.company.tests import create_company
|
||||
from trytond.transaction import Transaction
|
||||
|
@ -12,10 +12,9 @@ from decimal import Decimal
|
|||
from datetime import time, date, datetime
|
||||
|
||||
|
||||
class AssetTestCase(ModuleTestCase):
|
||||
'Test asset module'
|
||||
module = 'investment'
|
||||
|
||||
class AssetTestCase(object):
|
||||
""" test asset
|
||||
"""
|
||||
def prep_asset_company(self):
|
||||
""" get/create company
|
||||
"""
|
||||
|
@ -28,7 +27,9 @@ class AssetTestCase(ModuleTestCase):
|
|||
company = create_company(name='m-ds')
|
||||
return company
|
||||
|
||||
def prep_asset_product(self, name='Product 1', description=None, unit='u', unit_name='Units'):
|
||||
def prep_asset_product(
|
||||
self, name='Product 1', description=None, unit='u',
|
||||
unit_name='Units'):
|
||||
""" create product
|
||||
"""
|
||||
pool = Pool()
|
||||
|
@ -95,7 +96,8 @@ class AssetTestCase(ModuleTestCase):
|
|||
{
|
||||
'currency_digits': 1,
|
||||
}])
|
||||
self.assertRaisesRegex(UserError,
|
||||
self.assertRaisesRegex(
|
||||
UserError,
|
||||
'ss',
|
||||
Asset.write,
|
||||
*[[asset], {
|
||||
|
@ -127,7 +129,9 @@ class AssetTestCase(ModuleTestCase):
|
|||
'rate': Decimal('2.45'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(asset.rec_name, 'Product 1 | 2.4500 usd/u | 05/15/2022')
|
||||
self.assertEqual(
|
||||
asset.rec_name,
|
||||
'Product 1 | 2.4500 usd/u | 05/15/2022')
|
||||
self.assertEqual(Asset.search_count([('name', '=', 'Product 1')]), 1)
|
||||
|
||||
@with_transaction()
|
||||
|
@ -173,8 +177,12 @@ class AssetTestCase(ModuleTestCase):
|
|||
}])],
|
||||
},
|
||||
])
|
||||
self.assertEqual(asset1.rec_name, 'Product 1 | 3.5000 usd/u | 05/18/2022')
|
||||
self.assertEqual(asset2.rec_name, 'Product 2 | 2.6000 usd/u | 05/17/2022')
|
||||
self.assertEqual(
|
||||
asset1.rec_name,
|
||||
'Product 1 | 3.5000 usd/u | 05/18/2022')
|
||||
self.assertEqual(
|
||||
asset2.rec_name,
|
||||
'Product 2 | 2.6000 usd/u | 05/17/2022')
|
||||
|
||||
assets = Asset.search([], order=[('date', 'ASC')])
|
||||
self.assertEqual(len(assets), 2)
|
||||
|
@ -242,7 +250,9 @@ class AssetTestCase(ModuleTestCase):
|
|||
}])],
|
||||
},
|
||||
])
|
||||
self.assertEqual(asset1.rec_name, 'Product 1 | 2.6000 usd/u | 05/16/2022')
|
||||
self.assertEqual(
|
||||
asset1.rec_name,
|
||||
'Product 1 | 2.6000 usd/u | 05/16/2022')
|
||||
self.assertEqual(len(asset1.rates), 4)
|
||||
self.assertEqual(asset1.rates[0].date, date(2022, 5, 16))
|
||||
self.assertEqual(asset1.rates[1].date, date(2022, 5, 15))
|
||||
|
@ -252,8 +262,7 @@ class AssetTestCase(ModuleTestCase):
|
|||
# query fixed date
|
||||
tab_percent = Asset.get_percentage_sql(days=0)
|
||||
with Transaction().set_context({
|
||||
'qdate': date(2022, 5, 16),
|
||||
}):
|
||||
'qdate': date(2022, 5, 16)}):
|
||||
query = tab_percent.select(
|
||||
tab_percent.id,
|
||||
tab_percent.date,
|
||||
|
@ -268,7 +277,9 @@ class AssetTestCase(ModuleTestCase):
|
|||
self.assertEqual(len(records[0]), 3)
|
||||
self.assertEqual(records[0][0], asset1.id)
|
||||
self.assertEqual(records[0][1], date(2022, 5, 16))
|
||||
self.assertEqual(records[0][2].quantize(Decimal('0.01')), Decimal('6.12'))
|
||||
self.assertEqual(
|
||||
records[0][2].quantize(Decimal('0.01')),
|
||||
Decimal('6.12'))
|
||||
|
||||
@with_transaction()
|
||||
def test_asset_percentages_daterange(self):
|
||||
|
@ -314,8 +325,12 @@ class AssetTestCase(ModuleTestCase):
|
|||
}])],
|
||||
},
|
||||
])
|
||||
self.assertEqual(asset1.rec_name, 'Product 1 | 2.6000 usd/u | 05/16/2022')
|
||||
self.assertEqual(asset2.rec_name, 'Product 1 | 5.2500 usd/u | 05/15/2022')
|
||||
self.assertEqual(
|
||||
asset1.rec_name,
|
||||
'Product 1 | 2.6000 usd/u | 05/16/2022')
|
||||
self.assertEqual(
|
||||
asset2.rec_name,
|
||||
'Product 1 | 5.2500 usd/u | 05/15/2022')
|
||||
self.assertEqual(asset1.change_day1, Decimal('6.12'))
|
||||
self.assertEqual(asset2.change_day1, Decimal('-8.7'))
|
||||
self.assertEqual(asset1.change_month1, None)
|
||||
|
@ -411,7 +426,9 @@ class AssetTestCase(ModuleTestCase):
|
|||
'rate': Decimal('2.8'),
|
||||
},])],
|
||||
}])
|
||||
self.assertEqual(asset1.rec_name, 'Product 1 | 2.6000 usd/u | 05/16/2022')
|
||||
self.assertEqual(
|
||||
asset1.rec_name,
|
||||
'Product 1 | 2.6000 usd/u | 05/16/2022')
|
||||
self.assertEqual(len(asset1.rates), 4)
|
||||
self.assertEqual(asset1.rates[0].date, date(2022, 5, 16))
|
||||
self.assertEqual(asset1.rates[1].date, date(2022, 5, 15))
|
||||
|
@ -465,7 +482,6 @@ class AssetTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
OnlineSource = pool.get('investment.source')
|
||||
Asset = pool.get('investment.asset')
|
||||
|
||||
company = self.prep_asset_company()
|
||||
product = self.prep_asset_product(
|
||||
|
@ -524,8 +540,8 @@ class AssetTestCase(ModuleTestCase):
|
|||
}])
|
||||
|
||||
with Transaction().set_context({
|
||||
'qdate': date(2022, 10, 14), # friday
|
||||
}):
|
||||
|
||||
'qdate': date(2022, 10, 14)}):
|
||||
# re-read to make context work
|
||||
asset2, = Asset.browse([asset.id])
|
||||
|
||||
|
@ -539,10 +555,12 @@ class AssetTestCase(ModuleTestCase):
|
|||
self.assertEqual(asset2.nextupdate, datetime(2022, 10, 17, 10, 45))
|
||||
|
||||
self.assertEqual(
|
||||
Asset.search_count([('nextupdate', '<', datetime(2022, 10, 17, 10, 45))]),
|
||||
Asset.search_count([
|
||||
('nextupdate', '<', datetime(2022, 10, 17, 10, 45))]),
|
||||
0)
|
||||
self.assertEqual(
|
||||
Asset.search_count([('nextupdate', '>=', datetime(2022, 10, 17, 10, 45))]),
|
||||
Asset.search_count([
|
||||
('nextupdate', '>=', datetime(2022, 10, 17, 10, 45))]),
|
||||
1)
|
||||
|
||||
# add rate at next monday
|
||||
|
@ -564,10 +582,12 @@ class AssetTestCase(ModuleTestCase):
|
|||
self.assertEqual(asset.nextupdate, datetime(2022, 10, 18, 10, 45))
|
||||
|
||||
self.assertEqual(
|
||||
Asset.search_count([('nextupdate', '<', datetime(2022, 10, 18, 10, 45))]),
|
||||
Asset.search_count([
|
||||
('nextupdate', '<', datetime(2022, 10, 18, 10, 45))]),
|
||||
0)
|
||||
self.assertEqual(
|
||||
Asset.search_count([('nextupdate', '>=', datetime(2022, 10, 18, 10, 45))]),
|
||||
Asset.search_count([
|
||||
('nextupdate', '>=', datetime(2022, 10, 18, 10, 45))]),
|
||||
1)
|
||||
|
||||
# add rate at today
|
||||
|
@ -589,10 +609,12 @@ class AssetTestCase(ModuleTestCase):
|
|||
self.assertEqual(asset2.nextupdate, datetime(2022, 10, 19, 10, 45))
|
||||
|
||||
self.assertEqual(
|
||||
Asset.search_count([('nextupdate', '<', datetime(2022, 10, 19, 10, 45))]),
|
||||
Asset.search_count([
|
||||
('nextupdate', '<', datetime(2022, 10, 19, 10, 45))]),
|
||||
0)
|
||||
self.assertEqual(
|
||||
Asset.search_count([('nextupdate', '>=', datetime(2022, 10, 19, 10, 45))]),
|
||||
Asset.search_count([
|
||||
('nextupdate', '>=', datetime(2022, 10, 19, 10, 45))]),
|
||||
1)
|
||||
|
||||
@with_transaction()
|
||||
|
@ -609,12 +631,8 @@ class AssetTestCase(ModuleTestCase):
|
|||
product2 = self.prep_asset_product(
|
||||
name='Product gram', unit='g')
|
||||
|
||||
asset1 = self.prep_asset_item(
|
||||
company=company,
|
||||
product = product1)
|
||||
asset2 = self.prep_asset_item(
|
||||
company=company,
|
||||
product = product2)
|
||||
asset1 = self.prep_asset_item(company=company, product=product1)
|
||||
asset2 = self.prep_asset_item(company=company, product=product2)
|
||||
|
||||
Product.write(*[
|
||||
[product1],
|
||||
|
@ -653,9 +671,15 @@ class AssetTestCase(ModuleTestCase):
|
|||
self.assertEqual(Asset.search_count([('isin', '=', 'XC0009655157')]), 1)
|
||||
self.assertEqual(Asset.search_count([('secsymb', '=', '1472977')]), 1)
|
||||
|
||||
self.assertEqual(Asset.search_count([('rec_name', '=', '965515')]), 1)
|
||||
self.assertEqual(Asset.search_count([('rec_name', '=', 'XC0009655157')]), 1)
|
||||
self.assertEqual(Asset.search_count([('rec_name', '=', '1472977')]), 1)
|
||||
self.assertEqual(
|
||||
Asset.search_count([('rec_name', '=', '965515')]),
|
||||
1)
|
||||
self.assertEqual(
|
||||
Asset.search_count([('rec_name', '=', 'XC0009655157')]),
|
||||
1)
|
||||
self.assertEqual(
|
||||
Asset.search_count([('rec_name', '=', '1472977')]),
|
||||
1)
|
||||
|
||||
self.assertEqual(Asset.search_count([('name', '=', '965515')]), 1)
|
||||
self.assertEqual(Asset.search_count([('name', '=', 'XC0009655157')]), 1)
|
||||
|
@ -715,9 +739,7 @@ class AssetTestCase(ModuleTestCase):
|
|||
name='Product gram', unit='g')
|
||||
self.assertEqual(product2.default_uom.digits, 2)
|
||||
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = product1)
|
||||
asset = self.prep_asset_item(company=company, product=product1)
|
||||
|
||||
self.assertEqual(asset.product.rec_name, 'Product unit')
|
||||
self.assertEqual(asset.product.default_uom.rec_name, 'Unit')
|
|
@ -3,17 +3,15 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.modules.company.tests import create_company
|
||||
from decimal import Decimal
|
||||
from datetime import date
|
||||
|
||||
|
||||
class RateTestCase(ModuleTestCase):
|
||||
'Test rate module'
|
||||
module = 'investment'
|
||||
|
||||
class RateTestCase(object):
|
||||
""" test rate
|
||||
"""
|
||||
@with_transaction()
|
||||
def test_rate_create(self):
|
||||
""" create rate
|
|
@ -3,9 +3,8 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.modules.company.tests import create_company
|
||||
from trytond.transaction import Transaction
|
||||
from decimal import Decimal
|
||||
from datetime import time, date, datetime
|
||||
|
@ -14,10 +13,9 @@ from requests import Response
|
|||
import requests
|
||||
|
||||
|
||||
class SourceTestCase(ModuleTestCase):
|
||||
'Test online source module'
|
||||
module = 'investment'
|
||||
|
||||
class SourceTestCase(object):
|
||||
""" test online source
|
||||
"""
|
||||
@with_transaction()
|
||||
def test_waitlist_source_request(self):
|
||||
""" create source, call server
|
||||
|
@ -69,8 +67,7 @@ class SourceTestCase(ModuleTestCase):
|
|||
|
||||
with Transaction().set_context({
|
||||
'qdate': date(2022, 10, 1), # saturday
|
||||
'qdatetime': datetime(2022, 10, 2, 10, 0, 0),
|
||||
}):
|
||||
'qdatetime': datetime(2022, 10, 2, 10, 0, 0)}):
|
||||
asset2, = Asset.browse([asset])
|
||||
self.assertEqual(asset2.wkn, '965515')
|
||||
self.assertEqual(asset2.isin, 'XC0009655157')
|
||||
|
@ -82,7 +79,6 @@ class SourceTestCase(ModuleTestCase):
|
|||
self.assertEqual(asset2.nextupdate, datetime(2022, 10, 3, 14, 0))
|
||||
self.assertEqual(len(asset.rates), 0)
|
||||
|
||||
|
||||
# fake server-response
|
||||
resp1 = Response()
|
||||
resp1._content = """<html><body>Response from finance-server
|
26
tests/test_module.py
Normal file
26
tests/test_module.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the investment-module from m-ds for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from .asset import AssetTestCase
|
||||
from .rate import RateTestCase
|
||||
from .source import SourceTestCase
|
||||
from .wizard import WizardTestCase
|
||||
|
||||
|
||||
class InvestmentTestCase(
|
||||
WizardTestCase,
|
||||
SourceTestCase,
|
||||
RateTestCase,
|
||||
AssetTestCase,
|
||||
ModuleTestCase):
|
||||
'Test investment module'
|
||||
module = 'investment'
|
||||
|
||||
# end InvestmentTestCase
|
||||
|
||||
|
||||
del ModuleTestCase
|
|
@ -3,24 +3,21 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.modules.company.tests import create_company
|
||||
from trytond.transaction import Transaction
|
||||
from decimal import Decimal
|
||||
from datetime import date
|
||||
|
||||
|
||||
class WizardTestCase(ModuleTestCase):
|
||||
'Test wizard module'
|
||||
module = 'investment'
|
||||
|
||||
class WizardTestCase(object):
|
||||
""" test import wizard
|
||||
"""
|
||||
@with_transaction()
|
||||
def test_wiz_run_import(self):
|
||||
""" run import wizard
|
||||
"""
|
||||
pool = Pool()
|
||||
Asset = pool.get('investment.asset')
|
||||
ImportWiz = pool.get('investment.imp_wiz', type='wizard')
|
||||
|
||||
company = self.prep_asset_company()
|
||||
|
@ -28,15 +25,12 @@ class WizardTestCase(ModuleTestCase):
|
|||
name='Product 1',
|
||||
description='some asset')
|
||||
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = product)
|
||||
asset = self.prep_asset_item(company=company, product=product)
|
||||
self.assertEqual(len(asset.rates), 0)
|
||||
|
||||
with Transaction().set_context({
|
||||
'active_id': asset.id,
|
||||
'active_model': 'investment.asset',
|
||||
}):
|
||||
'active_model': 'investment.asset'}):
|
||||
(sess_id, start_state, end_state) = ImportWiz.create()
|
||||
w_obj = ImportWiz(sess_id)
|
||||
self.assertEqual(start_state, 'start')
|
||||
|
@ -61,7 +55,8 @@ class WizardTestCase(ModuleTestCase):
|
|||
'dec_divider': ',',
|
||||
'date_fmt': '%d.%m.%Y',
|
||||
'field_delimiter': ';',
|
||||
'file_': b'"date";"rate"\n"03.05.2022";"23,56"\n"05.05.2022";"24,22"\n"06.05.2022";"25,43"',
|
||||
'file_': b'"date";"rate"\n"03.05.2022";"23,56"\n' +
|
||||
b'"05.05.2022";"24,22"\n"06.05.2022";"25,43"',
|
||||
}}, 'importf')
|
||||
self.assertEqual(list(result.keys()), [])
|
||||
# finish wizard
|
|
@ -35,4 +35,3 @@ class UpdateSoureWizard(Wizard):
|
|||
return 'end'
|
||||
|
||||
# UpdateSoureWizard
|
||||
|
||||
|
|
Loading…
Reference in a new issue