changeset 4098ad13c2ad in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=4098ad13c2ad
description:
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.
diffstat:
move.py | 10 ++++++----
tests/scenario_move_line_split.rst | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 5 deletions(-)
diffs (65 lines):
diff -r 0a311ab83a28 -r 4098ad13c2ad move.py
--- a/move.py Sat Oct 30 11:32:00 2021 +0200
+++ b/move.py Sat Oct 30 18:28:52 2021 +0200
@@ -2208,20 +2208,22 @@
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 -r 0a311ab83a28 -r 4098ad13c2ad tests/scenario_move_line_split.rst
--- a/tests/scenario_move_line_split.rst Sat Oct 30 11:32:00 2021 +0200
+++ b/tests/scenario_move_line_split.rst Sat Oct 30 18:28:52 2021 +0200
@@ -77,7 +77,30 @@
>>> 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