diff --git a/beesdoo_shift/__openerp__.py b/beesdoo_shift/__openerp__.py
index ba56969..dc23e2e 100644
--- a/beesdoo_shift/__openerp__.py
+++ b/beesdoo_shift/__openerp__.py
@@ -32,5 +32,6 @@
"wizard/batch_template.xml",
"wizard/assign_super_coop.xml",
"wizard/subscribe.xml",
+ "wizard/extension.xml",
],
}
diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py
index e8aea50..8256a99 100644
--- a/beesdoo_shift/models/cooperative_status.py
+++ b/beesdoo_shift/models/cooperative_status.py
@@ -208,5 +208,22 @@ class ResPartner(models.Model):
res['context'] = {'default_unsubscribed': True}
return res
+ @api.multi
+ def manual_extension(self):
+ return {
+ 'name': _('Manual Extension'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'beesdoo.shift.extension',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def auto_extension(self):
+ res = self.manual_extension()
+ res['context'] = {'default_auto': True}
+ res['name'] = _('Trigger Grace Delay')
+ return res
#TODO access right + vue on res.partner
#TODO can_shop : Status can_shop ou extempted ou part C
diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml
index 91c1dd5..b650073 100644
--- a/beesdoo_shift/views/cooperative_status.xml
+++ b/beesdoo_shift/views/cooperative_status.xml
@@ -15,7 +15,14 @@
('cooperator_type', '!=', 'share_a'),
'|',
('state', '!=', 'suspended'),
- ('extension_start_time', '!=', False)]}"/>
+ ('extension_start_time', '!=', False)]}" />
+
diff --git a/beesdoo_shift/wizard/__init__.py b/beesdoo_shift/wizard/__init__.py
index ec19ce4..474c92e 100644
--- a/beesdoo_shift/wizard/__init__.py
+++ b/beesdoo_shift/wizard/__init__.py
@@ -1,4 +1,5 @@
import instanciate_planning
import batch_template
import assign_super_coop
-import subscribe
\ No newline at end of file
+import subscribe
+import extension
\ No newline at end of file
diff --git a/beesdoo_shift/wizard/extension.py b/beesdoo_shift/wizard/extension.py
new file mode 100644
index 0000000..1a5255b
--- /dev/null
+++ b/beesdoo_shift/wizard/extension.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, api, _
+from openerp.exceptions import UserError
+
+class Subscribe(models.TransientModel):
+ _name = 'beesdoo.shift.extension'
+ _inherit = 'beesdoo.shift.action_mixin'
+
+ def _get_default_extension_delay(self):
+ return int(self.env['ir.config_parameter'].get_param('default_extension_delay', 28))
+
+
+ extension_start_date = fields.Date(string="Start date for the extension", default=fields.Date.today, readonly=True)
+ auto = fields.Boolean("Auto Extension", default=False)
+ extension_days = fields.Integer(default=_get_default_extension_delay)
+
+ @api.multi
+ def auto_ext(self):
+ self = self._check()
+ status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
+ status_id.sudo().write({'extension_start_time': self.extension_start_date})
+
+ @api.multi
+ def extension(self):
+ self = self._check() #maybe a different group
+ grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10))
+ status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
+ if not status_id.extension_start_time:
+ raise UserError(_('You should not make a manual extension when the grace delay has not been triggered yet'))
+ extension_date = fields.Date.from_string(status_id.extension_start_time)
+ today = fields.Date.from_string(status_id.today)
+ today_delay = (today - extension_date).days - grace_delay
+ if today_delay < 0:
+ raise UserError(_('You should not start a manual extension during the grace delay'))
+ status_id.sudo().write({'time_extension': self.extension_days + today_delay})
+
+ #TO continue
diff --git a/beesdoo_shift/wizard/extension.xml b/beesdoo_shift/wizard/extension.xml
new file mode 100644
index 0000000..d4dabc5
--- /dev/null
+++ b/beesdoo_shift/wizard/extension.xml
@@ -0,0 +1,26 @@
+
+
+ Extension Management
+ beesdoo.shift.extension
+
+
+
+
+
diff --git a/beesdoo_shift/wizard/subscribe.py b/beesdoo_shift/wizard/subscribe.py
index 632b05f..24a25ee 100644
--- a/beesdoo_shift/wizard/subscribe.py
+++ b/beesdoo_shift/wizard/subscribe.py
@@ -2,8 +2,22 @@
from openerp import models, fields, api, _
from openerp.exceptions import UserError
+class StatusActionMixin(models.AbstractModel):
+ _name = "beesdoo.shift.action_mixin"
+
+ cooperator_id = fields.Many2one('res.partner', default=lambda self: self.env['res.partner'].browse(self._context.get('active_id')), required=True)
+
+ def _check(self, group='beesdoo_shift.group_shift_management'):
+ self.ensure_one()
+ if not self.env.user.has_group(group):
+ 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 perform this operation on yourself"))
+ return self.with_context(real_uid=self._uid)
+
class Subscribe(models.TransientModel):
_name = 'beesdoo.shift.subscribe'
+ _inherit = 'beesdoo.shift.action_mixin'
def _get_date(self):
date = self.env['res.partner'].browse(self._context.get('active_id')).info_session_date
@@ -18,7 +32,6 @@ class Subscribe(models.TransientModel):
def _get_mode(self):
return self.env['res.partner'].browse(self._context.get('active_id')).working_mode
- 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)
@@ -34,16 +47,14 @@ class Subscribe(models.TransientModel):
reset_counter = fields.Boolean(default=False)
unsubscribed = fields.Boolean(default=False, string="Are you sure to unsubscribe this cooperator")
+
+
@api.multi
def unsubscribe(self):
- self.ensure_one()
+ self = self._check()
if not self.unsubscribed:
return
- 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 unsubscribe yourself."))
- self = self.with_context(real_uid=self._uid)
+
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
data = {
'unsubscribed': True,
@@ -56,12 +67,7 @@ class Subscribe(models.TransientModel):
@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()
- self = self.with_context(real_uid=self._uid)
+ self = self._check()
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: