commit
5c086aa498
|
|
@ -2862,3 +2862,9 @@ msgstr "تم التبرير "
|
|||
#: model_terms:ir.ui.view,arch_db:attendances.employee_lateness_absense_overtime_form_view
|
||||
msgid "Actual Absent Days"
|
||||
msgstr "أيام الغياب"
|
||||
|
||||
#. module: attendances
|
||||
#: model:ir.model.fields,field_description:attendances.field_attendance_attendance__attendance_duration
|
||||
#: model:ir.model.fields,field_description:attendances.field_attendance_attendance__attendance_duration_hhmmss
|
||||
msgid "Attendance Duration"
|
||||
msgstr "زمن الحضور"
|
||||
|
|
|
|||
|
|
@ -446,6 +446,11 @@ class Attendance(models.Model):
|
|||
|
||||
is_today = fields.Boolean(string='Is Today', compute='_compute_is_today', store=True)
|
||||
|
||||
attendance_duration = fields.Float(string="Attendance Duration", compute='_compute_attendance_duration',
|
||||
store=True)
|
||||
attendance_duration_hhmmss = fields.Char(string="Attendance Duration",
|
||||
compute='_compute_attendance_duration', store=True)
|
||||
|
||||
@api.depends('action_date')
|
||||
def _compute_is_today(self):
|
||||
today = datetime.now().date()
|
||||
|
|
@ -468,6 +473,43 @@ class Attendance(models.Model):
|
|||
item.action_date = False
|
||||
|
||||
|
||||
@api.depends('employee_id', 'action_date', 'action', 'name')
|
||||
def _compute_attendance_duration(self):
|
||||
for record in self:
|
||||
record.attendance_duration = 0.0
|
||||
record.attendance_duration_hhmmss = "00:00:00"
|
||||
|
||||
if not record.employee_id or not record.action_date:
|
||||
continue
|
||||
|
||||
attendances = self.search([
|
||||
('employee_id', '=', record.employee_id.id),
|
||||
('action_date', '=', record.action_date)
|
||||
], order='name ASC')
|
||||
|
||||
total_seconds = 0
|
||||
last_sign_in = None
|
||||
|
||||
for att in attendances:
|
||||
if att.action == 'sign_in':
|
||||
if not last_sign_in:
|
||||
last_sign_in = att.name
|
||||
|
||||
elif att.action == 'sign_out' and last_sign_in:
|
||||
diff_seconds = (att.name - last_sign_in).total_seconds()
|
||||
total_seconds += diff_seconds
|
||||
|
||||
if att.id == record.id:
|
||||
hours = int(total_seconds // 3600)
|
||||
minutes = int((total_seconds % 3600) // 60)
|
||||
seconds = int(total_seconds % 60)
|
||||
|
||||
record.attendance_duration = round(total_seconds / 3600.0, 2)
|
||||
record.attendance_duration_hhmmss = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
|
||||
|
||||
last_sign_in = None
|
||||
|
||||
|
||||
class HrEmployee(models.Model):
|
||||
_inherit = 'hr.employee'
|
||||
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@
|
|||
<field name="action_reason" readonly="1" force_save="1"/>
|
||||
<field name="action_date" readonly="1"/>
|
||||
<field name="taken" invisible="1"/>
|
||||
<field name="attendance_duration_hhmmss" attrs="{'invisible': [('action','!=','sign_out')]}" />
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
|
@ -379,6 +380,7 @@
|
|||
<field name="name" required="1"/>
|
||||
<field name="action"/>
|
||||
<field name="action_type"/>
|
||||
<field name="attendance_duration_hhmmss" attrs="{'invisible': [('action','!=','sign_out')]}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
|||
Loading…
Reference in New Issue