Browse Source

Merge pull request #69 from nicolasj77/highlights_shifts_intranet

[IMP] beesdoo_website_shift new configuration rule in pc
pull/75/head
Nicolas Jamoulle 6 years ago
committed by GitHub
parent
commit
0f6b8fc0ba
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      beesdoo_website_shift/controllers/main.py
  2. 6
      beesdoo_website_shift/data/res_config_data.xml
  3. 2
      beesdoo_website_shift/i18n/fr_BE.po
  4. 60
      beesdoo_website_shift/models/res_config.py
  5. 6
      beesdoo_website_shift/views/my_shift_website_templates.xml
  6. 4
      beesdoo_website_shift/views/res_config_views.xml

36
beesdoo_website_shift/controllers/main.py

@ -253,9 +253,11 @@ class WebsiteShiftController(http.Controller):
""" """
return self.my_shift_worker_status() return self.my_shift_worker_status()
def available_shift_irregular_worker(self, irregular_enable_sign_up=False, nexturl=""):
def available_shift_irregular_worker(self, irregular_enable_sign_up=False,
nexturl=""):
""" """
Return template variables for 'beesdoo_website_shift.available_shift_irregular_worker' template
Return template variables for
'beesdoo_website_shift.available_shift_irregular_worker' template
""" """
# Get current user # Get current user
cur_user = request.env['res.users'].browse(request.uid) cur_user = request.env['res.users'].browse(request.uid)
@ -278,12 +280,18 @@ class WebsiteShiftController(http.Controller):
) )
# Get config # Get config
irregular_shift_limit = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_shift_limit'))
highlight_rule = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.highlight_rule'))
hide_rule = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.hide_rule')) / 100.0
irregular_shift_limit = int(
request.env['ir.config_parameter']
.get_param('beesdoo_website_shift.irregular_shift_limit')
)
highlight_rule_pc = int(
request.env['ir.config_parameter']
.get_param('beesdoo_website_shift.highlight_rule_pc')
)
hide_rule = int(
request.env['ir.config_parameter']
.get_param('beesdoo_website_shift.hide_rule')
) / 100.0
# Grouby task_template_id, if no task_template_id is specified # Grouby task_template_id, if no task_template_id is specified
# then group by start_time, if no start_time specified sort by # then group by start_time, if no start_time specified sort by
@ -307,15 +315,23 @@ class WebsiteShiftController(http.Controller):
sub_shift.start_time == start_time and sub_shift.start_time == start_time and
sub_shift.task_type_id == task_type) sub_shift.task_type_id == task_type)
for sub_shift in subscribed_shifts) for sub_shift in subscribed_shifts)
# Check the necessary number of worker based on the
# highlight_rule_pc
has_enough_workers = free_space <= (task_template.worker_nb
* highlight_rule_pc) / 100
if free_space >= task_template.worker_nb * hide_rule: if free_space >= task_template.worker_nb * hide_rule:
shifts_count_subscribed.append([shift_list[0], free_space, is_subscribed])
shifts_count_subscribed.append([
shift_list[0],
free_space,
is_subscribed,
has_enough_workers,
])
# Stop showing shifts if the limit is reached # Stop showing shifts if the limit is reached
if irregular_shift_limit > 0 and nb_displayed_shift >= irregular_shift_limit: if irregular_shift_limit > 0 and nb_displayed_shift >= irregular_shift_limit:
break break
return { return {
'shift_templates': shifts_count_subscribed, 'shift_templates': shifts_count_subscribed,
'highlight_rule': highlight_rule,
'nexturl': nexturl, 'nexturl': nexturl,
'irregular_enable_sign_up': irregular_enable_sign_up, 'irregular_enable_sign_up': irregular_enable_sign_up,
} }

6
beesdoo_website_shift/data/res_config_data.xml

@ -9,9 +9,9 @@
<field name="key">beesdoo_website_shift.irregular_shift_limit</field> <field name="key">beesdoo_website_shift.irregular_shift_limit</field>
<field name="value">0</field> <field name="value">0</field>
</record> </record>
<record id="beesdoo_website_shift.highlight_rule" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.highlight_rule</field>
<field name="value">3</field>
<record id="beesdoo_website_shift.highlight_rule_pc" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.highlight_rule_pc</field>
<field name="value">30</field>
</record> </record>
<record id="beesdoo_website_shift.hide_rule" model="ir.config_parameter"> <record id="beesdoo_website_shift.hide_rule" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.hide_rule</field> <field name="key">beesdoo_website_shift.hide_rule</field>

2
beesdoo_website_shift/i18n/fr_BE.po

@ -462,7 +462,7 @@ msgstr "S'inscrire"
#. module: beesdoo_website_shift #. module: beesdoo_website_shift
#: model:ir.ui.view,arch_db:beesdoo_website_shift.public_shift_irregular_worker #: model:ir.ui.view,arch_db:beesdoo_website_shift.public_shift_irregular_worker
msgid "Subscribe via" msgid "Subscribe via"
msgstr "Nous avons spécialement besoin d'aide pour les shifts&amp;nbsp; pour lesquels il y a au moins 3 places disponibles. Inscriptions via"
msgstr "Nous avons spécialement besoin d'aide pour les shifts surlignés en jaune. Inscriptions via"
#. module: beesdoo_website_shift #. module: beesdoo_website_shift
#: model:ir.ui.view,arch_db:beesdoo_website_shift.public_shift_template_regular_worker #: model:ir.ui.view,arch_db:beesdoo_website_shift.public_shift_template_regular_worker

60
beesdoo_website_shift/models/res_config.py

@ -8,17 +8,20 @@ from openerp import fields, models, api
PARAMS = [ PARAMS = [
('irregular_shift_limit', 'beesdoo_website_shift.irregular_shift_limit'), ('irregular_shift_limit', 'beesdoo_website_shift.irregular_shift_limit'),
('highlight_rule', 'beesdoo_website_shift.highlight_rule'),
('highlight_rule_pc', 'beesdoo_website_shift.highlight_rule_pc'),
('hide_rule', 'beesdoo_website_shift.hide_rule'), ('hide_rule', 'beesdoo_website_shift.hide_rule'),
('irregular_enable_sign_up', 'beesdoo_website_shift.irregular_enable_sign_up'),
('irregular_past_shift_limit', 'beesdoo_website_shift.irregular_past_shift_limit'),
('regular_past_shift_limit', 'beesdoo_website_shift.regular_past_shift_limit'),
('regular_next_shift_limit', 'beesdoo_website_shift.regular_next_shift_limit'),
('irregular_enable_sign_up',
'beesdoo_website_shift.irregular_enable_sign_up'),
('irregular_past_shift_limit',
'beesdoo_website_shift.irregular_past_shift_limit'),
('regular_past_shift_limit'
, 'beesdoo_website_shift.regular_past_shift_limit'),
('regular_next_shift_limit',
'beesdoo_website_shift.regular_next_shift_limit'),
] ]
class WebsiteShiftConfigSettings(models.TransientModel): class WebsiteShiftConfigSettings(models.TransientModel):
_name = 'beesdoo.website.shift.config.settings' _name = 'beesdoo.website.shift.config.settings'
_inherit = 'res.config.settings' _inherit = 'res.config.settings'
@ -26,11 +29,13 @@ class WebsiteShiftConfigSettings(models.TransientModel):
irregular_shift_limit = fields.Integer( irregular_shift_limit = fields.Integer(
help="Maximum shift that will be shown" help="Maximum shift that will be shown"
) )
highlight_rule = fields.Integer(
help="Treshold of available space in a shift that trigger the highlight of the shift"
highlight_rule_pc = fields.Integer(
help="Treshold (in %) of available space in a shift that trigger the "
"highlight of the shift"
) )
hide_rule = fields.Integer( hide_rule = fields.Integer(
help="Treshold ((available space)/(max space)) in percentage of available space under wich the shift is hidden"
help="Treshold ((available space)/(max space)) in percentage of "
"available space under wich the shift is hidden"
) )
irregular_enable_sign_up = fields.Boolean( irregular_enable_sign_up = fields.Boolean(
help="Enable shift sign up for irregular worker" help="Enable shift sign up for irregular worker"
@ -58,46 +63,59 @@ class WebsiteShiftConfigSettings(models.TransientModel):
@api.multi @api.multi
def get_default_irregular_shift_limit(self): def get_default_irregular_shift_limit(self):
return { return {
'irregular_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_shift_limit'))
'irregular_shift_limit': int(
self.env['ir.config_parameter']
.get_param("beesdoo_website_shift.irregular_shift_limit")
)
} }
@api.multi @api.multi
def get_default_highlight_rule(self):
def get_default_highlight_rule_pc(self):
return { return {
'highlight_rule': int(self.env['ir.config_parameter'].get_param('beesdoo_website_shift.highlight_rule'))
'highlight_rule_pc': int(
self.env['ir.config_parameter']
.get_param("beesdoo_website_shift.highlight_rule_pc")
)
} }
@api.multi @api.multi
def get_default_hide_rule(self): def get_default_hide_rule(self):
return { return {
'hide_rule': int(self.env['ir.config_parameter'].get_param('beesdoo_website_shift.hide_rule'))
'hide_rule': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.hide_rule'))
} }
@api.multi @api.multi
def get_default_irregular_shift_sign_up(self): def get_default_irregular_shift_sign_up(self):
return { return {
'irregular_enable_sign_up': literal_eval(self.env['ir.config_parameter'].get_param(
'irregular_enable_sign_up':
literal_eval(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_enable_sign_up')) 'beesdoo_website_shift.irregular_enable_sign_up'))
} }
@api.multi @api.multi
def get_default_irregular_past_shift_limit(self): def get_default_irregular_past_shift_limit(self):
return { return {
'irregular_past_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_past_shift_limit'))
'irregular_past_shift_limit': int(
self.env['ir.config_parameter']
.get_param("beesdoo_website_shift.irregular_past_shift_limit")
)
} }
@api.multi @api.multi
def get_default_regular_past_shift_limit(self): def get_default_regular_past_shift_limit(self):
return { return {
'regular_past_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.regular_past_shift_limit'))
'regular_past_shift_limit': int(
self.env['ir.config_parameter']
.get_param('beesdoo_website_shift.regular_past_shift_limit')
)
} }
@api.multi @api.multi
def get_default_regular_next_shift_limit(self): def get_default_regular_next_shift_limit(self):
return { return {
'regular_next_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.regular_next_shift_limit'))
'regular_next_shift_limit': int(
self.env['ir.config_parameter']
.get_param('beesdoo_website_shift.regular_next_shift_limit')
)
} }

6
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -380,7 +380,8 @@
<t t-set="shift" t-value="shift_count_subscribed[0]" /> <t t-set="shift" t-value="shift_count_subscribed[0]" />
<t t-set="count" t-value="shift_count_subscribed[1]" /> <t t-set="count" t-value="shift_count_subscribed[1]" />
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]" /> <t t-set="is_subscribed" t-value="shift_count_subscribed[2]" />
<t t-set="highlight_class" t-value="'panel-warning' if count >= highlight_rule else 'panel-default'"/>
<t t-set="has_enough_workers" t-value="shift_count_subscribed[3]" />
<t t-set="highlight_class" t-value="'panel-warning' if not has_enough_workers else 'panel-default'"/>
<div t-att-class="'panel %s' % highlight_class"> <div t-att-class="'panel %s' % highlight_class">
<div class="panel-heading clearfix"> <div class="panel-heading clearfix">
<div class="panel-title pull-left"> <div class="panel-title pull-left">
@ -427,7 +428,8 @@
<t t-set="shift" t-value="shift_count_subscribed[0]" /> <t t-set="shift" t-value="shift_count_subscribed[0]" />
<t t-set="count" t-value="shift_count_subscribed[1]" /> <t t-set="count" t-value="shift_count_subscribed[1]" />
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]" /> <t t-set="is_subscribed" t-value="shift_count_subscribed[2]" />
<tr t-attf-class="{{ 'warning' if count >= highlight_rule else '' }}">
<t t-set="has_enough_workers" t-value="shift_count_subscribed[3]"/>
<tr t-attf-class="{{ 'warning' if not has_enough_workers else '' }}">
<td> <td>
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/> <t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
</td> </td>

4
beesdoo_website_shift/views/res_config_views.xml

@ -20,8 +20,8 @@
<field name="irregular_shift_limit"/> <field name="irregular_shift_limit"/>
</div> </div>
<div> <div>
<label for="highlight_rule"/>
<field name="highlight_rule"/>
<label for="highlight_rule_pc"/>
<field name="highlight_rule_pc"/>
</div> </div>
<div> <div>
<label for="hide_rule"/> <label for="hide_rule"/>

Loading…
Cancel
Save