Browse Source

[ADD] b_shift : attendance sheet CRON for generation

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
870eeec675
  1. 12
      beesdoo_shift/data/cron.xml
  2. 36
      beesdoo_shift/models/attendance_sheet.py

12
beesdoo_shift/data/cron.xml

@ -11,7 +11,6 @@
<field name="args">()</field>
</record>
<record id="ir_cron_generate_next_planning" model="ir.cron">
<field name="name">Generate Next Planning</field>
<field name="interval_number">1</field>
@ -24,6 +23,17 @@
<field name="active" eval="False" />
</record>
<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="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model">beesdoo.shift.sheet</field>
<field name="function">_generate_attendance_sheet</field>
<field name="args">()</field>
</record>
<record id="ir_cron_compute_shift_counter" model="ir.cron">
<field name="name">Compute Shift Counter</field>
<field name="interval_number">4</field>

36
beesdoo_shift/models/attendance_sheet.py

@ -5,7 +5,7 @@ from lxml import etree
from openerp import models, exceptions, fields, api, _
from openerp.exceptions import UserError, ValidationError
from datetime import datetime
from datetime import date, datetime, timedelta
from lxml import etree
@ -463,6 +463,40 @@ class AttendanceSheet(models.Model):
"target": "new",
}
@api.model
def _generate_attendance_sheet(self):
"""
Generate sheets 20 minutes before current time.
Corresponding CRON intervall time must be the same.
Check if any task exists in the time intervall.
If no sheet is already created, it is created.
"""
time_ranges = set()
tasks = self.env["beesdoo.shift.shift"]
sheets = self.env["beesdoo.shift.sheet"]
current_time = datetime.now()
allowed_time_range = timedelta(minutes=20)
tasks = tasks.search(
[
("start_time", ">", str(current_time),),
("start_time", "<", str(current_time + allowed_time_range),),
]
)
for task in tasks:
start_time = task.start_time
end_time = task.end_time
sheets = sheets.search(
[("start_time", "=", start_time), ("end_time", "=", end_time),]
)
if not sheets:
sheet = sheets.create(
{"start_time": start_time, "end_time": end_time}
)
def on_barcode_scanned(self, barcode):
if self.state == "validated":

Loading…
Cancel
Save