Compare commits
3 Commits
master
...
golem_mult
Author | SHA1 | Date | |
---|---|---|---|
|
395a4becdb | ||
|
f9ba4284c8 | ||
|
350efce581 |
@ -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})
|
||||||
|
@ -19,8 +19,11 @@
|
|||||||
""" GOLEM Resource Reservation """
|
""" GOLEM Resource Reservation """
|
||||||
|
|
||||||
from math import modf
|
from math import modf
|
||||||
|
from datetime import timedelta
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
import logging
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GolemResourceReservation(models.Model):
|
class GolemResourceReservation(models.Model):
|
||||||
@ -28,18 +31,24 @@ class GolemResourceReservation(models.Model):
|
|||||||
_name = 'golem.resource.reservation'
|
_name = 'golem.resource.reservation'
|
||||||
_description = 'GOLEM Reservation Model'
|
_description = 'GOLEM Reservation Model'
|
||||||
_inherit = 'mail.thread'
|
_inherit = 'mail.thread'
|
||||||
_order = 'date desc,hour_start asc'
|
_order = 'date_start desc'
|
||||||
|
|
||||||
name = fields.Char(compute='_compute_name', store=True)
|
name = fields.Char(compute='_compute_name', store=True)
|
||||||
# TODO: handle multiple days reservation
|
# TODO: handle multiple days reservation
|
||||||
date = fields.Date(required=True, index=True, readonly=True,
|
date_start = fields.Datetime('Start date',required=True,
|
||||||
|
index=True, readonly=True,
|
||||||
states={'draft': [('readonly', False)]})
|
states={'draft': [('readonly', False)]})
|
||||||
hour_start = fields.Float('Start hour', required=True, readonly=True,
|
date_stop = fields.Datetime('Stop date', required=True,
|
||||||
|
index=True, readonly=True,
|
||||||
states={'draft': [('readonly', False)]})
|
states={'draft': [('readonly', False)]})
|
||||||
hour_stop = fields.Float('Stop hour', required=True, readonly=True,
|
#date = fields.Date(required=True, index=True, readonly=True,
|
||||||
states={'draft': [('readonly', False)]})
|
# states={'draft': [('readonly', False)]})
|
||||||
date_start = fields.Datetime(compute='_compute_date_start', store=True, index=True)
|
#hour_start = fields.Float('Start hour', required=True, readonly=True,
|
||||||
date_stop = fields.Datetime(compute='_compute_date_stop', store=True, index=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,
|
||||||
@ -47,6 +56,8 @@ class GolemResourceReservation(models.Model):
|
|||||||
states={'draft': [('readonly', False)]})
|
states={'draft': [('readonly', False)]})
|
||||||
resource_avaibility_start = fields.Date(related='resource_id.avaibility_start')
|
resource_avaibility_start = fields.Date(related='resource_id.avaibility_start')
|
||||||
resource_avaibility_stop = fields.Date(related='resource_id.avaibility_stop')
|
resource_avaibility_stop = fields.Date(related='resource_id.avaibility_stop')
|
||||||
|
resource_availibility_24_7 = fields.Boolean(related='resource_id.availibility_24_7')
|
||||||
|
resource_availibility_24_24 = fields.Boolean(related='resource_id.availibility_24_24')
|
||||||
resource_timetable_ids = fields.One2many(related='resource_id.timetable_ids')
|
resource_timetable_ids = fields.One2many(related='resource_id.timetable_ids')
|
||||||
|
|
||||||
note = fields.Text(help='Notes, optional subject for the reservation, reason')
|
note = fields.Text(help='Notes, optional subject for the reservation, reason')
|
||||||
@ -69,46 +80,48 @@ class GolemResourceReservation(models.Model):
|
|||||||
|
|
||||||
resource_reservation_count = fields.Integer(compute='_reservation_count')
|
resource_reservation_count = fields.Integer(compute='_reservation_count')
|
||||||
|
|
||||||
@api.depends('resource_id', 'date')
|
@api.depends('resource_id', 'date_start')
|
||||||
def _compute_name(self):
|
def _compute_name(self):
|
||||||
""" Computes reservation name """
|
""" Computes reservation name """
|
||||||
for reservation in self:
|
for reservation in self:
|
||||||
reservation.name = u'{}/{}'.format(reservation.resource_id.name,
|
reservation.name = u'{}/{}'.format(reservation.resource_id.name,
|
||||||
reservation.date)
|
reservation.date_start)
|
||||||
|
|
||||||
@api.depends('date', 'hour_start')
|
#@api.depends('date', 'hour_start')
|
||||||
def _compute_date_start(self):
|
#def _compute_date_start(self):
|
||||||
""" Computes Date start """
|
# """ Computes Date start """
|
||||||
for reservation in self:
|
# for reservation in self:
|
||||||
minute_start, hour_start = modf(reservation.hour_start)
|
# minute_start, hour_start = modf(reservation.hour_start)
|
||||||
hour_start = int(hour_start)
|
# hour_start = int(hour_start)
|
||||||
minute_start = int(round(minute_start * 60))
|
# minute_start = int(round(minute_start * 60))
|
||||||
reservation.date_start = u'{} {}:{}:00'.format(reservation.date,
|
# reservation.date_start = u'{} {}:{}:00'.format(reservation.date,
|
||||||
hour_start, minute_start)
|
# hour_start, minute_start)
|
||||||
|
|
||||||
@api.depends('date', 'hour_stop')
|
#@api.depends('date', 'hour_stop')
|
||||||
def _compute_date_stop(self):
|
#def _compute_date_stop(self):
|
||||||
""" Computes Date stop """
|
# """ Computes Date stop """
|
||||||
for reservation in self:
|
# for reservation in self:
|
||||||
minute_stop, hour_stop = modf(reservation.hour_stop)
|
# minute_stop, hour_stop = modf(reservation.hour_stop)
|
||||||
hour_stop = int(hour_stop)
|
# hour_stop = int(hour_stop)
|
||||||
minute_stop = int(round(minute_stop * 60))
|
# minute_stop = int(round(minute_stop * 60))
|
||||||
reservation.date_stop = u'{} {}:{}:00'.format(reservation.date,
|
# reservation.date_stop = u'{} {}:{}:00'.format(reservation.date,
|
||||||
hour_stop, minute_stop)
|
# hour_stop, minute_stop)
|
||||||
|
|
||||||
@api.onchange('hour_start')
|
@api.onchange('date_start')
|
||||||
def onchange_hour_start(self):
|
def onchange_date_start(self):
|
||||||
""" Propose automatically stop hour after start hour had been filled """
|
""" Propose automatically stop date after start date had been filled """
|
||||||
for reservation in self:
|
for reservation in self:
|
||||||
if reservation.hour_start and not reservation.hour_stop:
|
if reservation.date_start:
|
||||||
reservation.hour_stop = reservation.hour_start + 1
|
start = fields.Datetime.from_string(reservation.date_start)
|
||||||
|
duration = timedelta(hours=1)
|
||||||
|
reservation.date_stop = start + duration
|
||||||
|
|
||||||
@api.constrains('hour_start', 'hour_stop')
|
@api.constrains('date_start', 'date_stop')
|
||||||
def _check_hour_consistency(self):
|
def _check_date_consistency(self):
|
||||||
""" Checks hour consistency """
|
""" Checks date consistency """
|
||||||
for reservation in self:
|
for reservation in self:
|
||||||
if reservation.hour_stop <= reservation.hour_start:
|
if reservation.date_stop <= reservation.date_start:
|
||||||
raise ValidationError(_('End time should be after than start time'))
|
raise ValidationError(_('Stop date should be after start date'))
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def state_draft(self):
|
def state_draft(self):
|
||||||
@ -157,22 +170,71 @@ 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')
|
||||||
raise ValidationError(verr)
|
raise ValidationError(verr)
|
||||||
|
#check if it's a multidays reservation
|
||||||
|
res_date_start = fields.Datetime.from_string(reservation.date_start).date()
|
||||||
|
res_date_stop = fields.Datetime.from_string(reservation.date_stop).date()
|
||||||
|
multidays = res_date_start != res_date_stop
|
||||||
|
|
||||||
#check if the resource hasn't a total availibility
|
#check if the resource hasn't a total availibility
|
||||||
if not reservation.resource_id.availibility_24_7:
|
if not reservation.resource_availibility_24_7:
|
||||||
|
if reservation.resource_availibility_24_24 and multidays:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
elif reservation.resource_availibility_24_24:
|
||||||
|
|
||||||
# Check if reservation is not taking place out the avaibility timetables
|
# Check if reservation is not taking place out the avaibility timetables
|
||||||
is_day_allowed = False
|
is_day_allowed = False
|
||||||
|
for timetable in reservation.resource_id.timetable_ids:
|
||||||
|
# Check for the time according to resource timetable avaibility
|
||||||
|
date = fields.Datetime.from_string(reservation.date_start)
|
||||||
|
if int(timetable.weekday) == date.weekday():
|
||||||
|
is_day_allowed = True
|
||||||
|
if not is_day_allowed:
|
||||||
|
verr = _('Not allowed, the resource is not available '
|
||||||
|
'this day. Please choose another date.')
|
||||||
|
raise ValidationError(verr)
|
||||||
|
|
||||||
|
elif not reservation.resource_availibility_24_24 and multidays:
|
||||||
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Check if reservation is not taking place out the avaibility timetables
|
||||||
|
is_day_allowed = False
|
||||||
|
for timetable in reservation.resource_id.timetable_ids:
|
||||||
|
# Check for the time according to resource timetable avaibility
|
||||||
|
date = fields.Datetime.from_string(reservation.date_start)
|
||||||
|
if int(timetable.weekday) == date.weekday():
|
||||||
|
is_day_allowed = True
|
||||||
|
if reservation.hour_start < timetable.time_start or \
|
||||||
|
reservation.hour_stop > timetable.time_stop:
|
||||||
|
verr = _('Not allowed, the resource is not available '
|
||||||
|
'during this period, please choose another '
|
||||||
|
'time before confirming.')
|
||||||
|
raise ValidationError(verr)
|
||||||
|
if not is_day_allowed:
|
||||||
|
verr = _('Not allowed, the resource is not available '
|
||||||
|
'this day. Please choose another date.')
|
||||||
|
raise ValidationError(verr)
|
||||||
|
|
||||||
|
|
||||||
|
# Check if reservation is not taking place out the avaibility timetables
|
||||||
|
"""is_day_allowed = False
|
||||||
for timetable in reservation.resource_id.timetable_ids:
|
for timetable in reservation.resource_id.timetable_ids:
|
||||||
# Check for the time according to resource timetable avaibility
|
# Check for the time according to resource timetable avaibility
|
||||||
date = fields.Datetime.from_string(reservation.date)
|
date = fields.Datetime.from_string(reservation.date)
|
||||||
@ -187,7 +249,8 @@ class GolemResourceReservation(models.Model):
|
|||||||
if not is_day_allowed:
|
if not is_day_allowed:
|
||||||
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),
|
||||||
@ -202,7 +265,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 """
|
||||||
|
@ -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):
|
||||||
|
@ -39,9 +39,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree>
|
<tree>
|
||||||
<field name="resource_id" />
|
<field name="resource_id" />
|
||||||
<field name="date" />
|
<field name="date_start" />
|
||||||
<field name="hour_start" widget="float_time" />
|
<field name="date_stop" />
|
||||||
<field name="hour_stop" widget="float_time" />
|
|
||||||
<field name="partner_id" />
|
<field name="partner_id" />
|
||||||
<field name="state" />
|
<field name="state" />
|
||||||
</tree>
|
</tree>
|
||||||
@ -85,15 +84,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<group string="Resource">
|
<group string="Resource">
|
||||||
<field name="id" invisible="1" />
|
<field name="id" invisible="1" />
|
||||||
<field name="resource_id" options="{'no_create': True}" />
|
<field name="resource_id" options="{'no_create': True}" />
|
||||||
|
<field name="resource_availibility_24_7" readonly="1" />
|
||||||
<field name="resource_avaibility_start" readonly="1" />
|
<field name="resource_avaibility_start" readonly="1" />
|
||||||
<field name="resource_avaibility_stop" readonly="1" />
|
<field name="resource_avaibility_stop" readonly="1" />
|
||||||
<field name="resource_timetable_ids" readonly="1" />
|
<field name="resource_timetable_ids"
|
||||||
|
attrs="{'invisible': [('resource_availibility_24_7', '=', True)]}" readonly="1" />
|
||||||
</group>
|
</group>
|
||||||
<group string="Reservation">
|
<group string="Reservation">
|
||||||
<group>
|
<group>
|
||||||
<field name="date" />
|
<field name="date_start" />
|
||||||
<field name="hour_start" widget="float_time" />
|
<field name="date_stop" />
|
||||||
<field name="hour_stop" widget="float_time" />
|
|
||||||
<field name="user_id" options="{'no_create': True}" />
|
<field name="user_id" options="{'no_create': True}" />
|
||||||
<field name="partner_id" />
|
<field name="partner_id" />
|
||||||
<field name="note"
|
<field name="note"
|
||||||
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user