Derniere version de multidays avant mise à jours master

This commit is contained in:
eloyoussef 2018-03-10 23:09:44 +01:00
parent f9ba4284c8
commit 395a4becdb
2 changed files with 56 additions and 4 deletions

View File

@ -56,6 +56,8 @@ class GolemResourceReservation(models.Model):
states={'draft': [('readonly', False)]})
resource_avaibility_start = fields.Date(related='resource_id.avaibility_start')
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')
note = fields.Text(help='Notes, optional subject for the reservation, reason')
@ -181,10 +183,58 @@ class GolemResourceReservation(models.Model):
'this period, please choose another périod before '
'confirming')
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
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
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
"""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)
@ -199,7 +249,7 @@ class GolemResourceReservation(models.Model):
if not is_day_allowed:
verr = _('Not allowed, the resource is not available '
'this day. Please choose another date.')
raise ValidationError(verr)
raise ValidationError(verr)"""
"""
# Check if the resource is already taken during this period
# PERF : check the date, not iterate over all reservations

View File

@ -84,9 +84,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group string="Resource">
<field name="id" invisible="1" />
<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_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 string="Reservation">
<group>