[TMP] Test if date_start date_end is required and vice-versa AND unit test

This commit is contained in:
michel 2018-01-17 15:44:43 +01:00
parent 8cf4a1f07f
commit e7ba4b91f8
2 changed files with 26 additions and 29 deletions

View File

@ -42,8 +42,7 @@ class GolemSeason(models.Model):
def _onchange_season_dates(self):
""" Sets defaults dates according to membership type """
for season in self:
if season.membership_id:
if not season.date_start:
if season.membership_id and not season.date_start:
season.update({
'date_start': season.membership_id.membership_date_from,
'date_end': season.membership_id.membership_date_to
@ -59,7 +58,6 @@ class GolemSeason(models.Model):
raise models.ValidationError(_('The date end is required'))
elif season.date_end and not season.date_start:
raise models.ValidationError(_('The date start is required'))
if season.date_start > season.date_end:
raise models.ValidationError(_('Start of the period cannot be '
'after end of the period.'))

View File

@ -74,9 +74,8 @@ class TestGolemSeason(TransactionCase):
'membership_date_to': '2018-11-01'})
new_season = self.env['golem.season'].create({'name': 'Name',
'membership_id': membership.id})
new_season._onchange_season_dates()
'membership_id': membership.id,
'membership_date_from': '2017-11-01',
'membership_date_to': '2018-11-01'})
self.assertEqual(new_season.date_start, membership.membership_date_from)
self.assertEqual(new_season.date_end, membership.membership_date_to)