rates: speichert kurse
This commit is contained in:
parent
353df93a9e
commit
42ede3decb
15 changed files with 335 additions and 12 deletions
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
|
Loading…
Add table
Add a link
Reference in a new issue