# -*- coding: utf-8 -*- # Copyright 2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) # # Real implementations for the state-machine action stubs that # fusion_plating core's fp.job.step shipped as NotImplementedError # placeholders. Per spec ยง5.2 state machine. from odoo import _, fields, models from odoo.exceptions import UserError class FpJobStep(models.Model): _inherit = 'fp.job.step' def button_pause(self): """Pause an in-progress step (operator break, end of shift). Closes the open timelog row, sums duration_actual, transitions state to 'paused'. button_start re-opens a fresh timelog when the operator resumes. """ for step in self: if step.state != 'in_progress': raise UserError(_( "Step '%s' is in state '%s' โ€” only in-progress steps can pause." ) % (step.name, step.state)) now = fields.Datetime.now() open_log = step.time_log_ids.filtered(lambda l: not l.date_finished) if open_log: open_log.write({'date_finished': now}) step.state = 'paused' step.duration_actual = sum(step.time_log_ids.mapped('duration_minutes')) return True def button_skip(self): """Skip a pending/ready step (e.g. opt-in step the planner decided not to activate for this job). """ for step in self: if step.state not in ('pending', 'ready'): raise UserError(_( "Step '%s' is in state '%s' โ€” only pending/ready steps can be skipped." ) % (step.name, step.state)) step.state = 'skipped' return True def button_cancel(self): """Cancel a single step. Use fp.job.action_cancel to cancel the whole job. """ for step in self: if step.state == 'done': raise UserError(_( "Step '%s' is done โ€” cannot cancel." ) % step.name) if step.state == 'cancelled': raise UserError(_( "Step '%s' is already cancelled." ) % step.name) step.state = 'cancelled' return True