rates: speichert kurse
This commit is contained in:
parent
353df93a9e
commit
42ede3decb
15 changed files with 335 additions and 12 deletions
|
@ -5,10 +5,12 @@
|
|||
|
||||
from trytond.pool import Pool
|
||||
from .asset import Asset
|
||||
from .rate import Rate
|
||||
from .identifier import Identifier
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
Asset,
|
||||
Rate,
|
||||
Identifier,
|
||||
module='investment', type_='model')
|
||||
|
|
6
asset.py
6
asset.py
|
@ -30,6 +30,8 @@ class Asset(ModelSQL, ModelView):
|
|||
domain=[
|
||||
('category', '=', Eval('product_uom')),
|
||||
], depends=['product_uom', 'product'])
|
||||
rates = fields.One2Many(string='Rates', field='asset',
|
||||
model_name='investment.rate')
|
||||
|
||||
company_currency = fields.Function(fields.Many2One(readonly=True,
|
||||
string='Company Currency', states={'invisible': True},
|
||||
|
@ -72,9 +74,9 @@ class Asset(ModelSQL, ModelView):
|
|||
|
||||
@classmethod
|
||||
def default_currency_digits(cls):
|
||||
""" default: 2
|
||||
""" default: 4
|
||||
"""
|
||||
return 2
|
||||
return 4
|
||||
|
||||
@fields.depends('product', 'uom')
|
||||
def on_change_product(self):
|
||||
|
|
48
locale/de.po
48
locale/de.po
|
@ -15,6 +15,18 @@ msgid "Investment Administrator"
|
|||
msgstr "Investition Administrator"
|
||||
|
||||
|
||||
##############
|
||||
# ir.message #
|
||||
##############
|
||||
msgctxt "model:ir.message,text:msg_currency_unique_rate_date"
|
||||
msgid "A asset can only have one rate by date."
|
||||
msgstr "Es darf nur einen Kurs pro Datum für einen Vermögenswert geben."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_currency_rate_positive"
|
||||
msgid "A asset rate must be positive."
|
||||
msgstr "Der Kurs des Vermögenswertes muss positiv sein."
|
||||
|
||||
|
||||
##############
|
||||
# ir.ui.menu #
|
||||
##############
|
||||
|
@ -50,6 +62,10 @@ msgctxt "view:investment.asset:"
|
|||
msgid "Identifiers"
|
||||
msgstr "Bezeichner"
|
||||
|
||||
msgctxt "view:investment.asset:"
|
||||
msgid "Rates"
|
||||
msgstr "Kurse"
|
||||
|
||||
msgctxt "field:investment.asset,company:"
|
||||
msgid "Company"
|
||||
msgstr "Unternehmen"
|
||||
|
@ -110,6 +126,38 @@ msgctxt "help:investment.asset,secsymb:"
|
|||
msgid "Stock market symbol"
|
||||
msgstr "Börsensymbol"
|
||||
|
||||
msgctxt "field:investment.asset,rates:"
|
||||
msgid "Rates"
|
||||
msgstr "Kurse"
|
||||
|
||||
|
||||
###################
|
||||
# investment.rate #
|
||||
###################
|
||||
msgctxt "model:investment.rate,name:"
|
||||
msgid "Rate"
|
||||
msgstr "Kurs"
|
||||
|
||||
msgctxt "view:investment.rate:"
|
||||
msgid "per"
|
||||
msgstr "pro"
|
||||
|
||||
msgctxt "field:investment.rate,asset:"
|
||||
msgid "Asset"
|
||||
msgstr "Vermögenswert"
|
||||
|
||||
msgctxt "field:investment.rate,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
|
||||
msgctxt "field:investment.rate,rate:"
|
||||
msgid "Rate"
|
||||
msgstr "Kurs"
|
||||
|
||||
msgctxt "field:investment.rate,digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Nachkommastellen"
|
||||
|
||||
|
||||
######################
|
||||
# product.identifier #
|
||||
|
|
28
locale/en.po
28
locale/en.po
|
@ -10,6 +10,14 @@ msgctxt "model:res.group,name:group_investment_admin"
|
|||
msgid "Investment Administrator"
|
||||
msgstr "Investment Administrator"
|
||||
|
||||
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."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_currency_rate_positive"
|
||||
msgid "A asset rate must be positive."
|
||||
msgstr "A asset rate must be positive."
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_investment"
|
||||
msgid "Investment"
|
||||
msgstr "Investment"
|
||||
|
@ -94,6 +102,26 @@ msgctxt "help:investment.asset,secsymb:"
|
|||
msgid "Stock market symbol"
|
||||
msgstr "Stock market symbol"
|
||||
|
||||
msgctxt "model:investment.rate,name:"
|
||||
msgid "Rate"
|
||||
msgstr "Rate"
|
||||
|
||||
msgctxt "field:investment.rate,asset:"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "field:investment.rate,date:"
|
||||
msgid "Date"
|
||||
msgstr "Date"
|
||||
|
||||
msgctxt "field:investment.rate,rate:"
|
||||
msgid "Rate"
|
||||
msgstr "Rate"
|
||||
|
||||
msgctxt "field:investment.rate,digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Digits"
|
||||
|
||||
msgctxt "selection:product.identifier,type:"
|
||||
msgid "National Securities Identifying Number (NSIN)"
|
||||
msgstr "National Securities Identifying Number (NSIN)"
|
||||
|
|
16
message.xml
Normal file
16
message.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of the cashbook-module from m-ds for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the
|
||||
full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<record model="ir.message" id="msg_unique_rate_date">
|
||||
<field name="text">A asset can only have one rate by date.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_rate_positive">
|
||||
<field name="text">A asset rate must be positive.</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
76
rate.py
Normal file
76
rate.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
# -*- 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
|
||||
from trytond.pyson import Eval, Bool
|
||||
|
||||
|
||||
class Rate(ModelSQL, ModelView):
|
||||
'Rate'
|
||||
__name__ = 'investment.rate'
|
||||
|
||||
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,
|
||||
digits=(16, Eval('asset_digits', 4)),
|
||||
depends=['asset_digits'])
|
||||
|
||||
asset_digits = fields.Function(fields.Integer(string='Digits',
|
||||
readonly=True), 'on_change_with_asset_digits')
|
||||
currency = fields.Function(fields.Many2One(string='Currency',
|
||||
readonly=True, model_name='currency.currency'),
|
||||
'on_change_with_currency')
|
||||
uom = fields.Function(fields.Many2One(string='Uom',
|
||||
readonly=True, model_name='product.uom'),
|
||||
'on_change_with_uom')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Rate, cls).__setup__()
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints = [
|
||||
('date_asset_uniq',
|
||||
Unique(t, t.date, t.asset),
|
||||
'investment.msg_unique_rate_date'),
|
||||
('check_rate',
|
||||
Check(t, t.rate >= 0),
|
||||
'currency.msg_rate_positive'),
|
||||
]
|
||||
cls._order.insert(0, ('date', 'DESC'))
|
||||
|
||||
@classmethod
|
||||
def default_date(cls):
|
||||
""" today
|
||||
"""
|
||||
IrDate = Pool().get('ir.date')
|
||||
return IrDate.today()
|
||||
|
||||
@fields.depends('asset', '_parent_asset.uom')
|
||||
def on_change_with_uom(self, name=None):
|
||||
""" get unit of asset
|
||||
"""
|
||||
if self.asset:
|
||||
return self.asset.uom.id
|
||||
|
||||
@fields.depends('asset', '_parent_asset.currency')
|
||||
def on_change_with_currency(self, name=None):
|
||||
""" get currency
|
||||
"""
|
||||
if self.asset:
|
||||
return self.asset.currency.id
|
||||
|
||||
@fields.depends('asset', '_parent_asset.currency_digits')
|
||||
def on_change_with_asset_digits(self, name=None):
|
||||
""" get digits for asset
|
||||
"""
|
||||
if self.asset:
|
||||
return self.asset.currency_digits
|
||||
return 4
|
||||
|
||||
# Rate
|
57
rate.xml
Normal file
57
rate.xml
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- 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. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<!-- views -->
|
||||
<record model="ir.ui.view" id="rate_view_graph">
|
||||
<field name="model">investment.rate</field>
|
||||
<field name="type">graph</field>
|
||||
<field name="priority" eval="10"/>
|
||||
<field name="name">rate_graph</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="rate_view_list">
|
||||
<field name="model">investment.rate</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="20"/>
|
||||
<field name="name">rate_list</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="rate_view_form">
|
||||
<field name="model">investment.rate</field>
|
||||
<field name="type">form</field>
|
||||
<field name="priority" eval="30"/>
|
||||
<field name="name">rate_form</field>
|
||||
</record>
|
||||
|
||||
<!-- permission -->
|
||||
<!-- anon: deny all -->
|
||||
<record model="ir.model.access" id="access_rate-anon">
|
||||
<field name="model" search="[('model', '=', 'investment.rate')]"/>
|
||||
<field name="perm_read" eval="False"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<!-- group_investment: read -->
|
||||
<record model="ir.model.access" id="access_rate-group_investment">
|
||||
<field name="model" search="[('model', '=', 'investment.rate')]"/>
|
||||
<field name="group" ref="group_investment"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<!-- group_investment_admin: read/write -->
|
||||
<record model="ir.model.access" id="access_rate-group_investment_admin">
|
||||
<field name="model" search="[('model', '=', 'investment.rate')]"/>
|
||||
<field name="group" ref="group_investment_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
|
@ -5,12 +5,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
|
||||
|
||||
|
||||
__all__ = ['suite']
|
||||
|
||||
|
||||
class InvestmentTestCase(\
|
||||
RateTestCase,\
|
||||
AssetTestCase,\
|
||||
):
|
||||
'Test investment module'
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.company.tests import create_company
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
|
|
50
tests/test_rate.py
Normal file
50
tests/test_rate.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the cashbook-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, 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'
|
||||
|
||||
@with_transaction()
|
||||
def test_rate_create(self):
|
||||
""" create rate
|
||||
"""
|
||||
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)
|
||||
|
||||
Asset.write(*[
|
||||
[asset],
|
||||
{
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('2.5'),
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'rate': Decimal('2.8'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(len(asset.rates), 2)
|
||||
self.assertEqual(asset.rates[0].date, date(2022, 5, 2))
|
||||
self.assertEqual(asset.rates[0].rate, Decimal('2.8'))
|
||||
self.assertEqual(asset.rates[0].uom.rec_name, 'Unit')
|
||||
self.assertEqual(asset.rates[0].asset_digits, 4)
|
||||
self.assertEqual(asset.rates[0].currency.rec_name, 'usd')
|
||||
|
||||
# end RateTestCase
|
|
@ -7,6 +7,8 @@ depends:
|
|||
product
|
||||
xml:
|
||||
icon.xml
|
||||
message.xml
|
||||
group.xml
|
||||
asset.xml
|
||||
rate.xml
|
||||
menu.xml
|
||||
|
|
|
@ -18,7 +18,8 @@ full copyright notices and license terms. -->
|
|||
<label name="product_uom" />
|
||||
<field name="product_uom" />
|
||||
|
||||
<separator id="sepids" colspan="4" string="Identifiers"/>
|
||||
<notebook>
|
||||
<page id="pgids" col="4" string="Identifiers">
|
||||
<label name="wkn" />
|
||||
<field name="wkn" />
|
||||
<label name="secsymb" />
|
||||
|
@ -26,6 +27,10 @@ full copyright notices and license terms. -->
|
|||
|
||||
<label name="isin" />
|
||||
<field name="isin" />
|
||||
<newline/>
|
||||
</page>
|
||||
<page name="rates" col="1" string="Rates">
|
||||
<field name="rates" mode="tree,form,graph"/>
|
||||
</page>
|
||||
</notebook>
|
||||
|
||||
</form>
|
||||
|
|
17
view/rate_form.xml
Normal file
17
view/rate_form.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- 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. -->
|
||||
<form col="4">
|
||||
<label name="asset" />
|
||||
<field name="asset" colspan="3"/>
|
||||
|
||||
<label name="date" />
|
||||
<field name="date" />
|
||||
<label name="rate" />
|
||||
<field name="rate" symbol="currency"/>
|
||||
|
||||
<label colspan="3" id="lab1" string="per"/>
|
||||
<field name="uom"/>
|
||||
|
||||
</form>
|
12
view/rate_graph.xml
Normal file
12
view/rate_graph.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of the cashbook-module from m-ds for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the
|
||||
full copyright notices and license terms. -->
|
||||
<graph type="line" legend="1" background="#ffffc0">
|
||||
<x>
|
||||
<field name="date"/>
|
||||
</x>
|
||||
<y>
|
||||
<field name="rate" fill="0" empty="0"/>
|
||||
</y>
|
||||
</graph>
|
8
view/rate_list.xml
Normal file
8
view/rate_list.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- 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. -->
|
||||
<tree>
|
||||
<field name="date"/>
|
||||
<field name="rate" symbol="currency"/>
|
||||
</tree>
|
Loading…
Reference in a new issue