Ensure payment term always returns a value

issue4286
review26281002
This commit is contained in:
Sergi Almacellas Abellana
2016-05-25 12:59:48 +02:00
parent bb0c990355
commit 1e54ef271c
2 changed files with 54 additions and 2 deletions
+7 -2
View File
@@ -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,))
+47
View File
@@ -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()