Elouan Le Bars
5 years ago
6 changed files with 124 additions and 2 deletions
-
1beesdoo_shift/__openerp__.py
-
5beesdoo_shift/models/attendance_sheet.py
-
3beesdoo_shift/wizard/__init__.py
-
78beesdoo_shift/wizard/generate_attendance_sheet.py
-
37beesdoo_shift/wizard/generate_attendance_sheet.xml
-
2beesdoo_shift/wizard/subscribe.xml
@ -1,7 +1,8 @@ |
|||||
import instanciate_planning |
import instanciate_planning |
||||
|
import generate_attendance_sheet |
||||
import batch_template |
import batch_template |
||||
import assign_super_coop |
import assign_super_coop |
||||
import subscribe |
import subscribe |
||||
import extension |
import extension |
||||
import holiday |
import holiday |
||||
import temporary_exemption |
|
||||
|
import temporary_exemption |
@ -0,0 +1,78 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
from openerp import models, fields, api, exceptions, _ |
||||
|
|
||||
|
from datetime import date, datetime, timedelta |
||||
|
|
||||
|
|
||||
|
class GenerateAttendanceSheet(models.TransientModel): |
||||
|
_name = "beesdoo.shift.sheet.generate" |
||||
|
_description = "Use a selected time range to generate the corresponding attendance sheet." |
||||
|
|
||||
|
time_range = fields.Selection("_get_time_ranges", string="Hours") |
||||
|
|
||||
|
def _get_time_ranges(self): |
||||
|
time_ranges = set() |
||||
|
tasks = self.env["beesdoo.shift.shift"] |
||||
|
sheets = self.env["beesdoo.shift.sheet"] |
||||
|
current_time = datetime.now() |
||||
|
allowed_time_range = timedelta(minutes=45) |
||||
|
|
||||
|
tasks = tasks.search( |
||||
|
[ |
||||
|
("start_time", ">", str(current_time - allowed_time_range),), |
||||
|
("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 len(sheets) == 0: |
||||
|
start_time_dt = fields.Datetime.from_string(start_time) |
||||
|
start_time_dt = fields.Datetime.context_timestamp( |
||||
|
self, start_time_dt |
||||
|
) |
||||
|
end_time_dt = fields.Datetime.from_string(end_time) |
||||
|
end_time_dt = fields.Datetime.context_timestamp( |
||||
|
self, end_time_dt |
||||
|
) |
||||
|
|
||||
|
# We display contextualized time range |
||||
|
# but we save it according to UTC timezone |
||||
|
time_ranges.add( |
||||
|
( |
||||
|
start_time + "~" + end_time, |
||||
|
start_time_dt.strftime("%H:%M") |
||||
|
+ " - " |
||||
|
+ end_time_dt.strftime("%H:%M"), |
||||
|
) |
||||
|
) |
||||
|
return list(time_ranges) |
||||
|
|
||||
|
@api.multi |
||||
|
def button_generate(self): |
||||
|
self.ensure_one() |
||||
|
tasks = self.env["beesdoo.shift.shift"] |
||||
|
sheets = self.env["beesdoo.shift.sheet"] |
||||
|
if not self.time_range: |
||||
|
raise exceptions.UserError( |
||||
|
"Please select a time time_range to generate the sheet." |
||||
|
) |
||||
|
time_range = self.time_range.split("~") |
||||
|
if len(time_range) != 2: |
||||
|
raise exceptions.ValidationError("Selection key has wrong format.") |
||||
|
sheet = sheets.create( |
||||
|
{"start_time": time_range[0], "end_time": time_range[1]} |
||||
|
) |
||||
|
|
||||
|
return { |
||||
|
"type": "ir.actions.act_window", |
||||
|
"res_model": "beesdoo.shift.sheet", |
||||
|
"res_id": sheet.id, |
||||
|
"view_type": "form", |
||||
|
"view_mode": "form", |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
<odoo> |
||||
|
<record model="ir.ui.view" id="generate_attendance_sheet_view_form"> |
||||
|
<field name="name">Generate an attendance sheet</field> |
||||
|
<field name="model">beesdoo.shift.sheet.generate</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form> |
||||
|
<group> |
||||
|
<field name="time_range" /> |
||||
|
</group> |
||||
|
<footer> |
||||
|
<button type="object" name="button_generate" |
||||
|
string="Generate" class="oe_highlight" /> |
||||
|
<button special="cancel" string="Cancel" /> |
||||
|
</footer> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<!-- Actions --> |
||||
|
|
||||
|
<act_window id="action_generate_sheet_wizard" |
||||
|
name="Generate a non-existing sheet" |
||||
|
res_model="beesdoo.shift.sheet.generate" |
||||
|
view_mode="form" |
||||
|
target="new" |
||||
|
/> |
||||
|
|
||||
|
<!-- Menu actions --> |
||||
|
|
||||
|
<menuitem id="menu_generate_sheet" |
||||
|
name="Generate a sheet" |
||||
|
parent="menu_sheet_top" |
||||
|
action="action_generate_sheet_wizard" |
||||
|
sequence="5" |
||||
|
/> |
||||
|
|
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue