diff --git a/payment_term.py b/payment_term.py index 6bde5f4885..25fafc6e6d 100644 --- a/payment_term.py +++ b/payment_term.py @@ -73,7 +73,7 @@ class PaymentTerm(ModelSQL, ModelView): for line in self.lines: value = line.get_value(remainder, amount, currency) value_date = line.get_date(date) - if not value or not value_date: + if value is None or not value_date: if (not remainder) and line.amount: self.raise_user_error('invalid_line', { 'line': line.rec_name, @@ -84,8 +84,13 @@ class PaymentTerm(ModelSQL, ModelView): if ((remainder - value) * sign) < Decimal('0.0'): res.append((value_date, remainder)) break - res.append((value_date, value)) + if value: + res.append((value_date, value)) remainder -= value + else: + # Enforce to have at least one term + if not res: + res.append((date, Decimal(0))) if not currency.is_zero(remainder): self.raise_user_error('missing_remainder', (self.rec_name,)) diff --git a/tests/test_account_invoice.py b/tests/test_account_invoice.py index e478039eed..23d8518421 100644 --- a/tests/test_account_invoice.py +++ b/tests/test_account_invoice.py @@ -93,6 +93,53 @@ class AccountInvoiceTestCase(ModuleTestCase): (datetime.date(2012, 1, 14), Decimal('396.83')), ]) + @with_transaction() + def test_payment_term_with_empty_value(self): + 'Test payment_term with empty' + pool = Pool() + PaymentTerm = pool.get('account.invoice.payment_term') + + cu1 = create_currency('cu1') + remainder_term, percent_term = PaymentTerm.create([{ + 'name': 'Remainder', + 'lines': [ + ('create', [{'type': 'remainder', + 'relativedeltas': [('create', [{ + 'months': 1, + }, + ]), + ], + }])] + }, { + 'name': '25% tomorrow, remainder un month later ', + 'lines': [ + ('create', [{'type': 'percent', + 'divisor': 4, + 'ratio': Decimal('.25'), + 'relativedeltas': [('create', [{ + 'days': 1, + }, + ]), + ], + }, {'type': 'remainder', + 'relativedeltas': [('create', [{ + 'months': 1, + }, + ]), + ], + }])] + }]) + terms = remainder_term.compute(Decimal('0.0'), cu1, + date=datetime.date(2016, 05, 17)) + self.assertEqual(terms, [ + (datetime.date(2016, 05, 17), Decimal('0.0')), + ]) + terms = percent_term.compute(Decimal('0.0'), cu1, + date=datetime.date(2016, 05, 17)) + self.assertEqual(terms, [ + (datetime.date(2016, 05, 17), Decimal('0.0')), + ]) + def suite(): suite = trytond.tests.test_tryton.suite()