Ajout du champs disponibilité 24_24 et gestion de la liste des jours en fonction

This commit is contained in:
eloyoussef 2018-03-09 23:57:20 +01:00
parent 350efce581
commit f9ba4284c8
5 changed files with 27 additions and 13 deletions

View File

@ -49,7 +49,10 @@ class GolemResource(models.Model):
reservation_ids = fields.One2many('golem.resource.reservation', 'resource_id', reservation_ids = fields.One2many('golem.resource.reservation', 'resource_id',
string='Reservations') 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') 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 @api.multi
def active_toggle(self): def active_toggle(self):
@ -64,3 +67,9 @@ class GolemResource(models.Model):
if resource.avaibility_stop <= resource.avaibility_start: if resource.avaibility_stop <= resource.avaibility_start:
raise ValidationError(_('End availibility should be after than ' raise ValidationError(_('End availibility should be after than '
'start availibility')) '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})

View File

@ -168,15 +168,15 @@ class GolemResourceReservation(models.Model):
verr = _('You do not have permissions to validate or reject a reservation.') verr = _('You do not have permissions to validate or reject a reservation.')
raise ValidationError(verr) raise ValidationError(verr)
"""
@api.constrains('state') @api.constrains('state')
def check_confirmed(self):""" def check_confirmed(self):
""" Check date coherence on reservation confirmation """ """ Check date coherence on reservation confirmation """
"""" for reservation in self: for reservation in self:
if reservation.state == 'confirmed': if reservation.state == 'confirmed':
# Check is reservation is not taking place out of the resource avaibility period # Check is reservation is not taking place out of the resource avaibility period
if reservation.date < reservation.resource_id.avaibility_start or \ if reservation.date_start < reservation.resource_id.avaibility_start or \
reservation.date > reservation.resource_id.avaibility_stop: reservation.date_stop > reservation.resource_id.avaibility_stop:
verr = _('Not allowed, the resource is not available in ' verr = _('Not allowed, the resource is not available in '
'this period, please choose another périod before ' 'this period, please choose another périod before '
'confirming') 'confirming')
@ -200,6 +200,7 @@ class GolemResourceReservation(models.Model):
verr = _('Not allowed, the resource is not available ' verr = _('Not allowed, the resource is not available '
'this day. Please choose another date.') 'this day. Please choose another date.')
raise ValidationError(verr) raise ValidationError(verr)
"""
# Check if the resource is already taken during this period # Check if the resource is already taken during this period
# PERF : check the date, not iterate over all reservations # PERF : check the date, not iterate over all reservations
domain = [('resource_id', '=', reservation.resource_id.id), domain = [('resource_id', '=', reservation.resource_id.id),
@ -214,8 +215,7 @@ class GolemResourceReservation(models.Model):
'during this period : from {} to {} this day, ' 'during this period : from {} to {} this day, '
'please choose another périod before confirming.') 'please choose another périod before confirming.')
raise ValidationError(verr.format(other_res.date_start, raise ValidationError(verr.format(other_res.date_start,
other_res.date_stop)) other_res.date_stop))"""
"""
@api.multi @api.multi
def reservation_calendar(self): def reservation_calendar(self):
""" current resource reservation calendar """ """ current resource reservation calendar """

View File

@ -30,6 +30,7 @@ class GolemTimetable(models.Model):
resource_id = fields.Many2one('golem.resource', required=True, resource_id = fields.Many2one('golem.resource', required=True,
string='Linked resource') string='Linked resource')
availibility_24_24 = fields.Boolean(related="resource_id.availibility_24_24")
weekday = fields.Selection([('0', _('Monday')), weekday = fields.Selection([('0', _('Monday')),
('1', _('Tuesday')), ('1', _('Tuesday')),
('2', _('Wednesday')), ('2', _('Wednesday')),
@ -37,8 +38,8 @@ 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(required=True, string='Start', default=0.0)
time_stop = fields.Float(required=True, string='Stop') time_stop = fields.Float(required=True, string='Stop', default=23.99)
@api.onchange('time_start') @api.onchange('time_start')
def onchange_time_start(self): def onchange_time_start(self):

View File

@ -27,8 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<tree editable="bottom"> <tree editable="bottom">
<field name="resource_id" invisible="1" /> <field name="resource_id" invisible="1" />
<field name="weekday" /> <field name="weekday" />
<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="{'readonly': [('availibility_24_24', '=', True)]}"/>
<field name="time_stop" string="Stop hour" widget="float_time"
attrs="{'readonly': [('availibility_24_24', '=', True)]}"/>
<field name="availibility_24_24" invisible='1'/>
</tree> </tree>
</field> </field>
</record> </record>

View File

@ -74,9 +74,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Please save the resource before fixing the timetable availibility" Please save the resource before fixing the timetable availibility"
</p> </p>
<group colspan="2" attrs="{'invisible': [('availibility_24_7', '=', True)]}"> <group colspan="2" attrs="{'invisible': [('availibility_24_7', '=', True)]}">
<field name="availibility_24_24"/>
<field name="timetable_ids" <field name="timetable_ids"
context="{'default_resource_id': active_id}" context="{'default_resource_id': active_id}"
attrs="{'readonly': [('id', '=', False)]}" /> attrs="{'readonly': [('id', '=', False)]}"/>
</group> </group>
</group> </group>
</sheet> </sheet>