Browse Source

[ADD] Add unsubscribe wizard

pull/105/head
Thibault Francois 7 years ago
committed by Elouan
parent
commit
20b7b29982
  1. 13
      beesdoo_shift/models/cooperative_status.py
  2. 4
      beesdoo_shift/views/cooperative_status.xml
  3. 22
      beesdoo_shift/wizard/subscribe.py
  4. 10
      beesdoo_shift/wizard/subscribe.xml

13
beesdoo_shift/models/cooperative_status.py

@ -62,10 +62,11 @@ class CooperativeStatus(models.Model):
compute="_compute_status", string="Cooperative Status", store=True)
can_shop = fields.Boolean(compute='_compute_status', store=True)
history_ids = fields.One2many('cooperative.status.history', 'status_id', readonly=True)
unsubscribed = fields.Boolean(default=False, help="Manually unsubscribed")
@api.depends('today', 'sr', 'sc', 'time_holiday', 'holiday_start_time', 'time_extension', 'alert_start_time', 'extension_start_time')
@api.depends('today', 'sr', 'sc', 'time_holiday', 'holiday_start_time', 'time_extension', 'alert_start_time', 'extension_start_time', 'unsubscribed')
def _compute_status(self):
alert_delay = int(self.env['ir.config_parameter'].get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10))
@ -80,7 +81,7 @@ class CooperativeStatus(models.Model):
ok = rec.sr >= 0 and rec.sc >= 0
grace_delay = grace_delay + rec.time_extension
if rec.sr < -1: #un subscribed
if rec.sr < -1 or rec.unsubscribed:
rec.status = 'unsubscribed'
rec.can_shop = False
@ -112,7 +113,7 @@ class CooperativeStatus(models.Model):
"""
Overwrite write to historize the change
"""
for field in ['sr', 'sc', 'time_extension', 'extension_start_time', 'alert_start_time']:
for field in ['sr', 'sc', 'time_extension', 'extension_start_time', 'alert_start_time', 'unsubscribed']:
if not field in vals:
continue
for rec in self:
@ -200,5 +201,11 @@ class ResPartner(models.Model):
'target': 'new',
}
@api.multi
def coop_unsubscribe(self):
res = self.coop_subscribe()
res['context'] = {'default_unsubscribed': True}
return res
#TODO access right + vue on res.partner
#TODO can_shop : Status can_shop ou extempted ou part C

4
beesdoo_shift/views/cooperative_status.xml

@ -16,6 +16,9 @@
'|',
('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')]}"/>
<field name="state" widget="statusbar" attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}" />
</header>
</xpath>
@ -59,6 +62,7 @@
<field name="info_session_date" />
<field name="sr" />
<field name="sc" />
<field name="unsubscribed" />
<field name="can_shop" />
</group>
<group>

22
beesdoo_shift/wizard/subscribe.py

@ -32,6 +32,27 @@ class Subscribe(models.TransientModel):
exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason')
shift_id = fields.Many2one('beesdoo.shift.template')
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()
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,
'cooperator_id': self.cooperator_id.id,
}
if status_id:
status_id.sudo().write(data)
else:
self.env['cooperative.status'].sudo().create(data)
@api.multi
def subscribe(self):
@ -57,6 +78,7 @@ class Subscribe(models.TransientModel):
'exempt_reason_id' : self.exempt_reason_id.id,
'super' : self.super,
'cooperator_id': self.cooperator_id.id,
'unsubscribed': False
}
if self.reset_counter:
data['sr'] = 0

10
beesdoo_shift/wizard/subscribe.xml

@ -4,7 +4,11 @@
<field name="model">beesdoo.shift.subscribe</field>
<field name="arch" type="xml">
<form>
<group>
<group attrs="{'invisible': [('unsubscribed', '=', False)]}">
<separator string="Are you sure to unsubscribe this cooperator ?" />
<field name="unsubscribed" invisible="1" />
</group>
<group attrs="{'invisible': [('unsubscribed', '=', True)]}">
<field name="cooperator_id" />
<field name="info_session" />
<field name="info_session_date" />
@ -16,7 +20,9 @@
</group>
<footer>
<button type="object" name="subscribe"
string="Confirm" class="oe_highlight" />
string="Confirm" class="oe_highlight" attrs="{'invisible': [('unsubscribed', '=', True)]}" />
<button type="object" name="unsubscribe"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('unsubscribed', '=', False)]}" />
or
<button special="cancel" string="Cancel" />
</footer>

Loading…
Cancel
Save