Activités : inscription par créneau interne #41

Open
youssef wants to merge 15 commits from youssef/GOLEM:activites_inscription_par_creneau_interne into master
7 changed files with 262 additions and 0 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 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

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 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 registration slot',
'summary': 'GOLEM activity registration slot',
'description': ''' GOLEM activity registration slot management ''',
'version': '10.0.0.0.1',
'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3',
'application': True,
'installable': True,
'depends': ['golem_activity_registration'],
'data': ['views/golem_activity_views.xml']
}

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 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, golem_activity_registration_slot, golem_activity_registration

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 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/>.
""" GOLEM Activity adaptations """
from odoo import models, fields, api, _
class GolemActivity(models.Model):
""" GOLEM Activity adaptations """
_inherit = 'golem.activity'
individual_slots = fields.Boolean(string='Individual slots activity')
slots_number = fields.Integer(string='Registration Slot Number')
slots_duration = fields.Float(string='Registration Slot Duration')
registration_slot_ids = fields.One2many('golem.activity.registration.slot', 'activity_id',
string='Registration Slots')
#@api.constrains('slots_number', 'slots_duration')

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 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/>.
""" GOLEM Activity Registration """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemActivityRegistration(models.Model):
""" GOLEM Activity Registration Adaptations"""
_inherit = 'golem.activity.registration'
@api.model
def create(self, vals):
""" Create registration slot """
reg = super(GolemActivityRegistration, self).create(vals)
if reg.activity_id.individual_slots:
slots = self.env['golem.activity.registration.slot'].search(
[('activity_id', '=', reg.activity_id.id)], order='hour_stop')
if len(slots) >= reg.activity_id.slots_number:
verr = _(u'No available slot to register in this activity')
raise ValidationError(verr)
hour_start = slots[-1].hour_stop if slots else reg.activity_id.hour_start
self.env['golem.activity.registration.slot'].create({
'activity_id': reg.activity_id.id,
'member_id': reg.member_id.id,
'hour_start': hour_start,
'hour_stop': hour_start + reg.activity_id.slots_duration
})
return reg

View File

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 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/>.
""" GOLEM Activity Registration Slot """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemActivityRegistrationSlot(models.Model):
""" GOLEM Activity Registration Slot """
_name = 'golem.activity.registration.slot'
_order = 'sequence'
_description = 'GOLEM Activity Registration Slot'
activity_id = fields.Many2one('golem.activity', required=True,
string='Activity', ondelete='cascade',
index=True)
member_id = fields.Many2one('golem.member', string='Member',
ondelete='cascade', index=True)
hour_start = fields.Float('Start time')
hour_stop = fields.Float('Stop time')
sequence = fields.Integer('Sequence')
@api.constrains('hour_start', 'hour_stop')
def check_slot_hours(self):
""" Check slot hours consistency """
for slot in self:
if slot.hour_start >= slot.hour_stop:
verr = _(u'Slot start must be before slot stop')
raise ValidationError(verr)
if slot.hour_start < slot.activity_id.hour_start or \
slot.hour_stop > slot.activity_id.hour_stop:
verr = _(u'Slot start and stop must be between activity start and'
' activity stop.')
raise ValidationError(verr)
@api.constrains('sequence')
def calculate_slot_hours(self):
""" Calcualte slot hours """
slots = self.env['golem.activity.registration.slot'].search(
[('activity_id', '=', self[0].activity_id.id)], order='sequence')
for id_slot, slot in enumerate(slots):
hour_start = slot.activity_id.hour_start + (slot.activity_id.slots_duration * id_slot)
hour_stop = hour_start + slot.activity_id.slots_duration
slot.write({
'hour_start': hour_start,
'hour_stop': hour_stop
})

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
Copyright 2018 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/>.
-->
<odoo>
<data>
<!-- Forms -->
<record id="golem_activity_form_inherit_golem_activity_registration_slot"
model="ir.ui.view">
<field name="name">Add registration slot to activity form</field>
<field name="model">golem.activity</field>
<field name="inherit_id" ref="golem_activity.golem_activity_form" />
<field name="arch" type="xml">
<field name='list_price' position='after'>
<field name='individual_slots'/>
</field>
<page name='activity_others' position='before'>
<page name='individual_slots_tab' string='Individual Slots'
attrs="{'invisible': [('individual_slots', '!=', True)]}">
<group>
<field name='slots_number'/>
<field name='slots_duration' widget='float_time'/>
<field name='registration_slot_ids'>
<tree editable='bottom'>
<field name="sequence" widget="handle"/>
<field name="member_id"/>
<field name='hour_start' widget='float_time'/>
<field name='hour_stop' widget='float_time'/>
</tree>
</field>
</group>
</page>
</page>
</field>
</record>
</data>
</odoo>