[ADD][IMP]GOLEM Activity Session handling of non-recuurence and usability enhancements

This commit is contained in:
Fabien Bourgeois 2016-07-10 07:45:55 +02:00
parent 3052569437
commit e9fef7280a
2 changed files with 66 additions and 11 deletions

View File

@ -55,7 +55,7 @@ class GolemActivitySession(models.Model):
name = fields.Char('Name', compute='_compute_name')
@api.depends('activity_id', 'weekday')
@api.depends('activity_id')
def _compute_name(self):
for s in self:
s.name = s.activity_id.activity_name
@ -68,12 +68,48 @@ class GolemActivitySession(models.Model):
for s in self:
s.places_used = len(s.member_ids)
# TODO: recurrence etc... to link with calendar.event
# TODO: to link with calendar.event
activity_id = fields.Many2one('golem.activity', string='Activity',
required=True)
animator_id = fields.Many2one('res.partner', string='Animator')
@api.onchange('activity_id')
def onchange_activity_id(self):
for s in self:
if not s.animator_id:
s.animator_id = s.activity_id.animator_id
is_recurrent = fields.Boolean('Is recurrent ?', default=True,
help='Work in progress')
date_start = fields.Datetime('Start date')
date_end = fields.Datetime('End date')
@api.onchange('date_start')
def onchange_date_start(self):
""" Sets end date to start date if no start date """
for s in self:
if not s.date_end:
s.date_end = s.date_start
@api.constrains('date_start', 'date_end')
def _check_date_period(self):
""" Check if end date if after start date and if dates are included
into main activity period"""
for s in self:
if not s.is_recurrent:
if s.date_start > s.date_end:
emsg = _('Start of the session cannot be after end of the '
'period.')
raise models.ValidationError(emsg)
if s.date_start < s.activity_id.date_start:
emsg = _('Start of the session cannot be before the start '
'of activity date')
raise models.ValidationError(emsg)
if s.date_end > s.activity_id.date_end:
emsg = _('End of the session cannot be after the end of '
'activity date')
raise models.ValidationError(emsg)
weekday = fields.Selection([('mon', _('Monday')),
('tue', _('Tuesday')),
('wed', _('Wednesday')),
@ -84,8 +120,15 @@ class GolemActivitySession(models.Model):
hour_start = fields.Float('Start time')
hour_end = fields.Float('End time')
@api.onchange('hour_start')
def onchange_hour_start(self):
""" Sets end hour to start hour if no start hour """
for s in self:
if not s.hour_end:
s.hour_end = s.hour_start
@api.constrains('hour_start', 'hour_end')
def _check_period(self):
def _check_hour_period(self):
""" Check if end hour if after start hour """
for s in self:
if s.hour_start > s.hour_end:

View File

@ -27,7 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<div name="buttons" position="inside">
<button class="oe_inline oe_stat_button" type="object"
name="button_session" icon="fa-list">
<field string="Week sessions" name="session_count" widget="statinfo" />
<field string="Sessions" name="session_count"
widget="statinfo" />
</button>
</div>
</field>
@ -50,10 +51,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
attrs="{'invisible': [('is_overbooked', '=', False)]}" />
</group>
<group>
<field name="is_recurrent" readonly="True" />
<field name="weekday" />
<field name="hour_start" widget="float_time" />
<field name="hour_end" widget="float_time" />
<field name="is_recurrent" />
<field name="weekday"
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
<field name="hour_start" widget="float_time"
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
<field name="hour_end" widget="float_time"
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
<field name="date_start"
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
<field name="date_end"
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
</group>
</group>
<notebook>
@ -80,11 +88,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<tree colors="darkgrey: places_used &lt; places_min;
red: places_remain == 0;
orange: places_remain &lt;= 4;">
<field name="is_recurrent" invisible="True" />
<field name="activity_id" />
<field name="animator_id" />
<field name="weekday" string="Day" />
<field name="hour_start" string="Start" />
<field name="hour_end" string="End" />
<field name="weekday" string="Day"
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
<field name="hour_start" string="Hour"
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
<field name="date_start" string="Date"
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
<field name="places" />
<field name="places_min" string="Min." />
<field name="places_remain" string="Remain" />