From 7e62b1e335016ff14203d17080efe8fce5396b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 30 Oct 2021 18:28:52 +0200 Subject: [PATCH] Use the same sign for amount when splitting line by amount Also increase interval by the interval value and set a currency to the remaining term. --- move.py | 10 ++++++---- tests/scenario_move_line_split.rst | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/move.py b/move.py index 9eadc6f10e..65d14d5fc6 100644 --- a/move.py +++ b/move.py @@ -2208,20 +2208,22 @@ class SplitLines(Wizard): values['terms'] = terms = [] if self.start.amount: interval = self.start.interval - while abs(remaining - self.start.amount) > 0: + amount = self.start.amount.copy_sign(remaining) + while remaining - amount > 0: terms.append({ 'date': date, - 'amount': self.start.amount, + 'amount': amount, 'currency': currency.id, }) date = ( self.start.start_date + relativedelta(months=interval)) - interval += 1 - remaining -= self.start.amount + interval += self.start.interval + remaining -= amount if remaining: terms.append({ 'date': date, 'amount': remaining, + 'currency': currency.id, }) elif self.start.number: amount = self.start.currency.round( diff --git a/tests/scenario_move_line_split.rst b/tests/scenario_move_line_split.rst index c3b8feb05b..e37f493fc5 100644 --- a/tests/scenario_move_line_split.rst +++ b/tests/scenario_move_line_split.rst @@ -77,7 +77,30 @@ Create Lines to split:: >>> receivable.balance, receivable.amount_second_currency (Decimal('90.00'), Decimal('100.00')) -Split line:: +Split line by amount:: + + >>> split = Wizard('account.move.line.split', [line]) + >>> split.form.total_amount + Decimal('100.00') + >>> split.form.start_date = period.end_date + >>> split.form.frequency = 'other' + >>> split.form.interval = 2 + >>> split.form.amount = Decimal('30.00') + >>> split.execute('preview') + + >>> term1, term2, term3, term4 = split.form.terms + >>> term1.date == period.end_date + True + >>> term2.date == period.end_date + relativedelta(months=2) + True + >>> term3.date == period.end_date + relativedelta(months=4) + True + >>> term4.date == period.end_date + relativedelta(months=6) + True + >>> term1.amount, term2.amount, term3.amount, term4.amount + (Decimal('30.00'), Decimal('30.00'), Decimal('30.00'), Decimal('10.00')) + +Split line by number:: >>> split = Wizard('account.move.line.split', [line]) >>> split.form.total_amount