[IMP]GOLEM Activity Registrations migration from sessions to new pure activities

This commit is contained in:
Fabien Bourgeois 2016-10-10 17:51:42 +02:00
parent 22d3f91e0c
commit d1db9ae3b6
10 changed files with 72 additions and 68 deletions

View File

@ -49,17 +49,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<notebook>
<page string="Session">
<group>
<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_stop"
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
<group name="dates">
<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_stop"
attrs="{'invisible': [('is_recurrent', '=', True)]}" />
</group>
<group name="places">
</group>
</group>
</page>
<page name="activity_info" string="Information">

View File

@ -16,17 +16,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
'name': 'GOLEM Activity Session Member Registrations',
'summary': 'GOLEM Activities Session Member Registrations management',
'description': ''' Non-profit french MJC activities session member
registrations management ''',
'name': 'GOLEM Activity Member Registrations',
'summary': 'GOLEM Activities Member Registrations management',
'description': ''' Non-profit french MJC activity member registrations
management ''',
'version': '0.1',
'category': 'GOLEM',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': ['golem_activity_session', 'golem_member'],
'depends': ['golem_activity', 'golem_member'],
'data': ['views/golem_activity_session_registration_view.xml',
'views/golem_member_view.xml', 'views/golem_activity_view.xml']
}

View File

@ -21,25 +21,25 @@ from openerp import models, fields, api, _
class GolemMember(models.Model):
_inherit = 'golem.member'
activity_session_registration_ids = fields.One2many(
'golem.activity.session.registration', 'member_id', 'Activities')
activity_registration_ids = fields.One2many('golem.activity.registration',
'member_id', 'Activities')
class GolemActivitySession(models.Model):
_inherit = 'golem.activity.session'
_sql_constraints = [('golem_activity_session_places_signed',
class GolemActivity(models.Model):
_inherit = 'golem.activity'
_sql_constraints = [('golem_activity_places_signed',
'CHECK (places >= 0)',
_('Number of places cannot be negative.'))]
activity_session_registration_ids = fields.One2many(
'golem.activity.session.registration', 'session_id', 'Members')
activity_registration_ids = fields.One2many('golem.activity.registration',
'activity_id', 'Members')
places_used = fields.Integer('Places used', compute='_compute_places_used',
store=True)
@api.one
@api.depends('activity_session_registration_ids')
@api.depends('activity_registration_ids')
def _compute_places_used(self):
self.places_used = len(self.activity_session_registration_ids)
self.places_used = len(self.activity_registration_ids)
places = fields.Integer('Places', default=20)
places_remain = fields.Integer('Remaining places', store=True,
@ -59,29 +59,29 @@ class GolemActivitySession(models.Model):
raise models.ValidationError(emsg)
class GolemActivitySessionRegistration(models.Model):
_name = 'golem.activity.session.registration'
_description = 'GOLEM Activity Session Registration'
class GolemActivityRegistration(models.Model):
_name = 'golem.activity.registration'
_description = 'GOLEM Activity Registration'
member_id = fields.Many2one('golem.member', string='Member', required=True,
ondelete='cascade')
session_id = fields.Many2one('golem.activity.session', required=True,
string='Activity session', ondelete='cascade')
activity_id = fields.Many2one('golem.activity', required=True,
string='Activity', ondelete='cascade')
season_id = fields.Many2one(string='Season',
related='session_id.season_id')
related='activity_id.season_id')
is_current = fields.Boolean('Current season?',
related='session_id.is_current')
related='activity_id.is_current')
_sql_constraints = [
('registration_uniq', 'UNIQUE (member_id, session_id)',
_('This member has already been registered for this session.'))]
('registration_uniq', 'UNIQUE (member_id, activity_id)',
_('This member has already been registered for this activity.'))]
@api.constrains('member_id', 'session_id')
@api.constrains('member_id', 'activity_id')
def _check_season_reliability(self):
""" Forbid registration when member season if not coherent with
session season or are duplicates """
activity season or are duplicates """
for r in self:
if r.session_id.season_id not in r.member_id.season_ids:
if r.activity_id.season_id not in r.member_id.season_ids:
emsg = _('Subscription can not be executed : the targeted '
'member is not on the same season as the session.')
'member is not on the same season as the activity.')
raise models.ValidationError(emsg)

View File

@ -19,14 +19,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<data>
<!-- Form -->
<record id="registration_form" model="ir.ui.view">
<field name="name">Session registration form</field>
<field name="model">golem.activity.session.registration</field>
<field name="name">Activity registration form</field>
<field name="model">golem.activity.registration</field>
<field name="arch" type="xml">
<form>
<sheet>
<group string="Subscription">
<field name="member_id" invisible="1" />
<field name="session_id" />
<field name="activity_id" />
<field name="season_id" />
</group>
</sheet>
@ -37,26 +37,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Tree -->
<record id="registration_tree" model="ir.ui.view">
<field name="name">Session registration list</field>
<field name="model">golem.activity.session.registration</field>
<field name="name">Activity registration list</field>
<field name="model">golem.activity.registration</field>
<field name="arch" type="xml">
<tree create="true" edit="false" delete="false" editable="top">
<field name="season_id" readonly="1" />
<field name="member_id" domain="[('is_current', '=', True)]" />
<field name="session_id" domain="[('is_current', '=', True)]" />
<field name="activity_id" domain="[('is_current', '=', True)]" />
</tree>
</field>
</record>
<!-- Search -->
<record id="searches" model="ir.ui.view">
<field name="name">GOLEM Activity Session Registration searches</field>
<field name="model">golem.activity.session.registration</field>
<field name="name">GOLEM Activity Registration searches</field>
<field name="model">golem.activity.registration</field>
<field name="arch" type="xml">
<search>
<field name="season_id" widget="many2one" />
<field name="member_id" widget="many2one" />
<field name="session_id" widget="many2one" />
<field name="activity_id" widget="many2one" />
<filter name="season_default" string="Default season"
domain="[('is_current', '=', True)]" />
</search>
@ -65,14 +65,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Action -->
<record id="registration_action_list" model="ir.actions.act_window">
<field name="name">GOLEM Activity Session Registration List</field>
<field name="res_model">golem.activity.session.registration</field>
<field name="name">GOLEM Activity Registration List</field>
<field name="res_model">golem.activity.registration</field>
<field name="view_mode">tree</field>
<field name="context">{'search_default_season_default': True}</field>
</record>
<!-- Menu -->
<menuitem id="registration_menu_list" name="Session registrations"
<menuitem id="registration_menu_list" name="Acitivity registrations"
parent="golem_activity.activity_menu" action="registration_action_list"
groups="golem_base.group_golem_user"
sequence="20" />

View File

@ -21,22 +21,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- 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="model">golem.activity</field>
<field name="inherit_id" ref="golem_activity.view_form" />
<field name="arch" type="xml">
<field name="type_of" position="after">
<group name="places" position="inside">
<field name="places" />
</field>
<page string="Service" position="before">
</group>
<page string="Session" position="after">
<page string="Members">
<group>
<field name="places_remain" readonly="True" />
<field name="activity_session_registration_ids"
context="{'default_session_id': active_id}">
<field name="activity_registration_ids"
context="{'default_activity_id': active_id}">
<tree editable="top">
<field name="member_id"
domain="[('season_ids', '=', season_id)]" />
<field name="session_id" readonly="1" />
<field name="activity_id" readonly="1" />
<field name="season_id" readonly="1" />
</tree>
</field>
@ -49,8 +49,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- 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="model">golem.activity</field>
<field name="inherit_id" ref="golem_activity.view_tree" />
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="colors">red: places_remain == 0;orange: places_remain &lt;= 4;</attribute>
@ -65,11 +65,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- 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="model">golem.activity</field>
<field name="inherit_id" ref="golem_activity.view_filter" />
<field name="arch" type="xml">
<filter name="season_default" position="after">
<filter name="full_session" string="Full"
<filter name="full_activity" string="Full"
domain="[('places_remain', '=', 0)]" />
</filter>
</field>

View File

@ -19,21 +19,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<data>
<!-- Form -->
<record model="ir.ui.view" id="sessions_registration">
<field name="name">Add sessions registrations to member form</field>
<record model="ir.ui.view" id="activities_registration">
<field name="name">Add activities registrations 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="before">
<page name="sessions" string="Activities">
<page name="activities" string="Activities">
<p name="default_season_label">Default season activities</p>
<field name="id" invisible="1" />
<group>
<field name="activity_session_registration_ids"
<field name="activity_registration_ids"
attrs="{'readonly': [('id', '=', False)]}"
context="{'default_member_id': active_id}">
<tree editable="top">
<field name="session_id"
<field name="activity_id"
domain="[('is_current', '=', True)]" />
<field name="season_id" readonly="1" />
<field name="member_id" readonly="1" />