diff --git a/golem_activity_session_registration_state/__init__.py b/golem_activity_session_registration_state/__init__.py new file mode 100644 index 0000000..2fca3d2 --- /dev/null +++ b/golem_activity_session_registration_state/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +from . import models diff --git a/golem_activity_session_registration_state/__openerp__.py b/golem_activity_session_registration_state/__openerp__.py new file mode 100644 index 0000000..c516eb9 --- /dev/null +++ b/golem_activity_session_registration_state/__openerp__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +{ + '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'] +} diff --git a/golem_activity_session_registration_state/models/__init__.py b/golem_activity_session_registration_state/models/__init__.py new file mode 100644 index 0000000..23e71d3 --- /dev/null +++ b/golem_activity_session_registration_state/models/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +from . import golem_activity_session_registration diff --git a/golem_activity_session_registration_state/models/golem_activity_session_registration.py b/golem_activity_session_registration_state/models/golem_activity_session_registration.py new file mode 100644 index 0000000..942dca4 --- /dev/null +++ b/golem_activity_session_registration_state/models/golem_activity_session_registration.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- + +# copyright 2016 fabien bourgeois +# +# 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 . + +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 diff --git a/golem_activity_session_registration_state/views/golem_activity_session_registration_view.xml b/golem_activity_session_registration_state/views/golem_activity_session_registration_view.xml new file mode 100644 index 0000000..351eb91 --- /dev/null +++ b/golem_activity_session_registration_state/views/golem_activity_session_registration_view.xml @@ -0,0 +1,55 @@ + + + + + + + + Session registration list + golem.activity.session.registration + + + + red: state == 'canceled';darkgrey: state == 'draft'; + + + + + + + + + + + + + + Registration state specific searches + golem.activity.session.registration + + + + + + + + + + diff --git a/golem_activity_session_registration_state/views/golem_activity_view.xml b/golem_activity_session_registration_state/views/golem_activity_view.xml new file mode 100644 index 0000000..afe2ee5 --- /dev/null +++ b/golem_activity_session_registration_state/views/golem_activity_view.xml @@ -0,0 +1,41 @@ + + + + + + + + Activity Registrations States + golem.activity.session + + + + red: state == 'canceled';darkgrey: state == 'draft'; + + + + + + + + + + + + diff --git a/golem_activity_session_registration_state/views/golem_member_view.xml b/golem_activity_session_registration_state/views/golem_member_view.xml new file mode 100644 index 0000000..3729116 --- /dev/null +++ b/golem_activity_session_registration_state/views/golem_member_view.xml @@ -0,0 +1,56 @@ + + + + + + + + Add state for sessions registrations + golem.member + + +

+

+ Note that you can't register activities if the member is new and not yet saved into the database. +

+

+ +