Multidays reservation added #12

Manually merged
Yaltik merged 1 commits from youssef/GOLEM:youssef_multidays_2 into master 2018-03-17 09:39:34 +01:00
5 changed files with 49 additions and 51 deletions

View File

@ -39,15 +39,6 @@ class GolemResourceReservation(models.Model):
date_stop = fields.Datetime('Stop date', required=True, date_stop = fields.Datetime('Stop date', required=True,
index=True, readonly=True, index=True, readonly=True,
states={'draft': [('readonly', False)]}) states={'draft': [('readonly', False)]})
#date = fields.Date(required=True, index=True, readonly=True,
# states={'draft': [('readonly', False)]})
#hour_start = fields.Float('Start hour', required=True, readonly=True,
# states={'draft': [('readonly', False)]})
#hour_stop = fields.Float('Stop hour', required=True, readonly=True,
# states={'draft': [('readonly', False)]})
#date_start = fields.Datetime(compute='_compute_date_start', store=True, index=True)
#date_stop = fields.Datetime(compute='_compute_date_stop', store=True, index=True)
resource_id = fields.Many2one('golem.resource', required=True, index=True, resource_id = fields.Many2one('golem.resource', required=True, index=True,
string='Resource', readonly=True, string='Resource', readonly=True,
track_visibility='onchange', track_visibility='onchange',
@ -82,28 +73,6 @@ class GolemResourceReservation(models.Model):
reservation.name = u'{}/{}'.format(reservation.resource_id.name, reservation.name = u'{}/{}'.format(reservation.resource_id.name,
reservation.date_start) reservation.date_start)
#@api.depends('date', 'hour_start')
#def _compute_date_start(self):
# """ Computes Date start """
# for reservation in self:
# minute_start, hour_start = modf(reservation.hour_start)
# hour_start = int(hour_start)
# minute_start = int(round(minute_start * 60))
# reservation.date_start = u'{} {}:{}:00'.format(reservation.date,
# hour_start, minute_start)
#@api.depends('date', 'hour_stop')
#def _compute_date_stop(self):
# """ Computes Date stop """
# for reservation in self:
# minute_stop, hour_stop = modf(reservation.hour_stop)
# hour_stop = int(hour_stop)
# minute_stop = int(round(minute_stop * 60))
# reservation.date_stop = u'{} {}:{}:00'.format(reservation.date,
# hour_stop, minute_stop)
@api.onchange('date_start') @api.onchange('date_start')
def onchange_date_start(self): def onchange_date_start(self):
""" Propose automatically stop hour after start hour had been filled """ """ Propose automatically stop hour after start hour had been filled """
@ -206,7 +175,6 @@ class GolemResourceReservation(models.Model):
hour_start = date_start.hour + date_start.minute/60.0 hour_start = date_start.hour + date_start.minute/60.0
hour_stop = 23.98 hour_stop = 23.98
elif reservation_day.date() == date_stop.date(): elif reservation_day.date() == date_stop.date():
hour_start = 0.0 hour_start = 0.0
hour_stop = date_stop.hour + date_stop.minute/60.0 hour_stop = date_stop.hour + date_stop.minute/60.0
else: else:

View File

@ -37,25 +37,25 @@ class GolemTimetable(models.Model):
('4', _('Friday')), ('4', _('Friday')),
('5', _('Saturday')), ('5', _('Saturday')),
('6', _('Sunday'))], required=True) ('6', _('Sunday'))], required=True)
time_start = fields.Float(required=True, string='Start') time_start = fields.Float(string='Start')
time_stop = fields.Float(required=True, string='Stop') time_stop = fields.Float(string='Stop')
availibility_24 = fields.Boolean(string="All day") availibility_24 = fields.Boolean(string="All day")
#@api.onchange('availibility_24')
#def _set_time_start_stop(self):
# """ set start and stop time """
# self.ensure_one()
# if self.availibility_24:
# self.time_start = 0.0
# self.time_stop = 23.99
@api.onchange('availibility_24') @api.onchange('availibility_24')
def onchange_availibility_24(self): def onchange_availibility_24(self):
""" Propose automatically stop hour after start hour had been filled """ """ fill time_start et time_stop if availibility_24 is True """
for line in self: for line in self:
if line.availibility_24: if line.availibility_24:
line.time_start = 0.0 line.time_start = 0.0
line.time_stop = 23.98 line.time_stop = 23.98
@api.constrains('availibility_24')
@api.multi
def check_time_filling(self):
""" Check start and stop time filling out"""
for line in self:
if not line.availibility_24 and (not line.time_start or not line.time_stop):
raise ValidationError(_('Start and stop time should be filled out '
'if the 24 availibility is not checked.'))
@api.onchange('time_start') @api.onchange('time_start')
def onchange_time_start(self): def onchange_time_start(self):

View File

@ -43,9 +43,21 @@ class TestGolemResourceReservation(TransactionCase):
}) })
self.timetable_obj = self.env['golem.resource.timetable'] self.timetable_obj = self.env['golem.resource.timetable']
timetable_data = {'resource_id': self.resource.id, 'weekday': '0', timetable_data = {'resource_id': self.resource.id, 'weekday': '0',
'time_start': 8.0, 'time_stop': 12.0} 'time_start': 8.0, 'time_stop': 12.0}
timetable_data2 = {'resource_id': self.resource.id, 'weekday': '1',
'availibility_24': True}
timetable_data3 = {'resource_id': self.resource.id, 'weekday': '2',
'time_start': 7.0, 'time_stop': 23.98}
timetable_data4 = {'resource_id': self.resource.id, 'weekday': '3',
'availibility_24': True}
self.timetable_obj.create(timetable_data) self.timetable_obj.create(timetable_data)
self.timetable_obj.create(timetable_data2)
self.timetable_obj.create(timetable_data3)
self.timetable_obj.create(timetable_data4)
timetable_data['resource_id'] = self.resource_val.id timetable_data['resource_id'] = self.resource_val.id
self.timetable_obj.create(timetable_data) self.timetable_obj.create(timetable_data)
@ -72,7 +84,7 @@ class TestGolemResourceReservation(TransactionCase):
self.assertFalse(reservation.rejection_reason) self.assertFalse(reservation.rejection_reason)
self.assertEqual(reservation.name, 'Resource/2018-02-05 11:00:00') self.assertEqual(reservation.name, 'Resource/2018-02-05 11:00:00')
self.assertEqual(reservation.resource_id, self.resource) self.assertEqual(reservation.resource_id, self.resource)
self.assertEqual(len(reservation.resource_timetable_ids), 1) self.assertEqual(len(reservation.resource_timetable_ids), 4)
self.assertEqual(reservation.resource_id.reservation_ids[0], reservation) self.assertEqual(reservation.resource_id.reservation_ids[0], reservation)
def test_reservation_hours(self): def test_reservation_hours(self):
@ -111,6 +123,7 @@ class TestGolemResourceReservation(TransactionCase):
reservation.state_confirm() reservation.state_confirm()
self.assertEqual(reservation.state, 'validated') self.assertEqual(reservation.state, 'validated')
def test_state_rejected(self): def test_state_rejected(self):
""" Tests state rejected """ """ Tests state rejected """
self.data['resource_id'] = self.resource_val.id self.data['resource_id'] = self.resource_val.id
@ -146,7 +159,7 @@ class TestGolemResourceReservation(TransactionCase):
reservation = self.res_obj.create(self.data) reservation = self.res_obj.create(self.data)
with self.assertRaises(ValidationError) as err: with self.assertRaises(ValidationError) as err:
reservation.state_confirm() reservation.state_confirm()
self.assertIn(u'pas disponible durant cette période', err.exception.args[0]) self.assertIn(u'pas disponible durant cette période', err.exception.args[0])
def test_confirmed_allowed_day(self): def test_confirmed_allowed_day(self):
""" Test allowed day """ """ Test allowed day """
@ -156,13 +169,29 @@ class TestGolemResourceReservation(TransactionCase):
reservation.state_confirm() reservation.state_confirm()
self.assertIn('pas disponible ce jour', err.exception.args[0]) self.assertIn('pas disponible ce jour', err.exception.args[0])
def test_multidays_reservation(self):
""" Test multidays reservation """
#two days allowed reservation
self.data['date_start'] = '2018-02-07 14:00:00' # Wednesday : allowed FROM 7
self.data['date_stop'] = '2018-02-08 11:00:00' # Thursday : allowed
reservation = self.res_obj.create(self.data)
reservation.state_confirm()
self.assertEqual(reservation.state, 'validated')
reservation.state_draft()
#Two days allowed but one not allowed in the middle
reservation.write({'date_start': '2018-02-06 14:00:00',# Tuesday : allowed
'date_stop': '2018-02-08 11:00:00'})# Thursday : allowed but not Wednesday
with self.assertRaises(ValidationError) as err:
reservation.state_confirm()
self.assertIn('pas disponible ce jour', err.exception.args[0])
def test_confirmed_allowed_hours(self): def test_confirmed_allowed_hours(self):
""" Test allowed hours """ """ Test allowed hours """
self.data['date_stop'] = '2018-02-05 14:00:00' # Out of range stop hour self.data['date_stop'] = '2018-02-05 14:00:00' # Out of range stop hour
reservation = self.res_obj.create(self.data) reservation = self.res_obj.create(self.data)
with self.assertRaises(ValidationError) as err: with self.assertRaises(ValidationError) as err:
reservation.state_confirm() reservation.state_confirm()
self.assertIn(u'merci de choisir d\'autres horaires', err.exception.args[0]) self.assertIn(u'merci de choisir d\'autres horaires', err.exception.args[0])
reservation = self.res_obj.create({'resource_id': self.resource.id, reservation = self.res_obj.create({'resource_id': self.resource.id,
'date_start': '2018-02-05 05:00:00',# Out of range start hour 'date_start': '2018-02-05 05:00:00',# Out of range start hour
'date_stop': '2018-02-05 12:00:00', 'date_stop': '2018-02-05 12:00:00',

View File

@ -46,6 +46,7 @@ class TestGolemResourceTimetable(TransactionCase):
self.assertEqual(timetable.resource_id, self.resource) self.assertEqual(timetable.resource_id, self.resource)
self.assertEqual(timetable.time_start, 8.0) self.assertEqual(timetable.time_start, 8.0)
self.assertEqual(timetable.time_stop, 10.0) self.assertEqual(timetable.time_stop, 10.0)
self.assertFalse(timetable.availibility_24)
self.assertEqual(timetable, self.resource.timetable_ids[0]) self.assertEqual(timetable, self.resource.timetable_ids[0])
def test_timetable_times(self): def test_timetable_times(self):

View File

@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<odoo> <odoo>
<data> <data>
<!-- Trees --> <!-- Trees -->
<record model="ir.ui.view" id="golem_resource_timetable_view_tree"> <record model="ir.ui.view" id="golem_resource_timetable_view_tree">
<field name="name">GOLEM Resource Timetable Tree</field> <field name="name">GOLEM Resource Timetable Tree</field>
@ -28,11 +27,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="resource_id" invisible="1" /> <field name="resource_id" invisible="1" />
<field name="weekday" /> <field name="weekday" />
<field name="availibility_24"/> <field name="availibility_24"/>
<field name="time_start" string="Start hour" widget="float_time"/> <field name="time_start" string="Start hour" widget="float_time"
<field name="time_stop" string="Stop hour" widget="float_time"/> attrs="{'required' : [('availibility_24', '=', False)]}"/>
<field name="time_stop" string="Stop hour" widget="float_time"
attrs="{'required' : [('availibility_24', '=', False)]}"/>
</tree> </tree>
</field> </field>
</record> </record>
</data> </data>
</odoo> </odoo>