55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
#
|
|
# fp.job.step.timelog — granular start/stop intervals for a step.
|
|
#
|
|
# Each step.button_start() opens a fresh timelog row. Each
|
|
# step.button_finish() (or button_pause once added) closes the open
|
|
# row. duration_actual on fp.job.step is the sum of these intervals.
|
|
#
|
|
# Replicates Odoo MRP's mrp.workorder.time_ids granularity natively
|
|
# (without depending on the mrp module).
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class FpJobStepTimeLog(models.Model):
|
|
_name = 'fp.job.step.timelog'
|
|
_description = 'Plating Job Step Time Log'
|
|
_order = 'date_started desc'
|
|
|
|
step_id = fields.Many2one(
|
|
'fp.job.step',
|
|
required=True,
|
|
ondelete='cascade',
|
|
index=True,
|
|
)
|
|
user_id = fields.Many2one('res.users', required=True)
|
|
date_started = fields.Datetime(required=True)
|
|
date_finished = fields.Datetime()
|
|
duration_minutes = fields.Float(
|
|
compute='_compute_duration', store=True,
|
|
)
|
|
|
|
@api.depends('date_started', 'date_finished')
|
|
def _compute_duration(self):
|
|
for log in self:
|
|
if log.date_started and log.date_finished:
|
|
delta = log.date_finished - log.date_started
|
|
log.duration_minutes = delta.total_seconds() / 60.0
|
|
else:
|
|
log.duration_minutes = 0.0
|
|
|
|
@api.depends('user_id', 'date_started', 'duration_minutes')
|
|
def _compute_display_name(self):
|
|
for log in self:
|
|
user = log.user_id.name or 'User'
|
|
when = log.date_started.strftime('%Y-%m-%d %H:%M') if log.date_started else ''
|
|
mins = ('%.0f min' % log.duration_minutes) if log.duration_minutes else 'open'
|
|
rec_bits = [user]
|
|
if when:
|
|
rec_bits.append(when)
|
|
rec_bits.append(mins)
|
|
log.display_name = ' · '.join(rec_bits)
|