Browse Source

[ADD] b_shift : wizard for generation of missing attendance sheets

pull/143/head
Elouan Le Bars 5 years ago
parent
commit
3efb918708
  1. 1
      beesdoo_shift/__manifest__.py
  2. 1
      beesdoo_shift/models/attendance_sheet.py
  3. 7
      beesdoo_shift/views/res_config_settings_view.xml
  4. 1
      beesdoo_shift/wizard/__init__.py
  5. 57
      beesdoo_shift/wizard/generate_missing_attendance_sheets.py
  6. 35
      beesdoo_shift/wizard/generate_missing_attendance_sheets.xml

1
beesdoo_shift/__manifest__.py

@ -37,6 +37,7 @@
"wizard/extension.xml",
"wizard/holiday.xml",
"wizard/temporary_exemption.xml",
"wizard/generate_missing_attendance_sheets.xml",
],
'demo': [
"demo/workers.xml",

1
beesdoo_shift/models/attendance_sheet.py

@ -597,7 +597,6 @@ class AttendanceSheet(models.Model):
defined from corresponding CRON time interval.
"""
time_ranges = set()
tasks = self.env["beesdoo.shift.shift"]
sheets = self.env["beesdoo.shift.sheet"]
current_time = datetime.now()

7
beesdoo_shift/views/res_config_settings_view.xml

@ -96,6 +96,13 @@
sequence="21"
/>
<record model="ir.actions.act_window" id="action_missing_attendance_sheets">
<field name="name">Generate missing past attendance sheets</field>
<field name="res_model">beesdoo.shift.generate_missing_attendance_sheets</field>
<field name="view_mode">form</field>
</record>
<record model="ir.actions.act_window" id="action_day_number">
<field name="name">Day Number</field>
<field name="res_model">beesdoo.shift.daynumber</field>

1
beesdoo_shift/wizard/__init__.py

@ -6,3 +6,4 @@ from . import extension
from . import holiday
from . import temporary_exemption
from . import validate_attendance_sheet
from . import generate_missing_attendance_sheets

57
beesdoo_shift/wizard/generate_missing_attendance_sheets.py

@ -0,0 +1,57 @@
from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError
from datetime import datetime
class GenerateMissingAttendanceSheets(models.TransientModel):
"""
Generate missing past sheets
"""
_name = "beesdoo.shift.generate_missing_attendance_sheets"
date_start = fields.Datetime("Start date", required=True)
date_end = fields.Datetime("End date", required=True)
@api.multi
def generate_missing_attendance_sheets(self):
self.ensure_one()
tasks = self.env["beesdoo.shift.shift"]
sheets = self.env["beesdoo.shift.sheet"]
tasks = tasks.search(
[
("start_time", ">", self.date_start),
("start_time", "<", self.date_end),
]
)
# We should not loop on task with same start_time and end_time
# To improve performances
for task in tasks:
start_time = task.start_time
end_time = task.end_time
sheet = sheets.search(
[("start_time", "=", start_time), ("end_time", "=", end_time),]
)
if not sheet:
sheets |= sheets.create(
{"start_time": start_time, "end_time": end_time}
)
return {
"name": _("Generated Missing Sheets"),
"type": "ir.actions.act_window",
"view_type": "form",
"view_mode": "tree,form",
"res_model": "beesdoo.shift.sheet",
"target": "current",
"domain": [("id", "in", sheets.ids)],
}
@api.constrains("date_start", "date_end")
def constrains_dates(self):
if self.date_start > datetime.now() or self.date_end > datetime.now():
raise UserError(_("Only past attendance sheets can be generated"))

35
beesdoo_shift/wizard/generate_missing_attendance_sheets.xml

@ -0,0 +1,35 @@
<odoo>
<record model="ir.ui.view" id="validate_attendance_sheet_form">
<field name="name">Generate Missing Attendance Sheets</field>
<field name="model">beesdoo.shift.generate_missing_attendance_sheets</field>
<field name="arch" type="xml">
<form>
<sheet>
<label for="date_start" string="Generate missing attendance sheets in a given time interval" />
<group>
<field name="date_start" />
<field name="date_end" />
</group>
</sheet>
<footer>
<button type="object"
name="generate_missing_attendance_sheets"
string="Generate"
class="oe_highlight"
/>
</footer>
</form>
</field>
</record>
<act_window id="action_missing_attendance_sheets" name="Generate Missing Sheets"
res_model="beesdoo.shift.generate_missing_attendance_sheets"
view_mode="form" target="new" />
<menuitem id="menu_missing_attendance_sheets"
name="Generate missing past attendance sheets"
parent="menu_configuration_top"
action="action_missing_attendance_sheets"
sequence="2"
/>
</odoo>
Loading…
Cancel
Save