formatting

This commit is contained in:
Frederik Jaeckel 2023-06-07 18:44:53 +02:00
parent 82f9d3a792
commit 8f12741d76
14 changed files with 411 additions and 344 deletions

View file

@ -32,4 +32,3 @@ def register():
UpdateSoureWizard,
ImportWizard,
module='investment', type_='wizard')

318
asset.py
View file

@ -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
@ -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)) & \
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',
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) & \
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) & \
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) & \
type_='LEFT OUTER',
).join(
tab_isin,
condition=(tab_prod.id == tab_isin.product) &
(tab_isin.type == 'isin'),
type_ = 'LEFT OUTER',
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,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,
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]) & \
where=Operator(field_qu, clause[2]) &
(field_qu != None),
)
@ -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) \
'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')

View file

@ -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()),
]

View file

@ -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()
@ -84,9 +87,9 @@ class ImportWizard(Wizard):
if self.start.file_ is not None:
(lines, max_date, min_date) = ImportWiz.read_csv_file(
self.start.file_.decode('utf8'),
dec_divider = self.start.dec_divider,
date_fmt = self.start.date_fmt,
delimiter = self.start.field_delimiter)
dec_divider=self.start.dec_divider,
date_fmt=self.start.date_fmt,
delimiter=self.start.field_delimiter)
if len(lines) > 0:
ImportWiz.upload_rates(
@ -140,8 +143,9 @@ class ImportWizard(Wizard):
max_rate = None
with StringIO(file_content) as fhdl:
csv_lines = csv.DictReader(fhdl,
fieldnames = ['date', 'rate'],
csv_lines = csv.DictReader(
fhdl,
fieldnames=['date', 'rate'],
dialect='excel',
delimiter=delimiter)
@ -150,23 +154,24 @@ class ImportWizard(Wizard):
if line.get('date', '') == 'date':
continue
try :
date_val = datetime.strptime(line.get('date', None).strip(), date_fmt).date()
except :
try:
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',
datefmt=date_fmt,
colnr='1',
))
try :
rate_val = line.get('rate', None).replace(del_chars[0], '').strip()
try:
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',
))
datefmt='dd%sdd' % dec_divider,
colnr='2'))
if isinstance(date_val, date) and isinstance(rate_val, Decimal):
result.append({'date': date_val, 'rate': rate_val})
@ -174,34 +179,32 @@ class ImportWizard(Wizard):
# date range
if max_date is None:
max_date = date_val
else :
else:
if max_date < date_val:
max_date = date_val
if min_date is None:
min_date = date_val
else :
else:
if min_date > date_val:
min_date = date_val
# rate range
if max_rate is None:
max_rate = rate_val
else :
else:
if max_rate < rate_val:
max_rate = rate_val
if min_rate is None:
min_rate = rate_val
else :
else:
if min_rate > rate_val:
min_rate = rate_val
else :
else:
raise UserError(gettext(
'investment.msg_err_unknown_content',
linetxt = line,
))
linetxt=line))
return (result, max_date, min_date)
# end ImportWizard

View file

@ -309,7 +309,7 @@ class OnlineSource(ModelSQL, ModelView):
oname=self.rec_name,
))
return url
else :
else:
if self.url:
return Template(self.url).substitute({
'isin': isin if isin is not None else '',

39
rate.py
View file

@ -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,8 +64,9 @@ class Rate(SymbolMixin, ModelSQL, ModelView):
tab_rate = cls.__table__()
cursor = Transaction().connection.cursor()
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_rate.id,
tab_asset.uom,
@ -74,7 +77,7 @@ class Rate(SymbolMixin, ModelSQL, ModelView):
cursor.execute(*query)
records = cursor.fetchall()
result = {x:{y.id: None for y in rates} for x in names}
result = {x: {y.id: None for y in rates} for x in names}
for record in records:
r1 = {
'symbol': '%',

View file

@ -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
@ -36,7 +36,7 @@ with open(path.join(here, 'versiondep.txt'), encoding='utf-8') as f:
l2 = i.strip().split(';')
if len(l2) < 4:
continue
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
major_version = 6
@ -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']))
else :
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' % (
prefix, dep, modversion[dep]['min'],
modversion[dep]['max']))
else:
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,
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']),
},

View file

@ -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

View file

@ -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
"""
@ -24,11 +23,13 @@ class AssetTestCase(ModuleTestCase):
company = Company.search([])
if len(company) > 0:
company = company[0]
else :
else:
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()
@ -85,7 +86,7 @@ class AssetTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
product=product)
self.assertEqual(asset.symbol, 'usd/u')
self.assertEqual(asset.asset_symbol.symbol, 'usd/u')
@ -95,7 +96,8 @@ class AssetTestCase(ModuleTestCase):
{
'currency_digits': 1,
}])
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'ss',
Asset.write,
*[[asset], {
@ -115,7 +117,7 @@ class AssetTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
product=product)
self.assertEqual(asset.rec_name, 'Product 1 | - usd/u | -')
@ -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()
@ -146,10 +150,10 @@ class AssetTestCase(ModuleTestCase):
asset1 = self.prep_asset_item(
company=company,
product = product1)
product=product1)
asset2 = self.prep_asset_item(
company=company,
product = product2)
product=product2)
Asset.write(*[
[asset1],
@ -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)
@ -221,7 +229,7 @@ class AssetTestCase(ModuleTestCase):
asset1 = self.prep_asset_item(
company=company,
product = product)
product=product)
self.assertEqual(asset1.rec_name, 'Product 1 | - usd/u | -')
Asset.write(*[
@ -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,13 +262,12 @@ 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,
tab_percent.percent,
where=tab_percent.id==asset1.id,
where=tab_percent.id == asset1.id,
)
cursor.execute(*query)
records = cursor.fetchall()
@ -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):
@ -284,10 +295,10 @@ class AssetTestCase(ModuleTestCase):
asset1 = self.prep_asset_item(
company=company,
product = product)
product=product)
asset2 = self.prep_asset_item(
company=company,
product = product)
product=product)
self.assertEqual(asset1.rec_name, 'Product 1 | - usd/u | -')
self.assertEqual(asset2.rec_name, 'Product 1 | - usd/u | -')
@ -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)
@ -390,7 +405,7 @@ class AssetTestCase(ModuleTestCase):
asset1 = self.prep_asset_item(
company=company,
product = product)
product=product)
self.assertEqual(asset1.rec_name, 'Product 1 | - usd/u | -')
@ -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(
@ -474,14 +490,14 @@ class AssetTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
product=product)
o_source, = OnlineSource.create([{
'name': 'Source 1',
}])
self.assertEqual(len(asset.updtsources), 0)
self.assertEqual(asset.updttime, time(14,0))
self.assertEqual(asset.updttime, time(14, 0))
asset.updtsources = [o_source]
asset.updttime = time(10, 45)
@ -511,7 +527,7 @@ class AssetTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
product=product)
o_source, = OnlineSource.create([{
'name': 'Source 1',
@ -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')

View file

@ -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
@ -27,7 +25,7 @@ class RateTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
product=product)
Asset.write(*[
[asset],

View file

@ -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
@ -59,7 +57,7 @@ class SourceTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
product=product)
Asset.write(*[
[asset],
@ -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
View 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

View file

@ -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

View file

@ -35,4 +35,3 @@ class UpdateSoureWizard(Wizard):
return 'end'
# UpdateSoureWizard