66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# This file is part of the cashbook-module from m-ds.de 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, Pool
|
|
from trytond.model import fields
|
|
from trytond.pyson import Eval, Or
|
|
from .mixin import SecondUomMixin
|
|
|
|
|
|
STATES = {
|
|
'readonly': Or(
|
|
Eval('state', '') != 'edit',
|
|
Eval('state_cashbook', '') != 'open',
|
|
),
|
|
'required': Eval('feature', '') == 'asset',
|
|
'invisible': Eval('feature', '') != 'asset',
|
|
}
|
|
DEPENDS=['state', 'state_cashbook', 'feature']
|
|
|
|
|
|
class SplitLine(SecondUomMixin, metaclass=PoolMeta):
|
|
__name__ = 'cashbook.split'
|
|
|
|
quantity = fields.Numeric(string='Quantity',
|
|
digits=(16, Eval('quantity_digits', 4)),
|
|
states=STATES, depends=DEPENDS+['quantity_digits'])
|
|
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'),
|
|
'on_change_with_quantity_uom')
|
|
|
|
@fields.depends('line', '_parent_line.cashbook')
|
|
def on_change_with_quantity_uom(self, name=None):
|
|
""" get quantity-unit of asset
|
|
"""
|
|
if self.line:
|
|
if self.line.cashbook.quantity_uom:
|
|
return self.cashbook.quantity_uom.id
|
|
|
|
@fields.depends('line', '_parent_line.cashbook')
|
|
def on_change_with_quantity_digits(self, name=None):
|
|
""" get digits from cashbook
|
|
"""
|
|
if self.line:
|
|
return self.line.cashbook.quantity_digits
|
|
return 4
|
|
|
|
@classmethod
|
|
def add_2nd_unit_values(cls, values):
|
|
""" extend create-values
|
|
"""
|
|
Line2 = Pool().get('cashbook.line')
|
|
|
|
values = super(SplitLine, cls).add_2nd_unit_values(values)
|
|
line = Line2(values.get('line', None))
|
|
|
|
if line:
|
|
values.update(cls.add_2nd_quantity(values, line.cashbook.quantity_uom))
|
|
return values
|
|
|
|
# end SplitLine
|