Browse Source

[ADD] extension wizard + [CLEAN] Abstract class for all wizard related to action on the cooperative status

pull/105/head
Thibault Francois 7 years ago
committed by Elouan
parent
commit
957965bab3
  1. 1
      beesdoo_shift/__openerp__.py
  2. 17
      beesdoo_shift/models/cooperative_status.py
  3. 9
      beesdoo_shift/views/cooperative_status.xml
  4. 3
      beesdoo_shift/wizard/__init__.py
  5. 37
      beesdoo_shift/wizard/extension.py
  6. 26
      beesdoo_shift/wizard/extension.xml
  7. 32
      beesdoo_shift/wizard/subscribe.py

1
beesdoo_shift/__openerp__.py

@ -32,5 +32,6 @@
"wizard/batch_template.xml",
"wizard/assign_super_coop.xml",
"wizard/subscribe.xml",
"wizard/extension.xml",
],
}

17
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

9
beesdoo_shift/views/cooperative_status.xml

@ -15,7 +15,14 @@
('cooperator_type', '!=', 'share_a'),
'|',
('state', '!=', 'suspended'),
('extension_start_time', '!=', False)]}"/>
('extension_start_time', '!=', False)]}" />
<button name="manual_extension" string="Manual Extension" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': ['|',
('cooperator_type', '!=', 'share_a'),
'|',
('state', '!=', 'suspended'),
('extension_start_time', '=', False)]}" />
<button name="coop_unsubscribe" string="Unsubscribe" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}"/>

3
beesdoo_shift/wizard/__init__.py

@ -1,4 +1,5 @@
import instanciate_planning
import batch_template
import assign_super_coop
import subscribe
import subscribe
import extension

37
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

26
beesdoo_shift/wizard/extension.xml

@ -0,0 +1,26 @@
<odoo>
<record model="ir.ui.view" id="extension_coop_wizard_view_form">
<field name="name">Extension Management</field>
<field name="model">beesdoo.shift.extension</field>
<field name="arch" type="xml">
<form>
<field name="cooperator_id" invisible="1"/>
<field name="auto" invisible="1"/>
<group attrs="{'invisible': [('auto', '=', False)]}">
<field name="extension_start_date" />
</group>
<group attrs="{'invisible': [('auto', '=', True)]}">
<field name="extension_days" />
</group>
<footer>
<button type="object" name="extension"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('auto', '=', True)]}" />
<button type="object" name="auto_ext"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('auto', '=', False)]}" />
or
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
</record>
</odoo>

32
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:

Loading…
Cancel
Save