Merge PR #447 into 12.0

Signed-off-by sbejaoui
This commit is contained in:
OCA-git-bot
2020-01-02 13:06:59 +00:00
2 changed files with 23 additions and 1 deletions

View File

@@ -569,7 +569,9 @@ class ContractLine(models.Model):
% line.name % line.name
) )
@api.constrains('date_start', 'date_end', 'last_date_invoiced') @api.constrains(
'date_start', 'date_end', 'last_date_invoiced', 'recurring_next_date'
)
def _check_last_date_invoiced(self): def _check_last_date_invoiced(self):
for rec in self.filtered('last_date_invoiced'): for rec in self.filtered('last_date_invoiced'):
if rec.date_start and rec.date_start > rec.last_date_invoiced: if rec.date_start and rec.date_start > rec.last_date_invoiced:
@@ -588,6 +590,17 @@ class ContractLine(models.Model):
) )
% rec.name % rec.name
) )
if (
rec.recurring_next_date
and rec.recurring_next_date <= rec.last_date_invoiced
):
raise ValidationError(
_(
"You can't have the next invoice date before the date "
"of last invoice for the contract line '%s'"
)
% rec.name
)
@api.constrains('recurring_next_date') @api.constrains('recurring_next_date')
def _check_recurring_next_date_recurring_invoices(self): def _check_recurring_next_date_recurring_invoices(self):

View File

@@ -2306,3 +2306,12 @@ class TestContract(TestContractBase):
self.assertTrue(self.acct_line.recurring_next_date) self.assertTrue(self.acct_line.recurring_next_date)
self.acct_line.stop(self.acct_line.last_date_invoiced) self.acct_line.stop(self.acct_line.last_date_invoiced)
self.assertFalse(self.acct_line.recurring_next_date) self.assertFalse(self.acct_line.recurring_next_date)
def test_check_last_date_invoiced_before_next_invoice_date(self):
with self.assertRaises(ValidationError):
self.acct_line.write({
'date_start': '2019-01-01',
'date_end': '2019-12-01',
'recurring_next_date': '2019-01-01',
'last_date_invoiced': '2019-06-01',
})