Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Discuss
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

calculate late using Odoo studio

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
hr
2 Replies
1888 Tampilan
Avatar
Mohamed Kandil

I want to calculate Late time in attendance

Late: If an employee comes after scheduled time then that count in late

how can I do it by studio /Odoo 17?

0
Avatar
Buang
Avatar
Mohamed Kandil
Penulis Jawaban Terbai

I made a module with this code but the

scheduled_check_in  get null
from odoo import models, fields, api
from datetime import datetime

class HrAttendance(models.Model):
_inherit = 'hr.attendance'

# Make scheduled_check_in editable
scheduled_check_in = fields.Datetime(string="Scheduled Check-In", default=lambda self: self._default_scheduled_check_in())
late_minutes = fields.Integer(string="Late Minutes", compute="_compute_late_minutes", store=True)

def _default_scheduled_check_in(self):
"""
Automatically populate scheduled_check_in based on the employee's work schedule.
"""
if self.employee_id and self.employee_id.resource_calendar_id and self.check_in:
calendar = self.employee_id.resource_calendar_id
check_in_date = fields.Datetime.to_datetime(self.check_in).date()

# Get the work intervals for the check-in date
work_intervals = calendar._work_intervals_batch(
datetime.combine(check_in_date, datetime.min.time()),
datetime.combine(check_in_date, datetime.max.time()),
resources=self.employee_id.resource_id,
)

if work_intervals and self.employee_id.resource_id in work_intervals:
# Get the start time of the first work interval
return work_intervals[self.employee_id.resource_id][0][0]
return False

@api.depends('check_in', 'scheduled_check_in')
def _compute_late_minutes(self):
"""
Compute late_minutes as the difference between check_in and scheduled_check_in in whole minutes.
"""
for record in self:
if record.check_in and record.scheduled_check_in:
check_in_time = fields.Datetime.to_datetime(record.check_in)
scheduled_time = fields.Datetime.to_datetime(record.scheduled_check_in)

# Ensure both times are in the same timezone (if necessary)
check_in_time = check_in_time.replace(tzinfo=None)
scheduled_time = scheduled_time.replace(tzinfo=None)

if check_in_time > scheduled_time:
delta = check_in_time - scheduled_time
# Convert total seconds to minutes and round to the nearest integer
record.late_minutes = round(delta.total_seconds() / 60)
else:
record.late_minutes = 0
else:
record.late_minutes = 0

@api.model
def create(self, vals):
"""
Automatically populate scheduled_check_in when creating a new attendance record.
"""
if 'scheduled_check_in' not in vals and vals.get('employee_id') and vals.get('check_in'):
employee = self.env['hr.employee'].browse(vals['employee_id'])
if employee.resource_calendar_id:
calendar = employee.resource_calendar_id
check_in_date = fields.Datetime.to_datetime(vals['check_in']).date()

# Get the work intervals for the check-in date
work_intervals = calendar._work_intervals_batch(
datetime.combine(check_in_date, datetime.min.time()),
datetime.combine(check_in_date, datetime.max.time()),
resources=employee.resource_id,
)

if work_intervals and employee.resource_id in work_intervals:
# Get the start time of the first work interval
vals['scheduled_check_in'] = work_intervals[employee.resource_id][0][0]
return super(HrAttendance, self).create(vals)
0
Avatar
Buang
Avatar
Hemangini Patel
Jawaban Terbai

The attendance data is typically tracked in the hr.attendance model, and the scheduled working time is often linked to the resource.calendar or resource.calendar.attendance model.

  • hr.attendance: Tracks employee check-in and check-out times.
  • resource.calendar: Defines the working schedule for employees.

Steps to Configure in Studio

Step 1: Add a Field for "Late Time"
  1. Go to Studio.
  2. Open the Attendance (hr.attendance) model.
  3. Add a new computed field (e.g., Late Time) with the following configuration:
    • Field Name: x_late_time
    • Type: Float (or Integer for minutes)
    • Label: "Late Time (Minutes)"
    • Computation Logic: Use Python code.
Step 2: Write the Computation Logic

You can use the Odoo Studio computation editor or define the logic via Python. For Studio, you need to approximate it as follows:

if record.check_in: # Get the scheduled start time from the resource calendar scheduled_start = record.employee_id.resource_calendar_id.attendance_ids.filtered( lambda a: a.dayofweek == str(record.check_in.weekday()) ).mapped('hour_from') if scheduled_start: scheduled_start_time = record.check_in.replace( hour=int(scheduled_start[0]), minute=int((scheduled_start[0] % 1) * 60) ) if record.check_in > scheduled_start_time: late_minutes = (record.check_in - scheduled_start_time).total_seconds() / 60 result = late_minutes else: result = 0 else: result = 0

Step 3: Save the Changes

Once the computation is added, save and test the field.

Add a Filter for "Late Employees"
  1. In Studio, create a new filter for records where x_late_time > 0.
  2. This will allow you to easily see employees who were late.
0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
[{(!!@Nombre~LAN~Colombia#)}] ¿Cómo se llama Avianca en Colombia?
hr
Avatar
0
Des 25
5
Implementing HR Module? Diselesaikan
hr
Avatar
Avatar
1
Nov 25
553
gratis trainingssessies
hr
Avatar
0
Nov 25
6
Attendance Analysis – How to calculate Extra Hours with flexible start times
hr
Avatar
Avatar
2
Okt 25
1113
block other users from editing a survey
hr
Avatar
Avatar
1
Okt 25
930
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now