line: quantity_credit/debit + test

book: berechnet 'quantity' aus quantity_credit/debit
This commit is contained in:
Frederik Jaeckel 2022-12-30 23:55:00 +01:00
parent e0895f3e4c
commit e94a869166
6 changed files with 210 additions and 133 deletions

69
line.py
View file

@ -9,27 +9,37 @@ from trytond.pool import PoolMeta
from trytond.pyson import Eval, Or, If
from trytond.modules.cashbook.line import STATES, DEPENDS
STATESQ = {
'required': Or(
Eval('feature', '') == 'asset',
Eval('booktransf_feature', '') == 'asset',
),
'invisible': ~Or(
Eval('feature', '') == 'asset',
Eval('booktransf_feature', '') == 'asset',
),
'readonly': Or(
STATES['readonly'],
Eval('bookingtype', '').in_(['spin', 'spout']),
),
}
DEPENDSQ = DEPENDS+['feature', 'booktransf_feature',
'quantity_digits', 'bookingtype']
class Line(metaclass=PoolMeta):
__name__ = 'cashbook.line'
quantity = fields.Numeric(string='Quantity',
digits=(16, Eval('quantity_digits', 4)),
states={
'required': Or(
Eval('feature', '') == 'asset',
Eval('booktransf_feature', '') == 'asset',
),
'invisible': ~Or(
Eval('feature', '') == 'asset',
Eval('booktransf_feature', '') == 'asset',
),
'readonly': Or(
STATES['readonly'],
Eval('bookingtype', '').in_(['spin', 'spout']),
),
}, depends=DEPENDS+['feature', 'booktransf_feature',
'quantity_digits', 'bookingtype'])
states=STATESQ, depends=DEPENDSQ)
quantity_credit = fields.Numeric(string='Quantity Credit',
digits=(16, Eval('quantity_digits', 4)),
states=STATESQ, depends=DEPENDSQ)
quantity_debit = fields.Numeric(string='Quantity Debit',
digits=(16, Eval('quantity_digits', 4)),
states=STATESQ, depends=DEPENDSQ)
quantity_digits = fields.Function(fields.Integer(string='Digits',
readonly=True, states={'invisible': True}),
'on_change_with_quantity_digits')
@ -46,6 +56,35 @@ class Line(metaclass=PoolMeta):
}, depends=['currency_digits', 'quantity_digits', 'feature']),
'on_change_with_asset_rate')
@classmethod
def get_debit_credit(cls, values):
""" compute quantity_debit/quantity_credit from quantity
"""
values2 = super(Line, cls).get_debit_credit(values)
if isinstance(values, dict):
type_ = values.get('bookingtype', None)
quantity = values.get('quantity', None)
else :
type_ = getattr(values, 'bookingtype', None)
quantity = getattr(values, 'quantity', None)
if type_:
if quantity is not None:
if type_ in ['in', 'mvin', 'spin']:
values2.update({
'quantity_debit': Decimal('0.0'),
'quantity_credit': quantity,
})
elif type_ in ['out', 'mvout', 'spout']:
values2.update({
'quantity_debit': quantity,
'quantity_credit': Decimal('0.0'),
})
else :
raise ValueError('invalid "bookingtype"')
return values2
@classmethod
def get_counterpart_values(cls, line, values={}):
""" add quantity to counterpart