diff --git a/golem_activity_session/__openerp__.py b/golem_activity_session/__openerp__.py index 72ace2c..b8ba374 100644 --- a/golem_activity_session/__openerp__.py +++ b/golem_activity_session/__openerp__.py @@ -26,6 +26,6 @@ 'application': False, 'installable': 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'] } diff --git a/golem_activity_session/models/golem_activity_session.py b/golem_activity_session/models/golem_activity_session.py index de4624b..1f8cb60 100644 --- a/golem_activity_session/models/golem_activity_session.py +++ b/golem_activity_session/models/golem_activity_session.py @@ -58,10 +58,6 @@ class GolemActivitySession(models.Model): _inherits = {'product.template': 'product_id'} _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, ondelete='cascade') @@ -87,7 +83,6 @@ class GolemActivitySession(models.Model): session_name = u'[{}] {}'.format(self.default_code, session_name) self.session_name = session_name - member_ids = fields.Many2many('golem.member', string='Members') type_of = fields.Selection([('activity', _('Activity')), ('workshop', _('Workshop')), ('training', _('Training'))], @@ -101,13 +96,6 @@ class GolemActivitySession(models.Model): else: 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 activity_id = fields.Many2one('golem.activity', string='Activity', required=True) @@ -184,21 +172,3 @@ class GolemActivitySession(models.Model): if s.hour_start > s.hour_end: raise models.ValidationError(_('Start of the period cannot be ' '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) diff --git a/golem_activity_session/views/golem_activity_view.xml b/golem_activity_session/views/golem_activity_view.xml index a1a8e1f..ecaf3f7 100644 --- a/golem_activity_session/views/golem_activity_view.xml +++ b/golem_activity_session/views/golem_activity_view.xml @@ -49,7 +49,6 @@ along with this program. If not, see . - @@ -66,13 +65,6 @@ along with this program. If not, see . - - - - - - @@ -103,8 +95,7 @@ along with this program. If not, see . Session list golem.activity.session - + @@ -113,8 +104,6 @@ along with this program. If not, see . attrs="{'invisible': [('is_recurrent', '=', False)]}" /> - - @@ -145,8 +134,6 @@ along with this program. If not, see . - . GOLEM Activity Sessions Places Form additions golem.activity.session - + @@ -37,7 +38,8 @@ along with this program. If not, see . Session list places adaptations golem.activity.session - + darkgrey: places_used < places_min; red: places_remain == 0; orange: places_remain <= 4; @@ -49,18 +51,5 @@ along with this program. If not, see . - - - GOLEM Activity Sessions Searches - golem.activity.session - - - - - - - - diff --git a/golem_activity_session_registration/__openerp__.py b/golem_activity_session_registration/__openerp__.py index 03335b1..1f5b8a5 100644 --- a/golem_activity_session_registration/__openerp__.py +++ b/golem_activity_session_registration/__openerp__.py @@ -28,5 +28,5 @@ 'installable': True, 'depends': ['golem_activity_session', 'golem_member'], 'data': ['views/golem_activity_session_registration_view.xml', - 'views/golem_member_view.xml'] + 'views/golem_member_view.xml', 'views/golem_activity_view.xml'] } diff --git a/golem_activity_session_registration/models/golem_activity_session_registration.py b/golem_activity_session_registration/models/golem_activity_session_registration.py index 3414847..521e2de 100644 --- a/golem_activity_session_registration/models/golem_activity_session_registration.py +++ b/golem_activity_session_registration/models/golem_activity_session_registration.py @@ -15,7 +15,7 @@ # 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 +from openerp import models, fields, api, _ class GolemMember(models.Model): @@ -25,6 +25,40 @@ class GolemMember(models.Model): '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): _name = 'golem.activity.session.registration' _description = 'GOLEM Activity Session Registration' diff --git a/golem_activity_session_registration/views/golem_activity_view.xml b/golem_activity_session_registration/views/golem_activity_view.xml new file mode 100644 index 0000000..f62e8bb --- /dev/null +++ b/golem_activity_session_registration/views/golem_activity_view.xml @@ -0,0 +1,71 @@ + + + + + + + + Activity Registrations and Places + golem.activity.session + + + + + + + + + + + + + + + + + + + Activity Tree registrations additions + golem.activity.session + + + + red: places_remain == 0;orange: places_remain <= 4; + + + + + + + + + + + Activity Search registrations additions + golem.activity.session + + + + + + + + + +