2016-08-03 17:25:18 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-05-02 00:37:22 +02:00
|
|
|
# copyright 2017 fabien bourgeois <fabien@yaltik.com>
|
2016-08-03 17:25:18 +02:00
|
|
|
#
|
|
|
|
# this program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the gnu affero general public license as
|
|
|
|
# published by the free software foundation, either version 3 of the
|
|
|
|
# license, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# this program is distributed in the hope that it will be useful,
|
|
|
|
# but without any warranty; without even the implied warranty of
|
|
|
|
# merchantability or fitness for a particular purpose. see the
|
|
|
|
# gnu affero general public license for more details.
|
|
|
|
#
|
|
|
|
# you should have received a copy of the gnu affero general public license
|
|
|
|
# along with this program. if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-05-02 00:37:22 +02:00
|
|
|
""" GOLEM Activity Advanced Places management """
|
2016-08-03 17:25:18 +02:00
|
|
|
|
2017-05-02 00:37:22 +02:00
|
|
|
from odoo import models, fields, api, _
|
2016-08-03 17:25:18 +02:00
|
|
|
|
2016-10-10 18:28:53 +02:00
|
|
|
class GolemActivity(models.Model):
|
2017-05-02 00:37:22 +02:00
|
|
|
""" GOLEM Activity Advanced Places management """
|
2016-10-10 18:28:53 +02:00
|
|
|
_inherit = 'golem.activity'
|
2016-08-03 17:25:18 +02:00
|
|
|
|
|
|
|
places_min = fields.Integer('Minimum places', default=0,
|
2016-10-10 18:28:53 +02:00
|
|
|
help='Minimum places to maintain the activity')
|
2016-08-03 17:25:18 +02:00
|
|
|
is_overbooked = fields.Boolean('Allow overbook?', default=False)
|
|
|
|
places_overbooked = fields.Integer('Places with overbook', default=0)
|
|
|
|
|
2017-05-02 00:37:22 +02:00
|
|
|
@api.multi
|
2016-10-09 12:43:23 +02:00
|
|
|
@api.depends('places', 'is_overbooked', 'places_overbooked', 'places_used')
|
2016-08-03 17:25:18 +02:00
|
|
|
def _compute_places_remain(self):
|
2017-05-02 00:37:22 +02:00
|
|
|
""" Overwrite : computes remaining places """
|
|
|
|
for activity in self:
|
|
|
|
if not activity.is_overbooked:
|
|
|
|
activity.places_remain = activity.places - activity.places_used
|
|
|
|
else:
|
|
|
|
activity.places_remain = activity.places_overbooked - activity.places_used
|
2016-08-03 17:25:18 +02:00
|
|
|
|
|
|
|
@api.onchange('is_overbooked', 'places')
|
|
|
|
def onchange_is_overbooked(self):
|
2017-05-02 00:37:22 +02:00
|
|
|
""" Realtime display for places and overbooked """
|
|
|
|
for activity in self:
|
|
|
|
if activity.places and activity.is_overbooked:
|
|
|
|
if not activity.places_overbooked or \
|
|
|
|
(activity.places_overbooked < activity.places):
|
|
|
|
activity.places_overbooked = activity.places + 1
|
2016-08-03 17:25:18 +02:00
|
|
|
|
|
|
|
@api.constrains('places', 'places_overbooked')
|
|
|
|
def _check_places(self):
|
|
|
|
""" Check integers are signed and overbooked to be superior than
|
|
|
|
normal places """
|
2017-05-02 00:37:22 +02:00
|
|
|
for activity in self:
|
|
|
|
for field in ['places', 'places_overbooked']:
|
|
|
|
if activity[field] < 0:
|
2016-08-03 17:25:18 +02:00
|
|
|
emsg = _('Number of places cannot be negative.')
|
|
|
|
raise models.ValidationError(emsg)
|
2017-05-02 00:37:22 +02:00
|
|
|
if activity.is_overbooked and \
|
|
|
|
(activity.places_overbooked <= activity.places):
|
2016-08-03 17:25:18 +02:00
|
|
|
emsg = _('Overbooked places cannot be inferior than places')
|
|
|
|
raise models.ValidationError(emsg)
|