From db2f8986cd6c115250b5aeb6ce73637cfaf5b552 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sat, 22 Apr 2017 20:25:36 +0200 Subject: [PATCH] =?UTF-8?q?[S0047]=20Faire=20le=20suivi=20des=20inscriptio?= =?UTF-8?q?ns=20aux=20s=C3=A9ances=20info/inscriptions=20shifts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beesdoo_base/models/partner.py | 2 - beesdoo_base/views/partner.xml | 6 +- beesdoo_shift/__openerp__.py | 4 +- beesdoo_shift/data/stage.xml | 10 +-- beesdoo_shift/data/system_parameter.xml | 10 +++ beesdoo_shift/models/__init__.py | 2 +- beesdoo_shift/models/cooperative_status.py | 59 ++++++++++++++++ beesdoo_shift/models/planning.py | 4 +- beesdoo_shift/models/res_users.py | 25 ------- beesdoo_shift/models/task.py | 6 +- beesdoo_shift/security/group.xml | 5 ++ beesdoo_shift/security/ir.model.access.csv | 3 + beesdoo_shift/views/cooperative_status.xml | 82 ++++++++++++++++++++++ beesdoo_shift/views/res_users.xml | 29 -------- beesdoo_shift/views/task.xml | 6 ++ beesdoo_shift/wizard/__init__.py | 3 +- beesdoo_shift/wizard/subscribe.py | 55 +++++++++++++++ beesdoo_shift/wizard/subscribe.xml | 24 +++++++ 18 files changed, 264 insertions(+), 71 deletions(-) create mode 100644 beesdoo_shift/data/system_parameter.xml create mode 100644 beesdoo_shift/models/cooperative_status.py delete mode 100644 beesdoo_shift/models/res_users.py create mode 100644 beesdoo_shift/views/cooperative_status.xml delete mode 100644 beesdoo_shift/views/res_users.xml create mode 100644 beesdoo_shift/wizard/subscribe.py create mode 100644 beesdoo_shift/wizard/subscribe.xml diff --git a/beesdoo_base/models/partner.py b/beesdoo_base/models/partner.py index 853e3d9..3d1a2cb 100644 --- a/beesdoo_base/models/partner.py +++ b/beesdoo_base/models/partner.py @@ -21,8 +21,6 @@ class Partner(models.Model): member_card_to_be_printed = fields.Boolean('Print BEES card?') last_printed = fields.Datetime('Last printed on') - info_session = fields.Boolean('Information Session ?') - info_session_date = fields.Datetime('Information Session Date') @api.onchange('first_name', 'last_name') def _on_change_name(self): diff --git a/beesdoo_base/views/partner.xml b/beesdoo_base/views/partner.xml index 771470d..2aa5510 100644 --- a/beesdoo_base/views/partner.xml +++ b/beesdoo_base/views/partner.xml @@ -34,11 +34,7 @@ - - - - + diff --git a/beesdoo_shift/__openerp__.py b/beesdoo_shift/__openerp__.py index 9ec7d50..a87a609 100644 --- a/beesdoo_shift/__openerp__.py +++ b/beesdoo_shift/__openerp__.py @@ -19,14 +19,16 @@ 'data': [ "data/stage.xml", + "data/system_parameter.xml", "security/group.xml", "security/ir.model.access.csv", "views/task_template.xml", "views/task.xml", "views/planning.xml", - "views/res_users.xml", + "views/cooperative_status.xml", "wizard/instanciate_planning.xml", "wizard/batch_template.xml", "wizard/assign_super_coop.xml", + "wizard/subscribe.xml", ], } diff --git a/beesdoo_shift/data/stage.xml b/beesdoo_shift/data/stage.xml index 2fd2f54..6d7f19e 100644 --- a/beesdoo_shift/data/stage.xml +++ b/beesdoo_shift/data/stage.xml @@ -14,11 +14,6 @@ 3 1 - - Replaced - 4 - 5 - Absent 5 @@ -29,6 +24,11 @@ 6 4 + + Excused - Absolute Necessity + 6 + 4 + Cancelled 7 diff --git a/beesdoo_shift/data/system_parameter.xml b/beesdoo_shift/data/system_parameter.xml new file mode 100644 index 0000000..c106f6d --- /dev/null +++ b/beesdoo_shift/data/system_parameter.xml @@ -0,0 +1,10 @@ + + + alert_delay + 28 + + + default_grace_delay + 10 + + \ No newline at end of file diff --git a/beesdoo_shift/models/__init__.py b/beesdoo_shift/models/__init__.py index 8d72c8b..b3d5110 100644 --- a/beesdoo_shift/models/__init__.py +++ b/beesdoo_shift/models/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- import planning import task -import res_users +import cooperative_status diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py new file mode 100644 index 0000000..2524e51 --- /dev/null +++ b/beesdoo_shift/models/cooperative_status.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +from openerp import models, fields, api, _ +from openerp.exceptions import ValidationError + +class CooperativeStatus(models.Model): + _name = 'cooperative.status' + _rec_name = 'cooperator_id' + + cooperator_id = fields.Many2one('res.partner') + info_session = fields.Boolean('Information Session ?') + info_session_date = fields.Datetime('Information Session Date') + super = fields.Boolean("Super Cooperative") + sr = fields.Integer("Compteur shift regulier") + sc = fields.Integer("Compteur shift de compensation") + time_holiday = fields.Integer("Holidays Days NB", default=0) + time_extension = fields.Integer("Extension Days NB", default=0) #Durée initial par défault sur ir_config_parameter + holiday_start_time = fields.Date("Holidays Start Day") + alert_start_time = fields.Date("Alert Start Day") + extension_start_time = fields.Date("Extension Start Day") + #Champ compute + status = fields.Selection([('ok', 'Up to Date'), ('holiday', 'Holidays'), ('alert', 'Alerte'), ('unsubscribed', 'Unsubscribed')], compute="_compute_status", string="Cooperative Status") + working_mode = fields.Selection( + [ + ('regular', 'Regular worker'), + ('irregular', 'Irregular worker'), + ('exempt', 'Exempted'), + ], + string="Working mode", + ) + + def _compute_status(self): + for rec in self: + rec.status = 'ok' + + _sql_constraints = [ + ('cooperator_uniq', 'unique (cooperator_id)', _('You can only set one cooperator status per cooperator')), + ] + +class ResPartner(models.Model): + _inherit = 'res.partner' + + cooperative_status_ids = fields.One2many('cooperative.status', 'cooperator_id', readonly=True) + super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True) + info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True) + info_session_date = fields.Datetime(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True) + working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True) + + @api.multi + def coop_subscribe(self): + return { + 'name': _('Subscribe Cooperator'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'beesdoo.shift.subscribe', + 'target': 'new', + } + + #TODO access right + vue on res.partner diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py index 88dedc3..8ad8a66 100644 --- a/beesdoo_shift/models/planning.py +++ b/beesdoo_shift/models/planning.py @@ -110,12 +110,14 @@ class TaskTemplate(models.Model): tasks = self.env['beesdoo.shift.shift'] for rec in self: for i in xrange(0, rec.worker_nb): + worker_id = rec.worker_ids[i].id if len(rec.worker_ids) > i else False tasks |= tasks.create({ '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, + 'worker_id' : worker_id, + 'is_regular': True if worker_id else False, 'start_time' : rec.start_date, 'end_time' : rec.end_date, 'stage_id': self.env.ref('beesdoo_shift.draft').id, diff --git a/beesdoo_shift/models/res_users.py b/beesdoo_shift/models/res_users.py deleted file mode 100644 index 96f86a2..0000000 --- a/beesdoo_shift/models/res_users.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -from openerp import models, fields - -class ResUsers(models.Model): - _inherit = 'res.users' - - super = fields.Boolean("Super Cooperative") - working_mode = fields.Selection( - [ - ('regular', 'Regular worker'), - ('irregular', 'Irregular worker'), - ('exempt', 'Exempted'), - ], - string="Working mode", - ) - -class ResPartner(models.Model): - _inherit = 'res.partner' - - super = fields.Boolean(related='user_ids.super', string="Super Cooperative", readonly=True) - working_mode = fields.Selection( - related='user_ids.working_mode', - string="Working mode", - readonly=True, - ) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index a858395..5abdf13 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -27,6 +27,8 @@ class Task(models.Model): 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) + is_regular = fields.Boolean(default=False) + replaced_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')]) def message_auto_subscribe(self, updated_fields, values=None): self._add_follower(values) @@ -45,4 +47,6 @@ class Task(models.Model): _group_by_full = { 'stage_id': _read_group_stage_id, - } \ No newline at end of file + } + + #TODO button to replaced someone \ No newline at end of file diff --git a/beesdoo_shift/security/group.xml b/beesdoo_shift/security/group.xml index 36cfaa8..a25186e 100644 --- a/beesdoo_shift/security/group.xml +++ b/beesdoo_shift/security/group.xml @@ -14,5 +14,10 @@ + + Cooperative Admin + + + \ 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 d415430..f90d443 100644 --- a/beesdoo_shift/security/ir.model.access.csv +++ b/beesdoo_shift/security/ir.model.access.csv @@ -6,9 +6,12 @@ access_coopplanning_planning,Attendance Read Planning,model_beesdoo_shift_planni 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 +access_coop_status,Coop Status Read for all,model_cooperative_status,,1,0,0,0 +access_coop_status_all,Coop Status Admin,model_cooperative_status,group_cooperative_admin,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/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml new file mode 100644 index 0000000..a34c460 --- /dev/null +++ b/beesdoo_shift/views/cooperative_status.xml @@ -0,0 +1,82 @@ + + + Partner Super Coop + res.partner + + + +
+
+
+ + + + + + + + + +
+ + + Coop Status Form View + cooperative.status + +
+
+ +
+ + + + + + + + + + + + + + +
+
+
+ + + Coop Status Tree view + cooperative.status + + + + + + + + + + + + + + + + + + Cooperator Status + cooperative.status + tree,form + + + + +
+ + diff --git a/beesdoo_shift/views/res_users.xml b/beesdoo_shift/views/res_users.xml deleted file mode 100644 index 16eac85..0000000 --- a/beesdoo_shift/views/res_users.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - Users Super Coop - res.users - - - - - - - - - - - Partner Super Coop - res.partner - - - - - - - - - - - - diff --git a/beesdoo_shift/views/task.xml b/beesdoo_shift/views/task.xml index f3d8ad8..f601639 100644 --- a/beesdoo_shift/views/task.xml +++ b/beesdoo_shift/views/task.xml @@ -91,6 +91,8 @@ + +
@@ -118,6 +120,7 @@ +
+
+ Regular Shift +
diff --git a/beesdoo_shift/wizard/__init__.py b/beesdoo_shift/wizard/__init__.py index b022bda..ec19ce4 100644 --- a/beesdoo_shift/wizard/__init__.py +++ b/beesdoo_shift/wizard/__init__.py @@ -1,3 +1,4 @@ import instanciate_planning import batch_template -import assign_super_coop \ No newline at end of file +import assign_super_coop +import subscribe \ No newline at end of file diff --git a/beesdoo_shift/wizard/subscribe.py b/beesdoo_shift/wizard/subscribe.py new file mode 100644 index 0000000..d7ef409 --- /dev/null +++ b/beesdoo_shift/wizard/subscribe.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from openerp import models, fields, api, _ +from openerp.exceptions import UserError + +class Subscribe(models.TransientModel): + _name = 'beesdoo.shift.subscribe' + + def _get_date(self): + date = self.env['res.partner'].browse(self._context.get('active_id')).info_session_date + if not date: + return fields.Date.today() + else: + return date + + def _get_super(self): + return self.env['res.partner'].browse(self._context.get('active_id')).super + + cooperator_id = fields.Many2one('res.partner', default=lambda self: self.env['res.partner'].browse(self._context.get('active_id')), required=True) + info_session = fields.Boolean(string="Followed an information session", default=True) + info_session_date = fields.Date(string="Date of information session", default=_get_date) + super = fields.Boolean(string="Super Cooperator", default=_get_super) + working_mode = fields.Selection( + [ + ('regular', 'Regular worker'), + ('irregular', 'Irregular worker'), + ('exempt', 'Exempted'), + ], + ) + shift_id = fields.Many2one('beesdoo.shift.template') + + @api.multi + def subscribe(self): + if not self.env.user.has_group('beesdoo_shift.group_shift_management'): + raise UserError(_("You don't have the required access for this operation.")) + if self.cooperator_id == self.env.user.partner_id and not self.env.user.has_group('beesdoo_shift.group_cooperative_admin'): + raise UserError(_("You cannot subscribe yourself.")) + self.ensure_one() + if self.shift_id and self.shift_id.remaining_worker <= 0: + raise UserError(_('There is no remaining space for this shift')) + if self.shift_id: + self.sudo().shift_id.worker_ids |= self.cooperator_id + data = { + 'info_session' : self.info_session, + 'info_session_date': self.info_session_date, + 'working_mode' : self.working_mode, + 'super' : self.super, + 'cooperator_id': self.cooperator_id.id, + 'sr' : 0, #set back to 0 if you subscribe a second time + } + + status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)]) + if status_id: + status_id.sudo().write(data) + else: + self.env['cooperative.status'].sudo().create(data) diff --git a/beesdoo_shift/wizard/subscribe.xml b/beesdoo_shift/wizard/subscribe.xml new file mode 100644 index 0000000..1bacc38 --- /dev/null +++ b/beesdoo_shift/wizard/subscribe.xml @@ -0,0 +1,24 @@ + + + Subscribre Cooperator + beesdoo.shift.subscribe + +
+ + + + + + + + + +
+
+
+