Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

calculate late using Odoo studio

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
hr
2 Risposte
1899 Visualizzazioni
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
Abbandona
Avatar
Mohamed Kandil
Autore Risposta migliore

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
Abbandona
Avatar
Hemangini Patel
Risposta migliore

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
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
[{(!!@Nombre~LAN~Colombia#)}] ¿Cómo se llama Avianca en Colombia?
hr
Avatar
0
dic 25
5
Implementing HR Module? Risolto
hr
Avatar
Avatar
1
nov 25
560
gratis trainingssessies
hr
Avatar
0
nov 25
6
Attendance Analysis – How to calculate Extra Hours with flexible start times
hr
Avatar
Avatar
2
ott 25
1117
block other users from editing a survey
hr
Avatar
Avatar
1
ott 25
931
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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