line: negate amount if splitline=spout - tests

This commit is contained in:
Frederik Jaeckel 2023-02-14 22:27:25 +01:00
parent 798da563ec
commit 3243ccc471
2 changed files with 62 additions and 26 deletions

12
line.py
View file

@ -4,7 +4,7 @@
# full copyright notices and license terms.
from decimal import Decimal
from sql.conditionals import Coalesce
from sql.conditionals import Coalesce, Case
from sql.aggregate import Sum
from trytond.model import fields
from trytond.pool import PoolMeta, Pool
@ -212,13 +212,19 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
Sum(Coalesce(
tab_inout_fee.credit - tab_inout_fee.debit,
tab_mv_spline_fee.amount,
tab_spline_fee.amount,
Case(
(tab_line.bookingtype == 'spin', tab_spline_fee.amount),
(tab_line.bookingtype == 'spout', tab_spline_fee.amount * Decimal('-1.0')),
),
Decimal('0.0'),
)).as_('fee'),
Sum(Coalesce(
tab_inout_divi.credit - tab_inout_divi.debit,
tab_mv_spline_divi.amount,
tab_spline_divi.amount,
Case(
(tab_line.bookingtype == 'spin', tab_spline_divi.amount),
(tab_line.bookingtype == 'spout', tab_spline_divi.amount * Decimal('-1.0')),
),
Decimal('0.0'),
)).as_('dividend'),
group_by=[tab_line.id],