forked from Yaltik/golem
[ADD]GOLEM Activities Sessions inscriptions for members, places management...
This commit is contained in:
parent
b2a1e86e67
commit
c263fc84ee
@ -36,30 +36,6 @@ class GolemActivity(models.Model):
|
|||||||
required=True)
|
required=True)
|
||||||
animator_id = fields.Many2one('res.partner', string="Animator",
|
animator_id = fields.Many2one('res.partner', string="Animator",
|
||||||
domain=[('is_company', '=', False)])
|
domain=[('is_company', '=', False)])
|
||||||
places = fields.Integer('Places', default=0)
|
|
||||||
is_overbooked = fields.Boolean('Allow overbook?', default=False)
|
|
||||||
places_overbooked = fields.Integer('Places with overbook', default=0)
|
|
||||||
|
|
||||||
@api.onchange('is_overbooked', 'places')
|
|
||||||
def onchange_is_overbooked(self):
|
|
||||||
for a in self:
|
|
||||||
if a.places and a.is_overbooked:
|
|
||||||
if not a.places_overbooked or (a.places_overbooked < a.places):
|
|
||||||
a.places_overbooked = a.places + 1
|
|
||||||
|
|
||||||
@api.constrains('places', 'places_overbooked')
|
|
||||||
def _check_places(self):
|
|
||||||
""" Check integers are signed and overbooked to be superior than
|
|
||||||
normal places """
|
|
||||||
for v in self:
|
|
||||||
for f in ['places', 'places_overbooked']:
|
|
||||||
if v[f] < 0:
|
|
||||||
emsg = _('Number of places cannot be negative.')
|
|
||||||
raise models.ValidationError(emsg)
|
|
||||||
if v.is_overbooked and (v.places_overbooked <= v.places):
|
|
||||||
emsg = _('Overbooked places cannot be inferior than places')
|
|
||||||
raise models.ValidationError(emsg)
|
|
||||||
|
|
||||||
date_start = fields.Date('Start date')
|
date_start = fields.Date('Start date')
|
||||||
date_end = fields.Date('End date')
|
date_end = fields.Date('End date')
|
||||||
|
|
||||||
|
@ -42,14 +42,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<group colspan="2">
|
<group colspan="2">
|
||||||
<field name="default_code" />
|
<field name="default_code" />
|
||||||
<field name="categ_id" />
|
<field name="categ_id" />
|
||||||
<field name="animator_id" />
|
|
||||||
<field name="list_price" />
|
<field name="list_price" />
|
||||||
</group>
|
</group>
|
||||||
<group colspan="2">
|
<group colspan="2">
|
||||||
<field name="places" />
|
<field name="animator_id" />
|
||||||
<field name="is_overbooked" />
|
|
||||||
<field name="places_overbooked"
|
|
||||||
attrs="{'invisible': [('is_overbooked', '=', False)]}" />
|
|
||||||
<field name="date_start" />
|
<field name="date_start" />
|
||||||
<field name="date_end" />
|
<field name="date_end" />
|
||||||
</group>
|
</group>
|
||||||
|
@ -26,5 +26,5 @@
|
|||||||
'application': False,
|
'application': False,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'depends': ['golem_activity'],
|
'depends': ['golem_activity'],
|
||||||
'data': ['views/golem_activity_view.xml']
|
'data': ['views/golem_activity_view.xml', 'views/golem_member_view.xml']
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,13 @@
|
|||||||
from openerp import models, fields, api, _
|
from openerp import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
|
class GolemMember(models.Model):
|
||||||
|
_inherit = 'golem.member'
|
||||||
|
|
||||||
|
activity_session_ids = fields.Many2many('golem.activity.session',
|
||||||
|
string='Activities')
|
||||||
|
|
||||||
|
|
||||||
class GolemActivity(models.Model):
|
class GolemActivity(models.Model):
|
||||||
_inherit = 'golem.activity'
|
_inherit = 'golem.activity'
|
||||||
|
|
||||||
@ -53,12 +60,12 @@ class GolemActivitySession(models.Model):
|
|||||||
for s in self:
|
for s in self:
|
||||||
s.name = s.activity_id.activity_name
|
s.name = s.activity_id.activity_name
|
||||||
|
|
||||||
# TODO: reucrrence etc... to link with calendar.event
|
member_ids = fields.Many2many('golem.member', string='Members')
|
||||||
|
# TODO: recurrence etc... to link with calendar.event
|
||||||
activity_id = fields.Many2one('golem.activity', string='Activité',
|
activity_id = fields.Many2one('golem.activity', string='Activité',
|
||||||
required=True)
|
required=True)
|
||||||
animator_id = fields.Many2one('res.partner', string='Animator',
|
animator_id = fields.Many2one('res.partner', string='Animator')
|
||||||
required=True)
|
is_recurrent = fields.Boolean('Is recurrent ?', default=True,
|
||||||
is_recurrent = fields.Boolean('Is recurrent ?', default=False,
|
|
||||||
help="Work in progress")
|
help="Work in progress")
|
||||||
weekday = fields.Selection([('mon', _('Monday')),
|
weekday = fields.Selection([('mon', _('Monday')),
|
||||||
('tue', _('Tuesday')),
|
('tue', _('Tuesday')),
|
||||||
@ -69,7 +76,6 @@ class GolemActivitySession(models.Model):
|
|||||||
('sun', _('Sunday'))])
|
('sun', _('Sunday'))])
|
||||||
hour_start = fields.Float('Start time')
|
hour_start = fields.Float('Start time')
|
||||||
hour_end = fields.Float('End time')
|
hour_end = fields.Float('End time')
|
||||||
note = fields.Text('Note')
|
|
||||||
|
|
||||||
@api.constrains('hour_start', 'hour_end')
|
@api.constrains('hour_start', 'hour_end')
|
||||||
def _check_period(self):
|
def _check_period(self):
|
||||||
@ -78,3 +84,48 @@ class GolemActivitySession(models.Model):
|
|||||||
if s.hour_start > s.hour_end:
|
if s.hour_start > s.hour_end:
|
||||||
raise models.ValidationError(_('Start of the period cannot be '
|
raise models.ValidationError(_('Start of the period cannot be '
|
||||||
'after end of the period.'))
|
'after end of the period.'))
|
||||||
|
|
||||||
|
places = fields.Integer('Places', default=0)
|
||||||
|
is_overbooked = fields.Boolean('Allow overbook?', default=False)
|
||||||
|
places_overbooked = fields.Integer('Places with overbook', default=0)
|
||||||
|
places_remain = fields.Integer('Remaining places', store=True,
|
||||||
|
compute='_compute_places_remain')
|
||||||
|
|
||||||
|
@api.depends('places', 'is_overbooked', 'places_overbooked', 'member_ids')
|
||||||
|
def _compute_places_remain(self):
|
||||||
|
for s in self:
|
||||||
|
used = len(s.member_ids)
|
||||||
|
if not s.is_overbooked:
|
||||||
|
s.places_remain = s.places - used
|
||||||
|
else:
|
||||||
|
s.places_remain = s.places_overbooked - used
|
||||||
|
|
||||||
|
@api.constrains('places_remain')
|
||||||
|
def _check_remaining_places(self):
|
||||||
|
""" Forbid inscription when there is no more place """
|
||||||
|
for s in self:
|
||||||
|
if s.places_remain < 0:
|
||||||
|
emsg = _('Sorry, there is no more place !')
|
||||||
|
raise models.ValidationError(emsg)
|
||||||
|
|
||||||
|
@api.onchange('is_overbooked', 'places')
|
||||||
|
def onchange_is_overbooked(self):
|
||||||
|
for s in self:
|
||||||
|
if s.places and s.is_overbooked:
|
||||||
|
if not s.places_overbooked or (s.places_overbooked < s.places):
|
||||||
|
s.places_overbooked = s.places + 1
|
||||||
|
|
||||||
|
@api.constrains('places', 'places_overbooked')
|
||||||
|
def _check_places(self):
|
||||||
|
""" Check integers are signed and overbooked to be superior than
|
||||||
|
normal places """
|
||||||
|
for v in self:
|
||||||
|
for f in ['places', 'places_overbooked']:
|
||||||
|
if v[f] < 0:
|
||||||
|
emsg = _('Number of places cannot be negative.')
|
||||||
|
raise models.ValidationError(emsg)
|
||||||
|
if v.is_overbooked and (v.places_overbooked <= v.places):
|
||||||
|
emsg = _('Overbooked places cannot be inferior than places')
|
||||||
|
raise models.ValidationError(emsg)
|
||||||
|
|
||||||
|
note = fields.Text('Note')
|
||||||
|
@ -43,6 +43,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<group>
|
<group>
|
||||||
<field name="activity_id" />
|
<field name="activity_id" />
|
||||||
<field name="animator_id" />
|
<field name="animator_id" />
|
||||||
|
<field name="places" />
|
||||||
|
<field name="is_overbooked" />
|
||||||
|
<field name="places_overbooked"
|
||||||
|
attrs="{'invisible': [('is_overbooked', '=', False)]}" />
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="is_recurrent" readonly="True" />
|
<field name="is_recurrent" readonly="True" />
|
||||||
@ -51,16 +55,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="hour_end" widget="float_time" />
|
<field name="hour_end" widget="float_time" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<notebook>
|
||||||
<field name="note" />
|
<page string="Members">
|
||||||
</group>
|
<group>
|
||||||
|
<field name="places_remain" readonly="True" />
|
||||||
|
<field name="member_ids" />
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
<page string="Note">
|
||||||
|
<field name="note" />
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Tree -->
|
<!-- Tree -->
|
||||||
<record id="family_tree" model="ir.ui.view">
|
<record id="session_tree" model="ir.ui.view">
|
||||||
<field name="name">Session list</field>
|
<field name="name">Session list</field>
|
||||||
<field name="model">golem.activity.session</field>
|
<field name="model">golem.activity.session</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
36
golem_activity_session/views/golem_member_view.xml
Normal file
36
golem_activity_session/views/golem_member_view.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
-->
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- Form -->
|
||||||
|
<record model="ir.ui.view" id="sessions_inscription">
|
||||||
|
<field name="name">Add sessions inscriptions to member form</field>
|
||||||
|
<field name="model">golem.member</field>
|
||||||
|
<field name="inherit_id" ref="golem_member.view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<page name="other_page" position="after">
|
||||||
|
<page name="sessions" string="Activities">
|
||||||
|
<field name="activity_session_ids" />
|
||||||
|
</page>
|
||||||
|
</page>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue
Block a user