diff --git a/__init__.py b/__init__.py
index 0c48da5..eda6b6d 100644
--- a/__init__.py
+++ b/__init__.py
@@ -7,10 +7,15 @@ from trytond.pool import Pool
from .asset import Asset
from .rate import Rate
from .identifier import Identifier
+from .cron import Cron
+from .onlinesource import OnlineSource
+
def register():
Pool.register(
+ OnlineSource,
Asset,
Rate,
Identifier,
+ Cron,
module='investment', type_='model')
diff --git a/asset.py b/asset.py
index 53cc0ce..1f10a45 100644
--- a/asset.py
+++ b/asset.py
@@ -6,7 +6,9 @@
from trytond.model import ModelView, ModelSQL, fields
from trytond.transaction import Transaction
from trytond.pool import Pool
-from trytond.pyson import Eval, Bool
+from trytond.pyson import Eval, Bool, And
+from decimal import Decimal
+from datetime import time
class Asset(ModelSQL, ModelView):
@@ -32,6 +34,9 @@ class Asset(ModelSQL, ModelView):
], depends=['product_uom', 'product'])
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']), 'on_change_with_rate')
company_currency = fields.Function(fields.Many2One(readonly=True,
string='Company Currency', states={'invisible': True},
@@ -56,6 +61,29 @@ class Asset(ModelSQL, ModelView):
help='Stock market symbol'),
'get_identifiers', searcher='search_identifier')
+ updtsource = fields.Many2One(string='Update Source',
+ help='Select a source for the course update.',
+ ondelete='SET NULL', model_name='investment.source')
+ updttime1 = fields.Time(string='Time 1',
+ states={
+ 'readonly': ~Bool(Eval('updtsource')),
+ }, depends=['updtsource'])
+ updttime2 = fields.Time(string='Time 2',
+ states={
+ 'readonly': ~And(
+ Bool(Eval('updtsource')),
+ Bool(Eval('updttime1')),
+ ),
+ }, depends=['updtsource', 'updttime1'])
+ updttime3 = fields.Time(string='Time 3',
+ states={
+ 'readonly': ~And(
+ Bool(Eval('updtsource')),
+ Bool(Eval('updttime1')),
+ Bool(Eval('updttime2')),
+ ),
+ }, depends=['updtsource', 'updttime1', 'updttime2'])
+
@classmethod
def default_currency(cls):
""" currency of company
@@ -78,6 +106,49 @@ class Asset(ModelSQL, ModelView):
"""
return 4
+ @fields.depends('updtsource', 'updttime1', 'updttime2', 'updttime3')
+ def on_change_updtsource(self):
+ """ clear time-fields
+ """
+ if self.updtsource is None:
+ self.updttime1 = None
+ self.updttime2 = None
+ self.updttime3 = None
+ else :
+ self.updttime1 = time(11, 30)
+
+ @fields.depends('updttime1', 'updttime2', 'updttime3')
+ def on_change_updttime1(self):
+ """ clear fiels
+ """
+ if self.updttime1 is None:
+ self.updttime2 = None
+ self.updttime3 = None
+
+ @fields.depends('updttime2', 'updttime3')
+ def on_change_updttime2(self):
+ """ clear fiels
+ """
+ if self.updttime2 is None:
+ self.updttime3 = None
+
+ @fields.depends('id', 'currency_digits')
+ def on_change_with_rate(self, name=None):
+ """ get current rate
+ """
+ pool = Pool()
+ Rate = pool.get('investment.rate')
+ IrDate = pool.get('ir.date')
+
+ if self.id:
+ rates = Rate.search([
+ ('date', '<=', IrDate.today()),
+ ('asset.id', '=', self.id),
+ ], order=[('date', 'DESC')], limit=1)
+ if len(rates) > 0:
+ exp = Decimal(Decimal(1) / 10 ** (self.currency_digits or 4))
+ return rates[0].rate.quantize(exp)
+
@fields.depends('product', 'uom')
def on_change_product(self):
""" update unit by product
@@ -213,4 +284,45 @@ class Asset(ModelSQL, ModelView):
"""
return [('product.rec_name',) + tuple(clause[1:])]
+ @classmethod
+ def cron_update(cls):
+ """ update asset-rates
+ """
+ pool = Pool()
+ Asset2 = pool.get('investment.asset')
+ IrDate = pool.get('ir.date')
+
+ assets = Asset2.search([
+ ('updtsource', '!=', None),
+ (),
+ ])
+ print('\n## assets:', assets)
+
+ @classmethod
+ def create(cls, vlist):
+ """ add debit/credit
+ """
+ vlist = [x.copy() for x in vlist]
+ for values in vlist:
+ if 'updtsource' in values.keys():
+ if values['updtsource'] is None:
+ values['updttime1'] = None
+ values['updttime2'] = None
+ values['updttime3'] = None
+ return super(Asset, cls).create(vlist)
+
+ @classmethod
+ def write(cls, *args):
+ """ deny update if cashbook.line!='open',
+ add or update debit/credit
+ """
+ actions = iter(args)
+ for lines, values in zip(actions, actions):
+ if 'updtsource' in values.keys():
+ if values['updtsource'] is None:
+ values['updttime1'] = None
+ values['updttime2'] = None
+ values['updttime3'] = None
+ super(Asset, cls).write(*args)
+
# end Asset
diff --git a/cron.py b/cron.py
new file mode 100644
index 0000000..4dffd61
--- /dev/null
+++ b/cron.py
@@ -0,0 +1,18 @@
+# -*- 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.pool import PoolMeta
+
+
+class Cron(metaclass=PoolMeta):
+ __name__ = 'ir.cron'
+
+ @classmethod
+ def __setup__(cls):
+ super(Cron, cls).__setup__()
+ cls.method.selection.append(
+ ('investment.asset|cron_update', "Update Asset Rates"))
+
+# end Cron
diff --git a/cron.xml b/cron.xml
new file mode 100644
index 0000000..5757c5a
--- /dev/null
+++ b/cron.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ investment.asset|cron_update
+
+ minutes
+
+
+
+
diff --git a/locale/de.po b/locale/de.po
index 12870d3..f8db2fd 100644
--- a/locale/de.po
+++ b/locale/de.po
@@ -15,6 +15,14 @@ msgid "Investment Administrator"
msgstr "Investition Administrator"
+###########
+# ir.cron #
+###########
+msgctxt "selection:ir.cron,method:"
+msgid "Update Asset Rates"
+msgstr "Vermögenswertkurse Aktualisieren"
+
+
##############
# ir.message #
##############
@@ -66,6 +74,14 @@ msgctxt "view:investment.asset:"
msgid "Rates"
msgstr "Kurse"
+msgctxt "view:investment.asset:"
+msgid "Course Update"
+msgstr "Kursaktualisierung"
+
+msgctxt "view:investment.asset:"
+msgid "You can have the course updated up to three times a day. The results are averaged."
+msgstr "Sie können den Kurs bis zu dreimal täglich aktualisieren lassen. Die Ergebnisse werden gemittelt."
+
msgctxt "field:investment.asset,company:"
msgid "Company"
msgstr "Unternehmen"
@@ -130,6 +146,30 @@ msgctxt "field:investment.asset,rates:"
msgid "Rates"
msgstr "Kurse"
+msgctxt "field:investment.asset,rate:"
+msgid "Current Rate"
+msgstr "aktueller Kurs"
+
+msgctxt "field:investment.asset,updtsource:"
+msgid "Update Source"
+msgstr "Kursquelle"
+
+msgctxt "help:investment.asset,updtsource:"
+msgid "Select a source for the course update."
+msgstr "Wählen Sie eine Quelle für die Kursaktualisierung aus."
+
+msgctxt "field:investment.asset,updttime1:"
+msgid "Time 1"
+msgstr "Zeitpunkt 1"
+
+msgctxt "field:investment.asset,updttime2:"
+msgid "Time 2"
+msgstr "Zeitpunkt 2"
+
+msgctxt "field:investment.asset,updttime3:"
+msgid "Time 3"
+msgstr "Zeitpunkt 3"
+
###################
# investment.rate #
diff --git a/locale/en.po b/locale/en.po
index 0625d2b..b687860 100644
--- a/locale/en.po
+++ b/locale/en.po
@@ -10,6 +10,10 @@ msgctxt "model:res.group,name:group_investment_admin"
msgid "Investment Administrator"
msgstr "Investment Administrator"
+msgctxt "selection:ir.cron,method:"
+msgid "Update Asset Rates"
+msgstr "Update Asset Rates"
+
msgctxt "model:ir.message,text:msg_currency_unique_rate_date"
msgid "A asset can only have one rate by date."
msgstr "A asset can only have one rate by date."
@@ -42,6 +46,18 @@ msgctxt "view:investment.asset:"
msgid "Identifiers"
msgstr "Identifiers"
+msgctxt "view:investment.asset:"
+msgid "Rates"
+msgstr "Rates"
+
+msgctxt "view:investment.asset:"
+msgid "Course Update"
+msgstr "Course Update"
+
+msgctxt "view:investment.asset:"
+msgid "You can have the course updated up to three times a day. The results are averaged."
+msgstr "You can have the course updated up to three times a day. The results are averaged."
+
msgctxt "field:investment.asset,company:"
msgid "Company"
msgstr "Company"
@@ -102,10 +118,42 @@ msgctxt "help:investment.asset,secsymb:"
msgid "Stock market symbol"
msgstr "Stock market symbol"
+msgctxt "field:investment.asset,rates:"
+msgid "Rates"
+msgstr "Rates"
+
+msgctxt "field:investment.asset,rate:"
+msgid "Current Rate"
+msgstr "Current Rate"
+
+msgctxt "field:investment.asset,updtsource:"
+msgid "Update Source"
+msgstr "Update Source"
+
+msgctxt "help:investment.asset,updtsource:"
+msgid "Select a source for the course update."
+msgstr "Select a source for the course update."
+
+msgctxt "field:investment.asset,updttime1:"
+msgid "Time 1"
+msgstr "Time 1"
+
+msgctxt "field:investment.asset,updttime2:"
+msgid "Time 2"
+msgstr "Time 2"
+
+msgctxt "field:investment.asset,updttime3:"
+msgid "Time 3"
+msgstr "Time 3"
+
msgctxt "model:investment.rate,name:"
msgid "Rate"
msgstr "Rate"
+msgctxt "view:investment.rate:"
+msgid "per"
+msgstr "per"
+
msgctxt "field:investment.rate,asset:"
msgid "Asset"
msgstr "Asset"
diff --git a/message.xml b/message.xml
index 7954767..a17315c 100644
--- a/message.xml
+++ b/message.xml
@@ -1,5 +1,5 @@
-
diff --git a/onlinesource.py b/onlinesource.py
new file mode 100644
index 0000000..562ca8f
--- /dev/null
+++ b/onlinesource.py
@@ -0,0 +1,17 @@
+# -*- 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.model import ModelView, ModelSQL, fields, Unique, Check
+from trytond.transaction import Transaction
+from trytond.pool import Pool
+
+
+class OnlineSource(ModelSQL, ModelView):
+ 'Online Source'
+ __name__ = 'investment.source'
+
+ name = fields.Char(string='Name')
+
+# end OnlineSource
diff --git a/tests/test_asset.py b/tests/test_asset.py
index 6ea561e..345bb1c 100644
--- a/tests/test_asset.py
+++ b/tests/test_asset.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# This file is part of the cashbook-module from m-ds for Tryton.
+# 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.
@@ -7,6 +7,7 @@ from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.modules.company.tests import create_company
from decimal import Decimal
+from datetime import time
class AssetTestCase(ModuleTestCase):
@@ -79,6 +80,43 @@ class AssetTestCase(ModuleTestCase):
company=company,
product = product)
+ @with_transaction()
+ def test_asset_check_onlinesource_onoff(self):
+ """ create asset, switch online-source on/off
+ """
+ pool = Pool()
+ OnlineSource = pool.get('investment.source')
+ Asset = pool.get('investment.asset')
+
+ company = self.prep_asset_company()
+ product = self.prep_asset_product(
+ name='Product 1',
+ description='some asset')
+
+ asset = self.prep_asset_item(
+ company=company,
+ product = product)
+
+ o_source, = OnlineSource.create([{
+ 'name': 'Source 1',
+ }])
+
+ self.assertEqual(asset.updtsource, None)
+ self.assertEqual(asset.updttime1, None)
+ self.assertEqual(asset.updttime2, None)
+ self.assertEqual(asset.updttime3, None)
+
+ asset.updtsource = o_source
+ asset.updttime1 = time(10, 45)
+ asset.save()
+ self.assertEqual(asset.updtsource.rec_name, 'Source 1')
+ self.assertEqual(asset.updttime1, time(10, 45))
+
+ asset.updtsource = None
+ asset.on_change_updtsource()
+ self.assertEqual(asset.updtsource, None)
+ self.assertEqual(asset.updttime1, None)
+
@with_transaction()
def test_asset_indentifiers(self):
""" create asset, add identifiers
diff --git a/tests/test_rate.py b/tests/test_rate.py
index 647f221..548b952 100644
--- a/tests/test_rate.py
+++ b/tests/test_rate.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# This file is part of the cashbook-module from m-ds for Tryton.
+# 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.
diff --git a/tryton.cfg b/tryton.cfg
index 06d33ec..eec3540 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -1,6 +1,7 @@
[tryton]
version=6.0.0
depends:
+ ir
res
company
currency
@@ -12,3 +13,4 @@ xml:
asset.xml
rate.xml
menu.xml
+ cron.xml
diff --git a/view/asset_form.xml b/view/asset_form.xml
index f3407bf..6b44cef 100644
--- a/view/asset_form.xml
+++ b/view/asset_form.xml
@@ -5,7 +5,8 @@ full copyright notices and license terms. -->
diff --git a/view/asset_list.xml b/view/asset_list.xml
index 23b5f74..4e756b0 100644
--- a/view/asset_list.xml
+++ b/view/asset_list.xml
@@ -7,6 +7,7 @@ full copyright notices and license terms. -->
+