diff --git a/beesdoo_shift/__openerp__.py b/beesdoo_shift/__openerp__.py index 4a2a996..9ec7d50 100644 --- a/beesdoo_shift/__openerp__.py +++ b/beesdoo_shift/__openerp__.py @@ -12,17 +12,21 @@ 'author': "Thibault Francois", 'website': "https://github.com/beescoop/Obeesdoo", - 'category': 'Coop', + 'category': 'Cooperative management', 'version': '0.1', 'depends': ['beesdoo_base'], 'data': [ + "data/stage.xml", + "security/group.xml", "security/ir.model.access.csv", "views/task_template.xml", "views/task.xml", "views/planning.xml", + "views/res_users.xml", "wizard/instanciate_planning.xml", "wizard/batch_template.xml", + "wizard/assign_super_coop.xml", ], } diff --git a/beesdoo_shift/data/stage.xml b/beesdoo_shift/data/stage.xml new file mode 100644 index 0000000..2fd2f54 --- /dev/null +++ b/beesdoo_shift/data/stage.xml @@ -0,0 +1,37 @@ + + + Unconfirmed + 1 + 0 + + + Confirmed + 2 + 5 + + + Attended + 3 + 1 + + + Replaced + 4 + 5 + + + Absent + 5 + 2 + + + Excused + 6 + 4 + + + Cancelled + 7 + 8 + + diff --git a/beesdoo_shift/models/__init__.py b/beesdoo_shift/models/__init__.py index 14cfb0e..b011d24 100644 --- a/beesdoo_shift/models/__init__.py +++ b/beesdoo_shift/models/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- import planning -import task \ No newline at end of file +import task +import res_users \ No newline at end of file diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py index 421c6bc..88dedc3 100644 --- a/beesdoo_shift/models/planning.py +++ b/beesdoo_shift/models/planning.py @@ -28,7 +28,7 @@ class TaskType(models.Model): class DayNumber(models.Model): _name = 'beesdoo.shift.daynumber' - + _order = 'number asc' name = fields.Char() @@ -44,12 +44,15 @@ class Planning(models.Model): class TaskTemplate(models.Model): _name = 'beesdoo.shift.template' + _order = 'start_time' + name = fields.Char(required=True) planning_id = fields.Many2one('beesdoo.shift.planning', required=True) day_nb_id = fields.Many2one('beesdoo.shift.daynumber', string='Day', required=True) task_type_id = fields.Many2one('beesdoo.shift.type', string="Type") start_time = fields.Float(required=True) end_time = fields.Float(required=True) + super_coop_id = fields.Many2one('res.users', string="Super Cooperative", domain=[('super', '=', True)]) duration = fields.Float(help="Duration in Hour") worker_nb = fields.Integer(string="Number of worker", help="Max number of worker for this task", default=1) @@ -72,7 +75,7 @@ class TaskTemplate(models.Model): h_end, m_end = floatime_to_hour_minute(rec.end_time) rec.start_date = fields.Datetime.context_timestamp(self, day).replace(hour=h_begin, minute=m_begin, second=0).astimezone(UTC) rec.end_date = fields.Datetime.context_timestamp(self, day).replace(hour=h_end, minute=m_end, second=0).astimezone(UTC) - + def _dummy_search(self, operator, value): return [] @@ -85,7 +88,7 @@ class TaskTemplate(models.Model): def _get_worker_name(self): for rec in self: rec.worker_name = ','.join(rec.worker_ids.mapped('display_name')) - + @api.constrains('worker_nb', 'worker_ids') def _nb_worker_max(self): for rec in self: @@ -97,7 +100,7 @@ class TaskTemplate(models.Model): def _get_duration(self): if self.start_time and self.end_time: self.duration = self.end_time - self.start_time - + @api.onchange('duration') def _set_duration(self): if self.start_time: @@ -108,11 +111,13 @@ class TaskTemplate(models.Model): for rec in self: for i in xrange(0, rec.worker_nb): tasks |= tasks.create({ - 'name' : "%s (%s) - (%s) [%s]" % (rec.name, float_to_time(rec.start_time), float_to_time(rec.end_time), i), + 'name' : "%s %s (%s - %s) [%s]" % (rec.name, rec.day_nb_id.name, float_to_time(rec.start_time), float_to_time(rec.end_time), i), 'task_template_id' : rec.id, 'task_type_id' : rec.task_type_id.id, + 'super_coop_id': rec.super_coop_id.id, 'worker_id' : rec.worker_ids[i].id if len(rec.worker_ids) > i else False, 'start_time' : rec.start_date, 'end_time' : rec.end_date, + 'stage_id': self.env.ref('beesdoo_shift.draft').id, }) return tasks \ No newline at end of file diff --git a/beesdoo_shift/models/res_users.py b/beesdoo_shift/models/res_users.py new file mode 100644 index 0000000..82452d0 --- /dev/null +++ b/beesdoo_shift/models/res_users.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +from openerp import models, fields + +class ResUsers(models.Model): + _inherit = 'res.users' + + super = fields.Boolean("Super Cooperative") \ No newline at end of file diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index d603b7e..a858395 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -1,22 +1,22 @@ # -*- coding: utf-8 -*- -from openerp import models, fields - -STATES = [ - ('draft', 'Unconfirmed'), - ('open', 'Confirmed'), - ('done', 'Attended'), - ('absent', 'Absent'), - ('excused', 'Excused'), - ('replaced', 'Replaced'), - ('cancel', 'Cancelled'), -] +from openerp import models, fields, api + +class TaskStage(models.Model): + _name = 'beesdoo.shift.stage' + _order = 'sequence asc' + + name = fields.Char() + sequence = fields.Integer() + color = fields.Integer() + class Task(models.Model): _name = 'beesdoo.shift.shift' - #EX01 ADD inheritance _inherit = ['mail.thread'] + _order = "start_time asc" + name = fields.Char(track_visibility='always') task_template_id = fields.Many2one('beesdoo.shift.template') planning_id = fields.Many2one(related='task_template_id.planning_id', store=True) @@ -24,7 +24,9 @@ class Task(models.Model): worker_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')]) start_time = fields.Datetime(track_visibility='always') end_time = fields.Datetime(track_visibility='always') - state = fields.Selection(STATES, default='draft', track_visibility='onchange') + stage_id = fields.Many2one('beesdoo.shift.stage', required=True, track_visibility='onchange') + super_coop_id = fields.Many2one('res.users', string="Super Cooperative", domain=[('super', '=', True)], track_visibility='onchange') + color = fields.Integer(related="stage_id.color", readonly=True) def message_auto_subscribe(self, updated_fields, values=None): self._add_follower(values) @@ -33,4 +35,14 @@ class Task(models.Model): def _add_follower(self, vals): if vals.get('worker_id'): worker = self.env['res.partner'].browse(vals['worker_id']) - self.message_subscribe(partner_ids=worker.ids) \ No newline at end of file + self.message_subscribe(partner_ids=worker.ids) + + @api.model + def _read_group_stage_id(self, ids, domain, read_group_order=None, access_rights_uid=None): + res = self.env['beesdoo.shift.stage'].search([]).name_get() + fold = dict.fromkeys([r[0] for r in res], False) + return res, fold + + _group_by_full = { + 'stage_id': _read_group_stage_id, + } \ No newline at end of file diff --git a/beesdoo_shift/security/group.xml b/beesdoo_shift/security/group.xml new file mode 100644 index 0000000..36cfaa8 --- /dev/null +++ b/beesdoo_shift/security/group.xml @@ -0,0 +1,18 @@ + + + + Shift Attendance + + + + Shift Management + + + + + Planning Management + + + + + \ No newline at end of file diff --git a/beesdoo_shift/security/ir.model.access.csv b/beesdoo_shift/security/ir.model.access.csv index a63e74b..d415430 100644 --- a/beesdoo_shift/security/ir.model.access.csv +++ b/beesdoo_shift/security/ir.model.access.csv @@ -1,6 +1,14 @@ id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink -access_coopplanning_task_type,access_coopplanning_task_type,model_beesdoo_shift_type,,1,1,1,1 -access_coopplanning_daynumber,access_coopplanning_daynumber,model_beesdoo_shift_daynumber,,1,1,1,1 -access_coopplanning_planning,access_coopplanning_planning,model_beesdoo_shift_planning,,1,1,1,1 -access_coopplanning_task_template,access_coopplanning_task_template,model_beesdoo_shift_template,,1,1,1,1 -access_coopplanning_task,access_coopplanning_task,model_beesdoo_shift_shift,,1,1,1,1 +access_coopplanning_task_stage,Attendance Read Stage,model_beesdoo_shift_stage,group_shift_attendance,1,0,0,0 +access_coopplanning_task_type,Attendance Read Type,model_beesdoo_shift_type,group_shift_attendance,1,0,0,0 +access_coopplanning_daynumber,Attendance Read Daynumber,model_beesdoo_shift_daynumber,group_shift_attendance,1,0,0,0 +access_coopplanning_planning,Attendance Read Planning,model_beesdoo_shift_planning,group_shift_attendance,1,0,0,0 +access_coopplanning_task_template,Attendance Read Template,model_beesdoo_shift_template,group_shift_attendance,1,0,0,0 +access_coopplanning_task,Attendance Edit Shift,model_beesdoo_shift_shift,group_shift_attendance,1,1,0,0 +access_coopplanning_task_full,Shift Management all Shift,model_beesdoo_shift_shift,group_shift_management,1,1,1,1 +all_config_coopplanning_task_stage,Attendance Read Stage,model_beesdoo_shift_stage,group_planning_management,1,1,1,1 +all_config_coopplanning_task_type,Attendance Read Type,model_beesdoo_shift_type,group_planning_management,1,1,1,1 +all_config_coopplanning_daynumber,Attendance Read Daynumber,model_beesdoo_shift_daynumber,group_planning_management,1,1,1,1 +all_config_coopplanning_planning,Attendance Read Planning,model_beesdoo_shift_planning,group_planning_management,1,1,1,1 +all_config_coopplanning_task_template,Attendance Read Template,model_beesdoo_shift_template,group_planning_management,1,1,1,1 +all_config_coopplanning_task,Attendance Edit Shift,model_beesdoo_shift_shift,group_planning_management,1,1,1,1 diff --git a/beesdoo_shift/views/planning.xml b/beesdoo_shift/views/planning.xml index 4aace85..8b42baa 100644 --- a/beesdoo_shift/views/planning.xml +++ b/beesdoo_shift/views/planning.xml @@ -15,7 +15,8 @@ kanban,tree,form,calendar,pivot {'group_by': 'day_nb_id', 'search_default_planning_id': active_id, - 'default_planning_id': active_id} + 'default_planning_id': active_id} + @@ -31,7 +32,7 @@
- +
@@ -49,7 +50,8 @@