Browse Source

[ADD] website_shift: Config en & dis shift sign up

This add a configuration boolean that enable or disable the shift sign
up for irregular worker.
pull/33/head
Rémy Taymans 7 years ago
parent
commit
8c6c02fa98
  1. 14
      beesdoo_website_shift/controllers/main.py
  2. 4
      beesdoo_website_shift/data/res_config_data.xml
  3. 13
      beesdoo_website_shift/models/res_config.py
  4. 4
      beesdoo_website_shift/views/res_config_views.xml
  5. 9
      beesdoo_website_shift/views/shift_website_templates.xml

14
beesdoo_website_shift/controllers/main.py

@ -1,4 +1,5 @@
# -*- coding: utf8 -*-
from ast import literal_eval
from datetime import datetime
from itertools import groupby
from openerp import http
@ -6,6 +7,7 @@ from openerp.http import request
from openerp.addons.beesdoo_shift.models.planning import float_to_time
class WebsiteShiftController(http.Controller):
@http.route('/shift', auth='user', website=True)
@ -30,7 +32,12 @@ class WebsiteShiftController(http.Controller):
def subscribe_to_shift(self, shift=None, **kwargs):
# Get current user
cur_user = request.env['res.users'].browse(request.uid)
if (cur_user.partner_id.working_mode == 'irregular'
# Get config
irregular_enable_sign_up = literal_eval(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_enable_sign_up'))
if (irregular_enable_sign_up
and cur_user.partner_id.working_mode == 'irregular'
and shift
and not shift.worker_id):
shift.worker_id = cur_user.partner_id
@ -62,6 +69,8 @@ class WebsiteShiftController(http.Controller):
'beesdoo_website_shift.highlight_rule'))
hide_rule = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.hide_rule')) / 100.0
irregular_enable_sign_up = literal_eval(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_enable_sign_up'))
# Grouby task_template_id, if no task_template_id is specified
# then group by start_time
@ -69,7 +78,7 @@ class WebsiteShiftController(http.Controller):
groupby_iter = groupby(shifts, groupby_func)
shifts_count_subscribed = []
nb_displayed_shift = 0 # Number of shift displayed
nb_displayed_shift = 0 # Number of shift displayed
for (keys, grouped_shifts) in groupby_iter:
(task_template, start_time, task_type) = keys
nb_displayed_shift = nb_displayed_shift + 1
@ -97,6 +106,7 @@ class WebsiteShiftController(http.Controller):
'highlight_rule': highlight_rule,
'nexturl': '/shift',
'subscribed_shifts': subscribed_shifts,
'irregular_enable_sign_up': irregular_enable_sign_up,
}
)

4
beesdoo_website_shift/data/res_config_data.xml

@ -13,5 +13,9 @@
<field name="key">beesdoo_website_shift.hide_rule</field>
<field name="value">20</field>
</record>
<record id="beesdoo_website_shift.irregular_enable_sign_up" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.irregular_enable_sign_up</field>
<field name="value">True</field>
</record>
</data>
</openerp>

13
beesdoo_website_shift/models/res_config.py

@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
from ast import literal_eval
from openerp import fields, models, api
PARAMS = [
('irregular_shift_limit', 'beesdoo_website_shift.irregular_shift_limit'),
('highlight_rule', 'beesdoo_website_shift.highlight_rule'),
('hide_rule', 'beesdoo_website_shift.hide_rule'),
('irregular_enable_sign_up', 'beesdoo_website_shift.irregular_enable_sign_up'),
]
class WebsiteShiftConfigSettings(models.TransientModel):
_name = 'beesdoo.website.shift.config.settings'
@ -22,6 +25,9 @@ class WebsiteShiftConfigSettings(models.TransientModel):
hide_rule = fields.Integer(
help="Treshold ((available space)/(max space)) in percentage of available space under wich the shift is hidden"
)
irregular_enable_sign_up = fields.Boolean(
help="Enable shift sign up for irregular worker"
)
@api.multi
def set_params(self):
@ -49,3 +55,10 @@ class WebsiteShiftConfigSettings(models.TransientModel):
return {
'hide_rule': int(self.env['ir.config_parameter'].get_param('beesdoo_website_shift.hide_rule'))
}
@api.multi
def get_default_irregular_shift_sign_up(self):
return {
'irregular_enable_sign_up': literal_eval(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_enable_sign_up'))
}

4
beesdoo_website_shift/views/res_config_views.xml

@ -23,6 +23,10 @@
<label for="hide_rule"/>
<field name="hide_rule"/>
</div>
<div>
<label for="irregular_enable_sign_up"/>
<field name="irregular_enable_sign_up"/>
</div>
</form>
</field>
</record>

9
beesdoo_website_shift/views/shift_website_templates.xml

@ -536,7 +536,7 @@
</div>
</div>
<table class="hidden-xs table table-striped">
<table class="hidden-xs table table-striped" t-if="subscribed_shifts">
<thead>
<tr>
<th>Day</th>
@ -630,7 +630,7 @@
Subscribed
</div>
</t>
<t t-if="not is_subscribed">
<t t-if="irregular_enable_sign_up and not is_subscribed">
<button type="button" class="btn btn-default btn-sm pull-right" data-toggle="modal"
t-att-data-target="'#subscribe-shift-%s' % shift.id">
<span class="fa fa-user-plus" aria-hidden="true"></span>
@ -649,7 +649,7 @@
<th>Time</th>
<th>Type of Shift</th>
<th class="text-center">Available Spaces</th>
<th class="text-center">Subscribed</th>
<th class="text-center" t-if="irregular_enable_sign_up">Subscribed</th>
</tr>
</thead>
<tbody>
@ -674,7 +674,7 @@
<td class="text-center">
<t t-esc="count"/>
</td>
<td class="text-center">
<td class="text-center" t-if="irregular_enable_sign_up">
<t t-if="is_subscribed">
<div class="label label-success">
<span class="fa fa-check" aria-hidden="true"></span>
@ -722,6 +722,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a class="btn btn-primary"
t-if="irregular_enable_sign_up"
t-att-href="'/shift/%s/subscribe?nexturl=%s' % (shift.id, nexturl)">
Subscribe
</a>

Loading…
Cancel
Save