[ADD][WIP]GOLEM Activity Session Registration States management
This commit is contained in:
parent
9dc2228bc4
commit
bd9b795c4f
18
golem_activity_session_registration_state/__init__.py
Normal file
18
golem_activity_session_registration_state/__init__.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: 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/>.
|
||||||
|
|
||||||
|
from . import models
|
32
golem_activity_session_registration_state/__openerp__.py
Normal file
32
golem_activity_session_registration_state/__openerp__.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: 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/>.
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'GOLEM Activity Session Member Registrations States',
|
||||||
|
'summary': 'GOLEM Activities Session Member Registration states',
|
||||||
|
'description': ''' Non-profit french MJC activities session member
|
||||||
|
registration states management ''',
|
||||||
|
'version': '0.1',
|
||||||
|
'category': 'GOLEM',
|
||||||
|
'author': 'Fabien Bourgeois',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'application': False,
|
||||||
|
'installable': True,
|
||||||
|
'depends': ['golem_activity_session_registration'],
|
||||||
|
'data': ['views/golem_activity_session_registration_view.xml',
|
||||||
|
'views/golem_member_view.xml', 'views/golem_activity_view.xml']
|
||||||
|
}
|
18
golem_activity_session_registration_state/models/__init__.py
Normal file
18
golem_activity_session_registration_state/models/__init__.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: 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/>.
|
||||||
|
|
||||||
|
from . import golem_activity_session_registration
|
@ -0,0 +1,94 @@
|
|||||||
|
# -*- coding: 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/>.
|
||||||
|
|
||||||
|
from openerp import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
|
class GolemMember(models.Model):
|
||||||
|
_inherit = 'golem.member'
|
||||||
|
|
||||||
|
has_draft_registrations = fields.Boolean(
|
||||||
|
'Has draft registrations ?',
|
||||||
|
compute='_compute_has_draft_registrations')
|
||||||
|
|
||||||
|
@api.one
|
||||||
|
@api.depends('activity_session_registration_ids')
|
||||||
|
def _compute_has_draft_registrations(self):
|
||||||
|
""" Check if there are draft states in member activities """
|
||||||
|
for r in self.activity_session_registration_ids:
|
||||||
|
if r.state == 'draft':
|
||||||
|
self.has_draft_registrations = True
|
||||||
|
return
|
||||||
|
self.has_draft_registrations = False
|
||||||
|
|
||||||
|
@api.one
|
||||||
|
def do_validate_registrations(self):
|
||||||
|
""" Validate all draft registrations """
|
||||||
|
draft_registrations = self.activity_session_registration_ids.filtered(
|
||||||
|
lambda r: r.state == 'draft')
|
||||||
|
draft_registrations.write({'state': 'confirmed'})
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def write(self, values):
|
||||||
|
""" Handle removed activities to be canceled """
|
||||||
|
if 'activity_session_registration_ids' in values:
|
||||||
|
rids = values['activity_session_registration_ids']
|
||||||
|
r_keep, r_removed = [], []
|
||||||
|
for r in rids: # == 2 is removal case
|
||||||
|
r_removed.append(r) if r[0] == 2 else r_keep.append(r)
|
||||||
|
rObj = self.env['golem.activity.session.registration']
|
||||||
|
for rem in r_removed:
|
||||||
|
r = rObj.browse([rem[1]])
|
||||||
|
# if already canceled, let it be removed, else cancel it
|
||||||
|
if r.state != 'canceled':
|
||||||
|
r.state = 'canceled'
|
||||||
|
else:
|
||||||
|
r_keep.append(rem)
|
||||||
|
values['activity_session_registration_ids'] = r_keep
|
||||||
|
return super(GolemMember, self).write(values)
|
||||||
|
|
||||||
|
|
||||||
|
class GolemActivitySession(models.Model):
|
||||||
|
_inherit = 'golem.activity.session'
|
||||||
|
|
||||||
|
@api.one
|
||||||
|
@api.depends('activity_session_registration_ids')
|
||||||
|
def _compute_places_used(self):
|
||||||
|
rids = self.activity_session_registration_ids
|
||||||
|
self.places_used = len(rids.filtered(lambda r: r.state == 'confirmed'))
|
||||||
|
|
||||||
|
|
||||||
|
class GolemActivitySessionRegistration(models.Model):
|
||||||
|
_inherit = 'golem.activity.session.registration'
|
||||||
|
|
||||||
|
state = fields.Selection([('draft', 'Draft'), ('confirmed', 'Confirmed'),
|
||||||
|
('canceled', 'Canceled')], required=True,
|
||||||
|
default='draft')
|
||||||
|
invoice_id = fields.Many2one('account.invoice', string='Invoice',
|
||||||
|
ondelete='set null')
|
||||||
|
invoice_line_id = fields.Many2one('account.invoice.line',
|
||||||
|
string='Invoice line',
|
||||||
|
ondelete='set null')
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def write(self, values):
|
||||||
|
""" Recomputes values linked to registrations when state change """
|
||||||
|
res = super(GolemActivitySessionRegistration, self).write(values)
|
||||||
|
if values['state']:
|
||||||
|
for r in self:
|
||||||
|
r.session_id._compute_places_used()
|
||||||
|
return res
|
@ -0,0 +1,55 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<!-- Tree -->
|
||||||
|
<record id="state_tree" model="ir.ui.view">
|
||||||
|
<field name="name">Session registration list</field>
|
||||||
|
<field name="model">golem.activity.session.registration</field>
|
||||||
|
<field name="inherit_id"
|
||||||
|
ref="golem_activity_session_registration.registration_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree position="attributes">
|
||||||
|
<attribute name="colors">red: state == 'canceled';darkgrey: state == 'draft';</attribute>
|
||||||
|
</tree>
|
||||||
|
<tree position="inside">
|
||||||
|
<field name="state" invisible="1" />
|
||||||
|
</tree>
|
||||||
|
<field name="session_id" position="after">
|
||||||
|
<field name="invoice_id" readonly="1" />
|
||||||
|
<field name="invoice_line_id" readonly="1" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Search -->
|
||||||
|
<record id="state_searches" model="ir.ui.view">
|
||||||
|
<field name="name">Registration state specific searches</field>
|
||||||
|
<field name="model">golem.activity.session.registration</field>
|
||||||
|
<field name="inherit_id"
|
||||||
|
ref="golem_activity_session_registration.searches" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="session_id" position="after">
|
||||||
|
<field name="invoice_id" widget="many2one" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
@ -0,0 +1,41 @@
|
|||||||
|
<?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="state_activity_form" model="ir.ui.view">
|
||||||
|
<field name="name">Activity Registrations States</field>
|
||||||
|
<field name="model">golem.activity.session</field>
|
||||||
|
<field name="inherit_id"
|
||||||
|
ref="golem_activity_session_registration.activity_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree position="attributes">
|
||||||
|
<attribute name="colors">red: state == 'canceled';darkgrey: state == 'draft';</attribute>
|
||||||
|
</tree>
|
||||||
|
<tree position="inside">
|
||||||
|
<field name="state" invisible="1" />
|
||||||
|
</tree>
|
||||||
|
<field name="season_id" position="after">
|
||||||
|
<field name="invoice_id" readonly="1" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
@ -0,0 +1,56 @@
|
|||||||
|
<?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="registration_state">
|
||||||
|
<field name="name">Add state for sessions registrations</field>
|
||||||
|
<field name="model">golem.member</field>
|
||||||
|
<field name="inherit_id"
|
||||||
|
ref="golem_activity_session_registration.sessions_registration" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<p name="default_season_label" position="after">
|
||||||
|
<p attrs="{'invisible': [('id', '!=', False)]}" style="color:red;}">
|
||||||
|
Note that you can't register activities if the member is new and not yet saved into the database.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<field name="has_draft_registrations" invisible="1" />
|
||||||
|
<button name="do_validate_registrations" type="object"
|
||||||
|
string="Validate all draft registrations"
|
||||||
|
class="oe_highlight"
|
||||||
|
help="If you validate draft registration, they will be seen as confirmed. Then, an invoice will be created for the current member."
|
||||||
|
attrs="{'invisible': [('has_draft_registrations', '=', False)]}" />
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
<!-- TODO : one by one cancelation -->
|
||||||
|
<!-- TODO : do not allow removal if confirmed -->
|
||||||
|
<tree position="attributes">
|
||||||
|
<attribute name="colors">red: state == 'canceled';darkgrey: state == 'draft';</attribute>
|
||||||
|
</tree>
|
||||||
|
<tree position="inside">
|
||||||
|
<field name="state" invisible="1" />
|
||||||
|
</tree>
|
||||||
|
<field name="member_id" position="after">
|
||||||
|
<field name="invoice_id" readonly="1" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue
Block a user