69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
![]() |
# -*- 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
|
||
|
from trytond.exceptions import UserError
|
||
|
from trytond.i18n import gettext
|
||
|
from trytond.transaction import Transaction
|
||
|
from trytond.pool import Pool
|
||
|
|
||
|
|
||
|
class Asset(ModelSQL, ModelView):
|
||
|
'Asset'
|
||
|
__name__ = 'investment.asset'
|
||
|
|
||
|
company = fields.Many2One(string='Company', model_name='company.company',
|
||
|
required=True, ondelete="RESTRICT")
|
||
|
|
||
|
company_currency = fields.Function(fields.Many2One(readonly=True,
|
||
|
string='Company Currency', states={'invisible': True},
|
||
|
model_name='currency.currency'),
|
||
|
'on_change_with_company_currency')
|
||
|
company_currency_digits = fields.Function(fields.Integer(
|
||
|
string='Currency Digits (Ref.)', readonly=True),
|
||
|
'on_change_with_currency_digits')
|
||
|
|
||
|
currency = fields.Many2One(string='Currency', select=True,
|
||
|
required=True, model_name='currency.currency', ondelete='RESTRICT')
|
||
|
currency_digits = fields.Integer(string='Currency Digits',
|
||
|
required=True)
|
||
|
|
||
|
@classmethod
|
||
|
def default_currency(cls):
|
||
|
""" currency of company
|
||
|
"""
|
||
|
Company = Pool().get('company.company')
|
||
|
|
||
|
company = cls.default_company()
|
||
|
if company:
|
||
|
company = Company(company)
|
||
|
if company.currency:
|
||
|
return company.currency.id
|
||
|
|
||
|
@staticmethod
|
||
|
def default_company():
|
||
|
return Transaction().context.get('company') or None
|
||
|
|
||
|
@fields.depends('currency')
|
||
|
def on_change_with_currency_digits(self, name=None):
|
||
|
""" currency of cashbook
|
||
|
"""
|
||
|
if self.currency:
|
||
|
return self.currency.digits
|
||
|
else:
|
||
|
return 2
|
||
|
|
||
|
@fields.depends('company', 'currency')
|
||
|
def on_change_with_company_currency(self, name=None):
|
||
|
""" get company-currency if its different from current
|
||
|
asset-currency
|
||
|
"""
|
||
|
if self.company:
|
||
|
if self.currency:
|
||
|
if self.company.currency.id != self.currency.id:
|
||
|
return self.company.currency.id
|
||
|
|
||
|
# end Asset
|