Browse Source

[IMP] b_shift : attendance sheet generation time configurable

Generation CRON is running every minute and check for sheets
in the configurable time interval. Workers can't subscribe
to a shift on intranet if its start time is in this interval.
pull/125/head
Elouan Le Bars 5 years ago
parent
commit
3ea0cdfc69
  1. 4
      beesdoo_shift/data/cron.xml
  2. 12
      beesdoo_shift/models/attendance_sheet.py
  3. 25
      beesdoo_shift/models/res_config.py
  4. 1
      beesdoo_shift/views/res_config_view.xml
  5. 20
      beesdoo_website_shift/controllers/main.py
  6. 2
      beesdoo_website_shift/views/my_shift_website_templates.xml

4
beesdoo_shift/data/cron.xml

@ -24,8 +24,8 @@
</record> </record>
<record id="ir_cron_generate_attendance_sheet" model="ir.cron"> <record id="ir_cron_generate_attendance_sheet" model="ir.cron">
<field name="name">Generate Attendance Sheet</field>
<field name="interval_number">20</field>
<field name="name">Generate Attendance Sheets</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field> <field name="interval_type">minutes</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field name="doall" eval="False" /> <field name="doall" eval="False" />

12
beesdoo_shift/models/attendance_sheet.py

@ -176,7 +176,6 @@ class AttendanceSheet(models.Model):
default=0, default=0,
readonly=True, readonly=True,
help="Indicative maximum number of workers.", help="Indicative maximum number of workers.",
) )
annotation = fields.Text("Annotation", default="") annotation = fields.Text("Annotation", default="")
is_annotated = fields.Boolean( is_annotated = fields.Boolean(
@ -539,16 +538,19 @@ class AttendanceSheet(models.Model):
@api.model @api.model
def _generate_attendance_sheet(self): def _generate_attendance_sheet(self):
""" """
Generate sheets 20 minutes before their start time.
Corresponding CRON intervall time must be the same.
Check if any task exists in the time intervall.
Generate sheets with shifts in the time interval
defined from corresponding CRON time interval.
""" """
time_ranges = set() time_ranges = set()
tasks = self.env["beesdoo.shift.shift"] tasks = self.env["beesdoo.shift.shift"]
sheets = self.env["beesdoo.shift.sheet"] sheets = self.env["beesdoo.shift.sheet"]
current_time = datetime.now() current_time = datetime.now()
allowed_time_range = timedelta(minutes=20)
generation_interval_setting = int(self.env["ir.config_parameter"].get_param(
"beesdoo_shift.attendance_sheet_generation_interval"
))
allowed_time_range = timedelta(minutes=generation_interval_setting)
tasks = tasks.search( tasks = tasks.search(
[ [

25
beesdoo_shift/models/res_config.py

@ -15,13 +15,24 @@ class ShiftConfigSettings(models.TransientModel):
string="Default Task Type", string="Default Task Type",
help="Default task type for attendance sheet pre-filling.", help="Default task type for attendance sheet pre-filling.",
) )
attendance_sheet_generation_interval = fields.Integer(
string="Time interval for attendance sheet generation",
help="Time interval expressed in minutes",
)
@api.multi @api.multi
def set_params(self): def set_params(self):
self.ensure_one() self.ensure_one()
value = self.default_task_type_id.id
parameters = self.env["ir.config_parameter"] parameters = self.env["ir.config_parameter"]
parameters.set_param("beesdoo_shift.default_task_type_id", value)
parameters.set_param(
"beesdoo_shift.default_task_type_id",
str(self.default_task_type_id.id),
)
parameters.set_param(
"beesdoo_shift.attendance_sheet_generation_interval",
str(self.attendance_sheet_generation_interval),
)
@api.multi @api.multi
def get_default_task_type_id(self): def get_default_task_type_id(self):
@ -32,3 +43,13 @@ class ShiftConfigSettings(models.TransientModel):
) )
) )
} }
@api.multi
def get_default_attendance_sheet_generation_interval(self):
return {
"attendance_sheet_generation_interval": int(
self.env["ir.config_parameter"].get_param(
"beesdoo_shift.attendance_sheet_generation_interval"
)
)
}

1
beesdoo_shift/views/res_config_view.xml

@ -40,6 +40,7 @@
</header> </header>
<separator string="General Settings"/> <separator string="General Settings"/>
<group name="Attendance Sheets"> <group name="Attendance Sheets">
<field name="attendance_sheet_generation_interval"/>
<field name="default_task_type_id"/> <field name="default_task_type_id"/>
</group> </group>
</form> </form>

20
beesdoo_website_shift/controllers/main.py

@ -135,7 +135,8 @@ class WebsiteShiftController(http.Controller):
* the given shift exist * the given shift exist
* the shift status is open * the shift status is open
* the shift is free for subscription * the shift is free for subscription
* the shift is starting in more than 20 minutes
* the shift is starting after the time interval
for attendance sheet generation defined in beesdoo_shift settings
""" """
# Get current user # Get current user
cur_user = request.env['res.users'].browse(request.uid) cur_user = request.env['res.users'].browse(request.uid)
@ -144,8 +145,13 @@ class WebsiteShiftController(http.Controller):
# Get config # Get config
irregular_enable_sign_up = literal_eval(request.env['ir.config_parameter'].get_param( irregular_enable_sign_up = literal_eval(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_enable_sign_up')) 'beesdoo_website_shift.irregular_enable_sign_up'))
# Set start time limit
start_time_limit = datetime.now() + timedelta(minutes = 20)
# Set start time limit as defined in beesdoo_shift settings
setting = int(
request.env["ir.config_parameter"].get_param(
"beesdoo_shift.attendance_sheet_generation_interval"
)
)
start_time_limit = datetime.now() + timedelta(minutes=setting)
shift_start_time = fields.Datetime.from_string(shift.start_time) shift_start_time = fields.Datetime.from_string(shift.start_time)
request.session['success'] = False request.session['success'] = False
@ -236,6 +242,14 @@ class WebsiteShiftController(http.Controller):
template_context['success'] = request.session.get('success') template_context['success'] = request.session.get('success')
del request.session['success'] del request.session['success']
# Add setting for subscription allowed time
subscription_time_limit = int(
request.env["ir.config_parameter"].get_param(
"beesdoo_shift.attendance_sheet_generation_interval"
)
)
template_context['subscription_time_limit'] = subscription_time_limit
return template_context return template_context
def my_shift_regular_worker_without_shift(self): def my_shift_regular_worker_without_shift(self):

2
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -902,7 +902,7 @@
subscribed before you or the shift was deleted. Try again in a subscribed before you or the shift was deleted. Try again in a
moment. moment.
Please note that you can't subscribe 20 minutes before the shift.
Please note that you can't subscribe <t t-esc="subscription_time_limit"/> minutes before the shift.
</t> </t>
</div> </div>

Loading…
Cancel
Save