line: field 'asset_gainloss' ok + test

This commit is contained in:
Frederik Jaeckel 2023-02-18 20:55:04 +01:00
parent 6ab88d9fb5
commit 4e118afffb
2 changed files with 294 additions and 60 deletions

24
line.py
View file

@ -139,6 +139,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
SplitLine = pool.get('cashbook.split')
tab_line = cls.__table__()
tab_mvsp_counterpart = cls.__table__()
tab_mvsp_local = cls.__table__()
tab_mvmv_counterpart = cls.__table__()
tab_spmv_counterpart = cls.__table__()
tab_mv_spline = SplitLine.__table__()
@ -186,15 +187,19 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
type_ = 'LEFT OUTER',
).select(
tab_line.id,
Coalesce(
(Coalesce(
tab_mvmv_counterpart.credit - tab_mvmv_counterpart.debit,
Case(
(tab_line.bookingtype == 'mvin', tab_mv_spline.amount),
(tab_line.bookingtype == 'mvout', tab_mv_spline.amount * Decimal('-1.0')),
),
Case(
(tab_mvsp_counterpart.cashbook == getattr(cfg1.gainloss_book, 'id', None),
tab_line.debit - tab_line.credit),
),
tab_spmv_counterpart.credit - tab_spmv_counterpart.debit,
Decimal('0.0'),
).as_('gainloss'),
) * Decimal('-1.0')).as_('gainloss'),
)
return (tab_line, query)
@ -640,13 +645,14 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
))
# quantity and amount must with same sign
(amount_sign, a_dig, a_exp) = line.amount.as_tuple()
(quantity_sign, q_dig, q_exp) = line.quantity.as_tuple()
if amount_sign != quantity_sign:
raise UserError(gettext(
'cashbook_investment.msg_line_sign_mismatch',
linetxt = line.rec_name,
))
if (line.amount != Decimal('0.0')) and (line.quantity != Decimal('0.0')):
(amount_sign, a_dig, a_exp) = line.amount.as_tuple()
(quantity_sign, q_dig, q_exp) = line.quantity.as_tuple()
if amount_sign != quantity_sign:
raise UserError(gettext(
'cashbook_investment.msg_line_sign_mismatch',
linetxt = line.rec_name,
))
@classmethod
def update_values_by_splitlines(cls, lines):