diff --git a/golem_resource/models/golem_resource.py b/golem_resource/models/golem_resource.py index c7896e1..eef465d 100644 --- a/golem_resource/models/golem_resource.py +++ b/golem_resource/models/golem_resource.py @@ -49,7 +49,10 @@ class GolemResource(models.Model): reservation_ids = fields.One2many('golem.resource.reservation', 'resource_id', string='Reservations') + #the resource is available in every hour, in every day during the availibility period availibility_24_7 = fields.Boolean(string='24/7 availibility') + #the resource is available 24h during the chosen days + availibility_24_24 = fields.Boolean(string='24/24 availibility') @api.multi def active_toggle(self): @@ -64,3 +67,9 @@ class GolemResource(models.Model): if resource.avaibility_stop <= resource.avaibility_start: raise ValidationError(_('End availibility should be after than ' 'start availibility')) + @api.onchange('availibility_24_24') + def _onchange_availibility_24_24(self): + for resource in self: + if resource.availibility_24_24: + resource.timetable_ids.write({'time_start': 0.0, + 'time_stop': 23.99}) diff --git a/golem_resource/models/golem_resource_reservation.py b/golem_resource/models/golem_resource_reservation.py index a7f153e..322b363 100644 --- a/golem_resource/models/golem_resource_reservation.py +++ b/golem_resource/models/golem_resource_reservation.py @@ -168,15 +168,15 @@ class GolemResourceReservation(models.Model): verr = _('You do not have permissions to validate or reject a reservation.') raise ValidationError(verr) - """ + @api.constrains('state') - def check_confirmed(self):""" - """ Check date coherence on reservation confirmation """ - """" for reservation in self: + def check_confirmed(self): + """ Check date coherence on reservation confirmation """ + for reservation in self: if reservation.state == 'confirmed': # Check is reservation is not taking place out of the resource avaibility period - if reservation.date < reservation.resource_id.avaibility_start or \ - reservation.date > reservation.resource_id.avaibility_stop: + if reservation.date_start < reservation.resource_id.avaibility_start or \ + reservation.date_stop > reservation.resource_id.avaibility_stop: verr = _('Not allowed, the resource is not available in ' 'this period, please choose another périod before ' 'confirming') @@ -200,6 +200,7 @@ class GolemResourceReservation(models.Model): verr = _('Not allowed, the resource is not available ' 'this day. Please choose another date.') raise ValidationError(verr) + """ # Check if the resource is already taken during this period # PERF : check the date, not iterate over all reservations domain = [('resource_id', '=', reservation.resource_id.id), @@ -214,8 +215,7 @@ class GolemResourceReservation(models.Model): 'during this period : from {} to {} this day, ' 'please choose another périod before confirming.') raise ValidationError(verr.format(other_res.date_start, - other_res.date_stop)) - """ + other_res.date_stop))""" @api.multi def reservation_calendar(self): """ current resource reservation calendar """ diff --git a/golem_resource/models/golem_resource_timetable.py b/golem_resource/models/golem_resource_timetable.py index e3eb8c9..8090a70 100644 --- a/golem_resource/models/golem_resource_timetable.py +++ b/golem_resource/models/golem_resource_timetable.py @@ -30,6 +30,7 @@ class GolemTimetable(models.Model): resource_id = fields.Many2one('golem.resource', required=True, string='Linked resource') + availibility_24_24 = fields.Boolean(related="resource_id.availibility_24_24") weekday = fields.Selection([('0', _('Monday')), ('1', _('Tuesday')), ('2', _('Wednesday')), @@ -37,8 +38,8 @@ class GolemTimetable(models.Model): ('4', _('Friday')), ('5', _('Saturday')), ('6', _('Sunday'))], required=True) - time_start = fields.Float(required=True, string='Start') - time_stop = fields.Float(required=True, string='Stop') + time_start = fields.Float(required=True, string='Start', default=0.0) + time_stop = fields.Float(required=True, string='Stop', default=23.99) @api.onchange('time_start') def onchange_time_start(self): diff --git a/golem_resource/views/golem_resource_timetable_views.xml b/golem_resource/views/golem_resource_timetable_views.xml index 9e532ea..2edaded 100644 --- a/golem_resource/views/golem_resource_timetable_views.xml +++ b/golem_resource/views/golem_resource_timetable_views.xml @@ -27,8 +27,11 @@ along with this program. If not, see . - - + + + diff --git a/golem_resource/views/golem_resource_views.xml b/golem_resource/views/golem_resource_views.xml index 1e8a974..abf5cf2 100644 --- a/golem_resource/views/golem_resource_views.xml +++ b/golem_resource/views/golem_resource_views.xml @@ -74,9 +74,10 @@ along with this program. If not, see . Please save the resource before fixing the timetable availibility"

+ + attrs="{'readonly': [('id', '=', False)]}"/>