Browse Source

[ADD] b_shift : attendance sheet time slot

pull/143/head
Elouan Le Bars 5 years ago
parent
commit
ead8cc6996
  1. 49
      beesdoo_shift/models/attendance_sheet.py
  2. 6
      beesdoo_shift/views/attendance_sheet.xml

49
beesdoo_shift/models/attendance_sheet.py

@ -147,8 +147,12 @@ class AttendanceSheet(models.Model):
_description = "Attendance sheets with all the shifts in one time range." _description = "Attendance sheets with all the shifts in one time range."
_order = "start_time" _order = "start_time"
name = fields.Char(
string="Name", compute="_compute_name", store=True, readonly=True
name = fields.Char(string="Name", compute="_compute_name")
time_slot = fields.Char(
string="Time Slot",
compute="_compute_time_slot",
store=True,
readonly=True,
) )
active = fields.Boolean(string="Active", default=1) active = fields.Boolean(string="Active", default=1)
state = fields.Selection( state = fields.Selection(
@ -163,6 +167,7 @@ class AttendanceSheet(models.Model):
string="Start Time", required=True, readonly=True string="Start Time", required=True, readonly=True
) )
end_time = fields.Datetime(string="End Time", required=True, readonly=True) end_time = fields.Datetime(string="End Time", required=True, readonly=True)
day = fields.Date(string="Day", compute="_compute_day", store=True)
default_super_coop_id = fields.Many2one( default_super_coop_id = fields.Many2one(
"res.users", "res.users",
@ -273,21 +278,37 @@ class AttendanceSheet(models.Model):
) )
) )
# Compute name (not hardcorded to prevent incoherence with timezone)
@api.depends("start_time", "end_time")
def _compute_time_slot(self):
for rec in self:
start_time_dt = fields.Datetime.from_string(rec.start_time)
start_time_dt = fields.Datetime.context_timestamp(
rec, start_time_dt
)
end_time_dt = fields.Datetime.from_string(rec.end_time)
end_time_dt = fields.Datetime.context_timestamp(rec, end_time_dt)
rec.time_slot = (
start_time_dt.strftime("%H:%M")
+ " - "
+ end_time_dt.strftime("%H:%M")
)
@api.depends("start_time", "end_time") @api.depends("start_time", "end_time")
def _compute_name(self): def _compute_name(self):
for rec in self:
start_time_dt = fields.Datetime.from_string(rec.start_time)
start_time_dt = fields.Datetime.context_timestamp(
rec, start_time_dt
)
if rec.time_slot:
rec.name = (
fields.Date.to_string(start_time_dt) + " " + rec.time_slot
)
start_time_dt = fields.Datetime.from_string(self.start_time)
start_time_dt = fields.Datetime.context_timestamp(self, start_time_dt)
end_time_dt = fields.Datetime.from_string(self.end_time)
end_time_dt = fields.Datetime.context_timestamp(self, end_time_dt)
self.name = (
start_time_dt.strftime("%Y-%m-%d")
+ " "
+ start_time_dt.strftime("%H:%M")
+ "-"
+ end_time_dt.strftime("%H:%M")
)
@api.depends("start_time")
def _compute_day(self):
for rec in self:
rec.day = fields.Date.from_string(rec.start_time)
@api.depends("expected_shift_ids") @api.depends("expected_shift_ids")
def _compute_default_super_coop_id(self): def _compute_default_super_coop_id(self):

6
beesdoo_shift/views/attendance_sheet.xml

@ -7,9 +7,7 @@
<field name="model">beesdoo.shift.sheet</field> <field name="model">beesdoo.shift.sheet</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search> <search>
<field name="name" />
<field name="start_time" />
<field name="end_time" />
<field name="day" />
<field name="default_super_coop_id" /> <field name="default_super_coop_id" />
<field name="validated_by" /> <field name="validated_by" />
<filter string="Annotated (unread)" <filter string="Annotated (unread)"
@ -156,7 +154,7 @@
</div> </div>
<div class="oe_title"> <div class="oe_title">
<h1> <h1>
<field name="name" />
<field name="time_slot" />
</h1> </h1>
</div> </div>
<separator string="Expected workers" /> <separator string="Expected workers" />

Loading…
Cancel
Save