[ADD]GOLEM Activity Session Registrations : adapt session view and move all places management to new paradigm
This commit is contained in:
parent
419feb58c5
commit
2359854ba8
@ -26,6 +26,6 @@
|
|||||||
'application': False,
|
'application': False,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': True,
|
'auto_install': True,
|
||||||
'depends': ['product', 'mail', 'golem_activity', 'golem_member'],
|
'depends': ['product', 'mail', 'golem_activity'],
|
||||||
'data': ['security/ir.model.access.csv', 'views/golem_activity_view.xml']
|
'data': ['security/ir.model.access.csv', 'views/golem_activity_view.xml']
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,6 @@ class GolemActivitySession(models.Model):
|
|||||||
_inherits = {'product.template': 'product_id'}
|
_inherits = {'product.template': 'product_id'}
|
||||||
_rec_name = 'session_name'
|
_rec_name = 'session_name'
|
||||||
|
|
||||||
_sql_constraints = [('golem_activity_session_places_signed',
|
|
||||||
'CHECK (places >= 0)',
|
|
||||||
_('Number of places cannot be negative.'))]
|
|
||||||
|
|
||||||
product_id = fields.Many2one('product.template', required=True,
|
product_id = fields.Many2one('product.template', required=True,
|
||||||
ondelete='cascade')
|
ondelete='cascade')
|
||||||
|
|
||||||
@ -87,7 +83,6 @@ class GolemActivitySession(models.Model):
|
|||||||
session_name = u'[{}] {}'.format(self.default_code, session_name)
|
session_name = u'[{}] {}'.format(self.default_code, session_name)
|
||||||
self.session_name = session_name
|
self.session_name = session_name
|
||||||
|
|
||||||
member_ids = fields.Many2many('golem.member', string='Members')
|
|
||||||
type_of = fields.Selection([('activity', _('Activity')),
|
type_of = fields.Selection([('activity', _('Activity')),
|
||||||
('workshop', _('Workshop')),
|
('workshop', _('Workshop')),
|
||||||
('training', _('Training'))],
|
('training', _('Training'))],
|
||||||
@ -101,13 +96,6 @@ class GolemActivitySession(models.Model):
|
|||||||
else:
|
else:
|
||||||
s.is_recurrent = True
|
s.is_recurrent = True
|
||||||
|
|
||||||
places_used = fields.Integer('Places used', compute='_compute_places_used')
|
|
||||||
|
|
||||||
@api.one
|
|
||||||
@api.depends('member_ids')
|
|
||||||
def _compute_places_used(self):
|
|
||||||
self.places_used = len(self.member_ids)
|
|
||||||
|
|
||||||
# TODO: to link with calendar.event
|
# TODO: to link with calendar.event
|
||||||
activity_id = fields.Many2one('golem.activity', string='Activity',
|
activity_id = fields.Many2one('golem.activity', string='Activity',
|
||||||
required=True)
|
required=True)
|
||||||
@ -184,21 +172,3 @@ 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=20)
|
|
||||||
places_remain = fields.Integer('Remaining places', store=True,
|
|
||||||
compute='_compute_places_remain')
|
|
||||||
|
|
||||||
@api.one
|
|
||||||
@api.depends('places', 'member_ids')
|
|
||||||
def _compute_places_remain(self):
|
|
||||||
used = len(self.member_ids)
|
|
||||||
self.places_remain = self.places - 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)
|
|
||||||
|
@ -49,7 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="activity_id" />
|
<field name="activity_id" />
|
||||||
<field name="animator_id" />
|
<field name="animator_id" />
|
||||||
<field name="type_of" />
|
<field name="type_of" />
|
||||||
<field name="places" />
|
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="is_recurrent" />
|
<field name="is_recurrent" />
|
||||||
@ -66,13 +65,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="Members">
|
|
||||||
<group>
|
|
||||||
<field name="places_remain" readonly="True" />
|
|
||||||
<field name="member_ids"
|
|
||||||
context="{'search_default_season_default': True}" />
|
|
||||||
</group>
|
|
||||||
</page>
|
|
||||||
<page string="Service">
|
<page string="Service">
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
@ -103,8 +95,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<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">
|
||||||
<tree colors="red: places_remain == 0;
|
<tree>
|
||||||
orange: places_remain <= 4;">
|
|
||||||
<field name="is_recurrent" invisible="True" />
|
<field name="is_recurrent" invisible="True" />
|
||||||
<field name="season_id" />
|
<field name="season_id" />
|
||||||
<field name="type_of" />
|
<field name="type_of" />
|
||||||
@ -113,8 +104,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
|
attrs="{'invisible': [('is_recurrent', '=', False)]}" />
|
||||||
<field name="date_start" string="Date"
|
<field name="date_start" string="Date"
|
||||||
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
|
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
|
||||||
<field name="places" invisible="True" />
|
|
||||||
<field name="places_remain" string="Remain" />
|
|
||||||
<field name="list_price" sum="True" />
|
<field name="list_price" sum="True" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
@ -145,8 +134,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="season_id" widget="many2one" />
|
<field name="season_id" widget="many2one" />
|
||||||
<filter name="season_default" string="Default season"
|
<filter name="season_default" string="Default season"
|
||||||
domain="[('is_current', '=', True)]" />
|
domain="[('is_current', '=', True)]" />
|
||||||
<filter name="full_session" string="Full"
|
|
||||||
domain="[('places_remain', '=', 0)]" />
|
|
||||||
<filter name="type_of_activity" string="Activity"
|
<filter name="type_of_activity" string="Activity"
|
||||||
domain="[('type_of', '=', 'activity')]" />
|
domain="[('type_of', '=', 'activity')]" />
|
||||||
<filter name="type_of_workshop" string="Workshop"
|
<filter name="type_of_workshop" string="Workshop"
|
||||||
|
@ -27,6 +27,6 @@
|
|||||||
'application': False,
|
'application': False,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
'depends': ['golem_activity_session'],
|
'depends': ['golem_activity_session_registration'],
|
||||||
'data': ['views/golem_activity_view.xml']
|
'data': ['views/golem_activity_view.xml']
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,10 @@ class GolemActivitySession(models.Model):
|
|||||||
places_overbooked = fields.Integer('Places with overbook', default=0)
|
places_overbooked = fields.Integer('Places with overbook', default=0)
|
||||||
|
|
||||||
@api.one
|
@api.one
|
||||||
@api.depends('places', 'is_overbooked', 'places_overbooked', 'member_ids')
|
@api.depends('places', 'is_overbooked', 'places_overbooked',
|
||||||
|
'activity_session_registration_ids')
|
||||||
def _compute_places_remain(self):
|
def _compute_places_remain(self):
|
||||||
used = len(self.member_ids)
|
used = len(self.activity_session_registration_ids)
|
||||||
if not self.is_overbooked:
|
if not self.is_overbooked:
|
||||||
self.places_remain = self.places - used
|
self.places_remain = self.places - used
|
||||||
else:
|
else:
|
||||||
|
@ -22,7 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<record id="view_form" model="ir.ui.view">
|
<record id="view_form" model="ir.ui.view">
|
||||||
<field name="name">GOLEM Activity Sessions Places Form additions</field>
|
<field name="name">GOLEM Activity Sessions Places Form additions</field>
|
||||||
<field name="model">golem.activity.session</field>
|
<field name="model">golem.activity.session</field>
|
||||||
<field name="inherit_id" ref="golem_activity_session.view_form" />
|
<field name="inherit_id"
|
||||||
|
ref="golem_activity_session_registration.activity_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="places" position="after">
|
<field name="places" position="after">
|
||||||
<field name="places_min" />
|
<field name="places_min" />
|
||||||
@ -37,7 +38,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<record id="session_tree" model="ir.ui.view">
|
<record id="session_tree" model="ir.ui.view">
|
||||||
<field name="name">Session list places adaptations</field>
|
<field name="name">Session list places adaptations</field>
|
||||||
<field name="model">golem.activity.session</field>
|
<field name="model">golem.activity.session</field>
|
||||||
<field name="inherit_id" ref="golem_activity_session.session_tree" />
|
<field name="inherit_id"
|
||||||
|
ref="golem_activity_session_registration.activity_tree" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree position="attributes">
|
<tree position="attributes">
|
||||||
<attribute name="colors">darkgrey: places_used < places_min; red: places_remain == 0; orange: places_remain <= 4;</attribute>
|
<attribute name="colors">darkgrey: places_used < places_min; red: places_remain == 0; orange: places_remain <= 4;</attribute>
|
||||||
@ -49,18 +51,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Searches -->
|
|
||||||
<record id="searches" model="ir.ui.view">
|
|
||||||
<field name="name">GOLEM Activity Sessions Searches</field>
|
|
||||||
<field name="model">golem.activity.session</field>
|
|
||||||
<field name="inherit_id" ref="golem_activity_session.searches" />
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<search>
|
|
||||||
<filter name="full_session" string="Full"
|
|
||||||
domain="[('places_remain', '=', 0)]" />
|
|
||||||
</search>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
@ -28,5 +28,5 @@
|
|||||||
'installable': True,
|
'installable': True,
|
||||||
'depends': ['golem_activity_session', 'golem_member'],
|
'depends': ['golem_activity_session', 'golem_member'],
|
||||||
'data': ['views/golem_activity_session_registration_view.xml',
|
'data': ['views/golem_activity_session_registration_view.xml',
|
||||||
'views/golem_member_view.xml']
|
'views/golem_member_view.xml', 'views/golem_activity_view.xml']
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# you should have received a copy of the gnu affero general public license
|
# 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/>.
|
# along with this program. if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from openerp import models, fields, api
|
from openerp import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
class GolemMember(models.Model):
|
class GolemMember(models.Model):
|
||||||
@ -25,6 +25,40 @@ class GolemMember(models.Model):
|
|||||||
'golem.activity.session.registration', 'member_id', 'Activities')
|
'golem.activity.session.registration', 'member_id', 'Activities')
|
||||||
|
|
||||||
|
|
||||||
|
class GolemActivitySession(models.Model):
|
||||||
|
_inherit = 'golem.activity.session'
|
||||||
|
_sql_constraints = [('golem_activity_session_places_signed',
|
||||||
|
'CHECK (places >= 0)',
|
||||||
|
_('Number of places cannot be negative.'))]
|
||||||
|
|
||||||
|
activity_session_registration_ids = fields.One2many(
|
||||||
|
'golem.activity.session.registration', 'session_id', 'Members')
|
||||||
|
places_used = fields.Integer('Places used', compute='_compute_places_used')
|
||||||
|
|
||||||
|
@api.one
|
||||||
|
@api.depends('activity_session_registration_ids')
|
||||||
|
def _compute_places_used(self):
|
||||||
|
self.places_used = len(self.activity_session_registration_ids)
|
||||||
|
|
||||||
|
places = fields.Integer('Places', default=20)
|
||||||
|
places_remain = fields.Integer('Remaining places', store=True,
|
||||||
|
compute='_compute_places_remain')
|
||||||
|
|
||||||
|
@api.one
|
||||||
|
@api.depends('places', 'activity_session_registration_ids')
|
||||||
|
def _compute_places_remain(self):
|
||||||
|
used = len(self.activity_session_registration_ids)
|
||||||
|
self.places_remain = self.places - 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)
|
||||||
|
|
||||||
|
|
||||||
class GolemActivitySessionRegistration(models.Model):
|
class GolemActivitySessionRegistration(models.Model):
|
||||||
_name = 'golem.activity.session.registration'
|
_name = 'golem.activity.session.registration'
|
||||||
_description = 'GOLEM Activity Session Registration'
|
_description = 'GOLEM Activity Session Registration'
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
<?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 id="activity_form" model="ir.ui.view">
|
||||||
|
<field name="name">Activity Registrations and Places</field>
|
||||||
|
<field name="model">golem.activity.session</field>
|
||||||
|
<field name="inherit_id" ref="golem_activity_session.view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="type_of" position="after">
|
||||||
|
<field name="places" />
|
||||||
|
</field>
|
||||||
|
<page string="Service" position="before">
|
||||||
|
<page string="Members">
|
||||||
|
<group>
|
||||||
|
<field name="places_remain" readonly="True" />
|
||||||
|
<field name="activity_session_registration_ids" />
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</page>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Tree -->
|
||||||
|
<record id="activity_tree" model="ir.ui.view">
|
||||||
|
<field name="name">Activity Tree registrations additions</field>
|
||||||
|
<field name="model">golem.activity.session</field>
|
||||||
|
<field name="inherit_id" ref="golem_activity_session.session_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree position="attributes">
|
||||||
|
<attribute name="colors">red: places_remain == 0;orange: places_remain <= 4;</attribute>
|
||||||
|
</tree>
|
||||||
|
<field name="date_start" position="after">
|
||||||
|
<field name="places" invisible="True" />
|
||||||
|
<field name="places_remain" string="Remain" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Search -->
|
||||||
|
<record id="activity_search" model="ir.ui.view">
|
||||||
|
<field name="name">Activity Search registrations additions</field>
|
||||||
|
<field name="model">golem.activity.session</field>
|
||||||
|
<field name="inherit_id" ref="golem_activity_session.searches" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<filter name="season_default" position="after">
|
||||||
|
<filter name="full_session" string="Full"
|
||||||
|
domain="[('places_remain', '=', 0)]" />
|
||||||
|
</filter>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue
Block a user