2022-12-21 23:32:26 +00:00
|
|
|
# -*- 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 decimal import Decimal
|
|
|
|
from trytond.model import fields
|
|
|
|
from trytond.pool import PoolMeta
|
|
|
|
from trytond.pyson import Eval, Or, If
|
|
|
|
from trytond.modules.cashbook.line import STATES, DEPENDS
|
|
|
|
|
|
|
|
|
|
|
|
class Line(metaclass=PoolMeta):
|
|
|
|
__name__ = 'cashbook.line'
|
|
|
|
|
|
|
|
quantity = fields.Numeric(string='Quantity',
|
|
|
|
digits=(16, Eval('quantity_digits', 4)),
|
|
|
|
states={
|
|
|
|
'required': Eval('feature', '') == 'asset',
|
|
|
|
'invisible': Eval('feature', '') != 'asset',
|
|
|
|
'readonly': Or(
|
|
|
|
STATES['readonly'],
|
|
|
|
Eval('bookingtype', '').in_(['spin', 'spout']),
|
|
|
|
),
|
|
|
|
}, depends=DEPENDS+['feature', 'quantity_digits', 'bookingtype'])
|
|
|
|
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
|
|
|
readonly=True, states={'invisible': True}),
|
|
|
|
'on_change_with_quantity_digits')
|
|
|
|
quantity_uom = fields.Function(fields.Many2One(string='Symbol',
|
|
|
|
readonly=True, model_name='product.uom'),
|
2022-12-22 15:01:10 +00:00
|
|
|
'on_change_with_quantity_uom')
|
2022-12-21 23:32:26 +00:00
|
|
|
asset_rate = fields.Function(fields.Numeric(string='Rate',
|
|
|
|
readonly=True,
|
|
|
|
digits=(16, If(
|
|
|
|
Eval('currency_digits', 2) > Eval('quantity_digits', 2),
|
2022-12-22 15:01:10 +00:00
|
|
|
Eval('currency_digits', 2), Eval('quantity_digits', 2))),
|
|
|
|
depends=['currency_digits', 'quantity_digits']),
|
2022-12-21 23:32:26 +00:00
|
|
|
'on_change_with_asset_rate')
|
|
|
|
|
|
|
|
@fields.depends('quantity', 'amount', 'currency_digits', 'quantity_digits')
|
|
|
|
def on_change_with_asset_rate(self, name=None):
|
|
|
|
""" get rate
|
|
|
|
"""
|
|
|
|
if (self.quantity is None) or (self.amount is None):
|
|
|
|
return
|
|
|
|
digit = max(
|
|
|
|
self.currency_digits if self.currency_digits is not None else 2,
|
|
|
|
self.quantity_digits if self.quantity_digits is not None else 4)
|
|
|
|
if self.quantity != Decimal('0.0'):
|
|
|
|
return (
|
|
|
|
self.amount / self.quantity
|
|
|
|
).quantize(Decimal(str(1/10**digit)))
|
|
|
|
|
|
|
|
@fields.depends('cashbook', '_parent_cashbook.quantity_uom')
|
2022-12-22 15:01:10 +00:00
|
|
|
def on_change_with_quantity_uom(self, name=None):
|
|
|
|
""" get quantity-unit of asset
|
2022-12-21 23:32:26 +00:00
|
|
|
"""
|
|
|
|
if self.cashbook:
|
|
|
|
return self.cashbook.quantity_uom.id
|
|
|
|
|
|
|
|
@fields.depends('cashbook', '_parent_cashbook.quantity_digits')
|
|
|
|
def on_change_with_quantity_digits(self, name=None):
|
|
|
|
""" get digits from cashbook
|
|
|
|
"""
|
|
|
|
if self.cashbook:
|
|
|
|
return self.cashbook.quantity_digits
|
|
|
|
return 4
|
|
|
|
|
|
|
|
# end LineContext
|